JSP error correction of wrong problem

Source: Internet
Author: User

A: Determine if the learner has manually installed Tomcat (practice proficiency) B: To enable the learner to understand the operation of Tomcat, the browser sends a request to the Web server, the Web site processes the request, after the processing of the results response to the browser c:tomcat as a Web server, You can deploy a Web site to provide support for browser access, and you cannot deploy the C/S program d:web the basic functionality provided by the container (understanding) through the above analysis: The tomcat description is not correct C

D The answer is wrong, because when the import guide package, different class files are separated by commas, should be: <% @page import= "java.util.*,java.text.*"%>

Because it is forwarding, you can get the value in the Request object on the a.jsp page. So the correct answer is B.

Request.getparameter ("userid") gets the value of the first FORM element named "UserID", and to obtain the value of multiple form elements with the same name, you need to pass Request.getparametervalues ("userid ") to get, returns an array of strings. So the answer is BC.

The LoginName final value of the form in index.jsp is bdqn when it arrives logindo.jsp

Then use forwarding mode to jump to loginsuccess.jsp, so request information is not lost use can get the parameter named LoginName value is BDQN

First of all, the session is really to solve the problem that HTTP cannot maintain customer status, so the A option is correct, and the user information is part of the customer status, so a can see that B is wrong; Then, whether the information in the session is safe does not depend on where it is stored, It depends on the session implementation mechanism and the acquisition mechanism, and the session does not explicitly stipulate the size limit of its storage space, so C, D is not correct;

When submitting a form request, the character encoding of the request should be set, and the syntax should be: request.setcharacterencoding ("GBK"); so the D answer is correct.

The Config object is an object that is created automatically when the server starts, and when the servlet is created, it is usually the information required to get initialized.
Answer Select a

Static contains the pages that are included to be executed together later. At this time the variable i duplicate

The number of requests sent from the client , the redirect is to send two requests to the server. Forwarding is the internal operation of the server, sending only one request, and the data in the request object can be preserved.

from the point of view of the URL display: Redirection of these two requests is directly affected by browser intervention. that is, the address that you see in the URL address bar after redirection has changed. And forwarding is the server from a resource page to navigate to another resource page, and has not been browser intervention, so the URL Address bar has not changed.

Conclusion: To save data in the request , use forwarding, otherwise redirect.

Redirection and forwarding have an important difference: When forwarding is used,JSPThe container uses an internal method to invoke the target page, and the new page continues to process the same request, and the browser will not know about the process. In contrast, the redirect means that the first page notifies the browser to send a new page request. Because, when you use redirection, the browser displays theURLwill become a new pageURL,When forwarding is used, theURLwill remain the same. Redirection is slower than forwarding because the browser has to make a new request. At the same time, due to a new request from redirection, after a redirect,Requestthe object within will not be available for use.
How do you choose to redirect or forward? Forwarding is usually faster and can keepRequestwithin the object, so he is the first choice. However, because after forwarding, the browserURLstill points to the start page, at which point the Start page will be called again if the current page is overloaded. If you do not want to see such a situation, select forward.

The difference between forwarding and redirection
Don't use it just to upload the variable to the next pageSessionScope , which increases the scope of the variable for no reason, forwarding may help you solve the problem.
Redirect: PreviousRequestall of the variables stored in it are invalidated and enter a newRequestscope.
Forward: the previousRequestThe variables stored in the are not invalidated, as if the two pages were spelled together.

Response.sendredirect ("index2.jsp"); redirect, the value in the request object cannot be reached, so the output is null. Answer a is correct

All JSPs are translated into the servlet's source code (Java) by the container after the client makes the request, and then the source (Java) is compiled into the servlet class, which is put into memory.  Among them, <%! int a=0;%> defines a member variable of a class, <% int b=0; %> is defined as a local variable in the service method. In addition to the first request, only the service method is called for the other two requests. The answer is C.

Redirection is a client-side behavior, which is two requests sent, so you cannot use the data a answer error in the first request

1 syntax for writing cookies:

Response.addcookie (Cookname);

Response.sendredirect ("Address");

2 Read cookie information:

Request.getcookies ();

JSP error correction of wrong problem

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.