1. What are the built-in JSP objects?
A: JSP has nine built-in objects:
Request: User-side request, which contains parameters from the get/POST request
Response: response from the webpage to the client
Pagecontext: Manage webpage attributes
Session: the session period related to the request.
Application: servlet content being executed
Out: used to send response output
Config: servlet architecture component and configuration information
Page: indicates the JSP page itself.
Exception: exception, uncaptured exception
2. What are the actions of JSP?
A: JSP has 6 basic actions.
JSP: include: Introduce a file when the page is requested
JSP: usebean: Find or instantiate a JavaBean
JSP: setproperty: Set attributes of JavaBean
JSP: getproperty: outputs the attributes of a JavaBean.
JSP: foward: Transfers requests to a new page
JSP: Plugin: generate the object or embed tag for the Java Plug-in based on the browser type
3. Differences between dynamic and static include in JSP
A: Dynamic include is implemented using the JSP: include action. It always checks changes in the included files. It is suitable for inclusion of dynamic pages and can represent parameters.
Static include is implemented using the include pseudo code and does not check the changes to the included files. It is applicable to include static pages.
4. What are the differences between the two jump methods?
Answer: 1. Forward jump: <JSP: Forward page = "Jump page address"/>
2. Response jump: Response. sendredirect ("Jump page address ");
The differences between the two jumps are as follows: 1. forward jump:. server jump, the address bar does not change; B. after the jump statement is executed, the system immediately jumps unconditionally, and the subsequent code is no longer executed (all resources must be released before the jump); C. the property set for the request can still be used on the page after the jump; D. use <JSP: Param name = "parameter name" value = "parameter value"/> to pass the parameter.
2. response jump:. client jump, address bar changed; B. jump after all code execution is complete; C. the request attribute of the previous page cannot be used for the redirected page; D. use address rewriting to pass Parameters (response. sendredirect ("url? Parameter Name = parameter value ")).
5. How to Implement the servlet single-thread mode
A: <% @ page isthreadsafe = "false" %>
6. What are the similarities and differences between JSP and Servlet?
A: JSP is an extension of Servlet technology. It is essentially a simple servlet method, with more emphasis on external expressions of applications. After JSP compilation, it is "servlet-like ". The main difference between Servlet and JSP is that the application logic of servlet is in the Java file and is completely separated from the HTML in the presentation layer. jsp is a combination of Java and HTML into a extension. JSP files, JSP focuses on views, Servlet focuses on control logic.
7. Four session tracking technologies
A: 1. Page indicates the objects and attributes related to a page. A page is represented by a compiled Java Servlet class (which can contain any include command but has no include action. This includes both Servlet and JSP pages compiled into servlet.
2. Request indicates the objects and attributes related to a request sent by the Web Client. One request may span multiple pages, involving multiple Web Components
3. A session represents the objects and attributes related to a user experience used for a Web client. A web session can also frequently request requests across multiple clients.
4. Application represents the objects and attributes related to the entire web application, which is essentially a global scope that spans multiple web applications, including multiple pages, requests, and sessions.
8. Let's talk about the main methods of the request object.
Answer: setattribute (string name, object, object): sets the parameter value of the request whose name is name.
Getattribute (string name) returns the attribute value specified by name.
Getattributename (): returns the set of names of all attributes of the request object. The result is an enumeration instance.
Getcookies (); return all cookie objects on the client. The result is a cookie array.
Getcharacterencoding (); returns the character encoding method in the request.
Getcontentlength (): returns the length of the Request body.
Getheader (string name): Get the file header defined by HTTP
Getheaders (string name): returns all the values of the request header with the specified name. The result is an enumeration instance.
Getheadernames (): returns the names of all request headers. The result is an enumeration instance.
Getinputstream (): returns the input stream of the request to obtain data in the request.
Getmethod (): method for obtaining data transmitted from a client to a server
Getparameter (string name): Get the parameter value specified by the name sent from the client to the server
Getparameternames (): obtains the names of all parameters sent from the client to the server. The result is an enumeration instance.
Getparametervalues (string name): obtains all values of the parameter specified by name.
Getprotocol (): Obtain the protocol name on which the client transmits data to the server.
Getquerystring (): Get the query string
Getrequesturl (): Get the client address that sends the request string
Getremoteaddr (): obtains the IP address of the client.
Getremotehost (): Get the client name
Getsession (Boolean create): returns the session associated with the request.
Getservername (): Get the server name
Getservletpath (): obtains the path of the script file requested by the client.
Getserverport (): Get the server port number
Removeattribute (string name): deletes an attribute in a request.
9. How can I prevent the output in JSP or servlet from being stored in the cache by browser?
A: Just add the script to the JSP file.
<%
Response. setheader ("cache-control", "No-store ");
Response. setheader ("Pragma", "No-Cache ");
Response. setdateheader ("expires", 0 );
%>
10. How do I set cookies in JSP?
A: Set
<%
Cookie mycookie = new cookie ("aname", "avalue ");
Response. addcookie (mycookie );
%>
Delete:
<%
Cookie killmycookie = new cookie ("mycookie", null );
Killmycookie. setmaxage (0 );
Killmycookie. setpath ("/");
Response. addcookie (killmycookie );
%>