Examples % TABLEBORDER0CELLPADDING0CELLSPACING0TRTDVALIGNTOPFONTFACEVerd an online examination system to test your jsp knowledge, the code is not so much, so don't add comments (http://jspbbs.yeah.net)
QuizResponses. java
Answer. jsp
<% -- Include directive -- %>
<% @ Include file = "header.html" %>
Quizzes Index JSP Professional, Chapter 12 Quiz Answers By Dan Malks
<% -- Page directive that applies to entire page. -- %> <% @ Page language = "java" %>
<% -- Identifies bean as "worker" and tells the page where to locate the bean. -- %>
<% -- Set bean properties with a wildcard. -- %>
<% -- Scoring -- %>
<% -- Variable declaration in code scriptlet --> <% Int score = 0; %>
|
1. | <% -- The method getOne () was set up in the bean with the id "worker" -- %><% -- All Java code is enclosed in <%>, leaving HTML to be easily -- %><% -- Changed or updated. -- %><% If (worker. getOne ()! = Null) & (worker. getOne (). equals ("D") {score ++; %>
D Is correct! | <%} Else if (worker. getOne ()! = Null) {%>
Is incorrect! | <%} Else {%>
Blank X | <% }%>
Every JavaServer PagesTM (JSP) TMsource page is compiled A servlet before it is executed at runtime.
|
2. | <% If (worker. getTwo ()! = Null) & (worker. getTwo (). equals ("B") {score ++; %>
B Is correct!
| <%} Else if (worker. getTwo ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
When large amounts of Java scriptlet code are mixed with HTML markup Within a JSP page, not only do readability and reuse suffer, but often Bugs are introduced as web-production team members, who may not be Familiar with Java programming, need to modify the accompanying markup. Additionally, dependencies now exist among various teams competing for Same file, making the development process less efficient.
|
3. | <% If (worker. getThree ()! = Null) & (worker. getThree (). equals ("D") {score ++; %>
D Is correct!
| <%} Else if (worker. getThree ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
Doing an HTTP redirect requires a round-trip to the client. If this Is not required, and the only desire is to forward the request Another resource, then this can be much more efficiently accomplished WithRequestDispatcher . Additionally, when using Dispatcher the state of the request object is maintained Resources, which will not be the case with the HTTP redirect.
|
4. | <% If (worker. getFour ()! = Null) & (worker. getFour (). equals ("C") {score ++; %>
C Is correct!
| <%} Else if (worker. getFour ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
Business logic is better contained in JavaBeanTM or a servlet, which is Owned by a software developer. When lots of Java code is embedded Directly within the JSP page as scriptlets, "Cut-and-paste" mentality tends to prevail when it comes To code reuse.
|
5. | <% If (worker. getFive ()! = Null) & (worker. getFive (). equals ("A") {score ++; %>
AIs correct!
| <%} Else if (worker. getFive ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
Since the servlet is the initial contact point for each request, it is Well-suited to handle logic that is common example SS multiple requests. A good example of this type of logic is an authentication check.
|
6. | <% If (worker. getSix ()! = Null) & (worker. getSix (). equals ("B") {score ++; %>
BIs correct!
| <%} Else if (worker. getSix ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
Using a business delegate reduces coupling between the presentation And business tiers. The presentation tier has no knowledge of EJB implementation details, such as Java Naming and Directory Interfacfe-lookup.
|
7. | <% If (worker. getSeven ()! = Null) & (worker. getSeven (). equals ("B") {score ++; %>
BIs correct!
| <%} Else if (worker. getSeven ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
Using Java scriptlets is the accepted method of doing iteration in JSPTM 1.0. In JSPTM 1.1, a custom tag may be used, Which will hide the implementation details of the iteration code.
|
8.
| <% If (worker. getEight ()! = Null) & (worker. getEight (). equals ("A") {score ++; %>
AIs correct!
| <%} Else if (worker. getEight ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
The termPage-CentricIs used to describe an architecture where The initial contact point for the request is a JSP page. An example Is shown abstrally below:
|
9.
| <% If (worker. getNine ()! = Null) & (worker. getNine (). equals ("A") {score ++; %>
AIs correct!
| <%} Else if (worker. getNine ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
When the forward method is used, the invoking resource does not regain Control. Multiple include invocations can be made from the same Resource, while the invoking resource maintains execution control.
|
10.
| <% If (worker. getTen ()! = Null) & (worker. getTen (). equals ("D") {score ++; %>
DIs correct!
| <%} Else if (worker. getTen ()! = Null) {%>
Is Incorrect | <%} Else {%>
Blank X | <% }%>
Error pages are invoked when there is an uncaught exception from Within a participating page. In this case, we mention that
validationGaurd() Method might throw an exception. If this exception is not caught within the page, then we vector Control toerrorPage , As stipulated in the attribute Of the given page directive.
|
<% -- Scoring calculations -- %><%Int missed = 10-score;Double grade = (double) score/10*100;%>
You missed<% = Missed %>
Your score is<% = (Int) grade %>Percent. Source Code
This quiz usedPage-View with Bean Approach, Detailed in HREF = "/developer/Books/triggerverpages/"> Chapter 12, JSP Archeticure. The first Page of the quiz consists of regular HTML with a form that cils href = "answer.txt">answer.jsp .Answer.jsp Requests parameters from the bean, In this case, called QuizResponses.Page-view with bean Approach for this quiz required extra work to write the bean, and it cowould have been done using Page-view approachWithout a bean, requesting invocation directly fromanswer.jsp Page. Deciding which approach is preferrable depends on the application and how much HTML and Java Scriptlets need to be used. For this quiz we opted forPage-view with beanApproach Authentication purposes.
Back to Quiz
|
<% @ Include file = "footer.html" %> |