JSPs of November 10, March 3

Source: Internet
Author: User

Zookeeper

1. Whether or not the browser disables cookies, the server will rewrite the URL upon first access.
However, if the cookie is not disabled after the second visit, the server will not perform the URL
Rewrite. If disabled, rewrite the URL. This is the response. encodeURL (url); Method
. It does this internally.

2. If response. setHeader ("Refresh", "2, url = .....");
The jsessionid parameter of the URL address after rewriting is removed. So do not use this.
Use response. sendRridirect ();


3. The session will time out, and the bank will be 5 minutes. It will expire in 5 minutes. A new session will be created during the next access.

4. The session contains a large Map of data.
(Class, attribute)
Serialization is required to exist on the hard disk; otherwise, an exception is returned.
Interface. You can view the experiment. Passivation and activation; Shelving and Activation

5. The cookie cannot be saved in Chinese. It must be base64-encoded. Remember the user name case, remember the user name

6. base64 principles and encoding and decoding. There are APIs in jdk, and the package is sun .....
If the package cannot be imported, you can check the information online. Case: Prevent form submission

Base64 can convert anything into characters.

Base64 encoding converts three bytes into four bytes. The three bytes are 24 bits, and the value of 24 divided by 4 equals to 6. Otherwise, the value of 0 is changed to four bytes.
Minimum 0000 0000
0011 1111
The number of intervals is 64.


7. md5 algorithms (which are included in jdk APIs) cannot be reversed (in mathematical thinking, there is a dictionary on the Internet that can be viewed and cracked on the surface, but not actually ),
MD5 will be encoded into bytes, and it will be converted back to characters in base64 encoding, that is, reversed

Struts2 prevents form submission and generates a token.


8. Nine built-in JSP objects are defined in a standardized manner. No matter
JSP is Servlet.
JSP basic syntax is not used in actual work and will be interviewed. But to learn.

Tomcat translation JSP.

Java code in JSP gets the Servlet directly. The body content in JSP is the service method.
Output content is output from the out object in the Servlet.


JSP declaration not needed (defined externally in the service method
Is global, and objects such as request and response cannot be used ),
Thread security issues. Check the Servlet code.

Speech: servlet is a small program running on the server. His lifecycle?

Dom parsing: node, element, and attribute


9. JSP translated Java files can be stored in the work directory on the tomcat server.
Find, find at one level.


10. preferred static inclusion in development

11. Common JSP action labels: comments cannot be written internally.

12. iserroepage = FALSE. The default value is FALSE. Whether to generate an exception object.
Print the error message. We still need to solve the problem.

13. autoFlush auto refresh. The default size is 8 KB. We don't care.

14. All things must be saved to the response cache first, and then the response responds to the browser.

JSP out objects are also cached, JSPwriter.

15. Close the browser. By default, a reply ends.
Another browser is to restart a new session.

However, the current browser opens again, which is also the same session. The above shall prevail.


16. The page object in JSP and the page range represented by pagecontext
(Generally not used, the indicated range is too small,
Not a concept.

17. The request object and response in JSP are useful only when combined with forwarding.

18. The session object in JSP can be used on different pages as long as it is the same session.
Functions such as query results cannot be stored in sessions. If we see this for the first time,
4 records. If the server updates the data and adds the data, what we can see again is
4 records. There will be no such problem with the request. After the request is complete, the request will be gone,
The request is resent.





Instructor notes:

I. HttpSession
1. How to maintain session data when cookies are disabled on the client
Http: // localhost: 8080/day10_00_session/servlet/ShowCartServlet

Http: // localhost: 8080/day10_00_session/servlet/ShowCartServlet; JSESSIONID = 111111 URL rewrite. All url addresses in this application must be rewritten.


String newURL = esponse. encodeUrl (String url );
Lazy: homepage --- do not disable your cookie to better browse our website
2. Status transition of the HttpSession object
2.1 configure the timeout time of the session object.
Modify web. xml

1


GetMaxInactiveInterval
Public int getMaxInactiveInterval ()
Returns the maximum time interval, in seconds, that the servlet container will keep this session open between client accesses. after this interval, the servlet container will invalidate the session. the maximum time interval can be set with the setMaxInactiveInterval method. A negative time indicates the session shold never timeout.
Returns:
An integer specifying the number of seconds this session remains open between client requests
See Also:
SetMaxInactiveInterval (int)

3. When will the IE browser start a new session?
Different versions of IE: it is not certain if a new browser process is enabled for the same session.
4. Base64 encoding: (very important)
Change 3 bytes to 4 Bytes:
10011100 01010011 10101111
00100111 00000101 00001110 00101111
Each byte decimal point is 00000000 ~ 00111111 64 integers. Each integer corresponds to a visible character.
Base64 can convert any byte into visible characters
Ii. JSP Overview:
JSP = HTML + Java
Servlet: control business logic
JSP: Display
When dynamic resources generate static resources, users will always see static resources, that is, they will see the results of dynamic resource generation.
The key to learning JSP well: When writing a part of JSP content, you must know where it is in the Servlet.
III. Basic JSP syntax
1. JSP template element: the HTML content in JSP. Interface display. (Artist) we recommend that you complete the template first.
2. JSP script expression:
Purpose: output the value of a variable to the page. (Equivalent to out. write ())
Syntax: <% = expression %>
3. JSP script snippets:
Role: Write java Logic
Syntax: <%
Statement 1;
Statement 2;
%>
4. JSP Declaration
Purpose: Define the Servlet member variables or methods corresponding to JSP.
Syntax:
<%!
Private int age = 100;
Public void m (){
}
Static {}
%>
5. JSP comments
Syntax: <% -- this is a comment -- %>
Result: The commented code is not translated by the server.
In actual development: in addition to the instructions described below. A row in JSP cannot appear <%>
4. JSP commands:
Function: used by the server.
Syntax: <% @ page | taglib | include attribute 1 = "value 1"... %>
1. page:
Language: Specifies the language of the script used in JSP. The default value is java. Currently, only java is supported.
* Import: imports the class or package used in jsp. It works exactly the same as the import in java.
Import = "java. io. InputStream, java. util. Date"
* Session: Indicates whether to create an HttpSession object. The default value is true.
Buffer: indicates the cache size of the Output Response stream. The default value is 8 KB.
* ErrorPage: specifies where to forward an error. The value is a uri address. If it starts with "/", it indicates the current application.
Configure the global error prompt page: (not forwarding)
Web. xml

Java. lang. Exception
/Error. jsp



404
/404.jsp

* IsErrorPage: Indicates whether to generate an exception object. True is generated. The default value is false.
* ContentType: Specifies the MIME type and encoding of the response body when the HttpServletResponse output is notified.
Same as response. setContextType = "text/html; charset = UTF-8"
* PageEncoding: indicates the code table to be queried when the jsp file is read from the disk.
1. indicates the encoding used by the server to read files on the disk.
2. encoding used by contentType
* IsELIgnored: The default value is false. Indicates whether to ignore the EL expression.
2. taglib: Introduce externally defined labels (emphasis)
<% @ Taglib uri = "http://java.sun.com/jsp/jstl/core" prefix = "c" %>
3. include: implement include (static include)
Static include: two pages correspond to one Servlet
Dynamic inclusion: two pages correspond to one Servlet respectively.
5. Common JSP action elements (jsp built-in labels)
Jsp: include: Dynamic inclusion
Jsp: forward
Jsp: param
6. Nine implicit objects in JSP (the local variables generated in the service corresponding to JSP)
Type of JSP implicit Object Name
Request javax. servlet. http. HttpServletRequest (domain object)
Response javax. servlet. http. HttpServletResponse
Session javax. servlet. HttpSession (domain object)
Application javax. servlet. ServletContext (domain object)
Config javax. servlet. ServletConfig
The Servlet instance corresponding to the current JSP page
Exception java. lang. Throwable

Out javax. servlet. jsp. JspWriter (same as response. getWriter)
PageContext javax. servlet. jsp. PageContext (important when using JSP)

Three major roles:
1. It is a domain object and can operate data in the other three domain objects.
Itself is a domain object: The range is the current page.
Void setAttribute (String key, Object value)
Void removeAttribute (String key)
Object getAttribute (String key)
Operate data in the other three domain objects: scope is a constant: PAGE_SCOPE (page range PageContext) | REQUEST_SCOPE (request range: ServletRequest) | SESSION_SCOPE (Session range: HttpSession) | APPLICATION_SCOPE (Application Scope: ServletContext)
Void setAttribute (String key, Object value, int scope)
Void removeAttribute (String key, int scope)
Object getAttribute (String key, int scope)

Search Method:
Object findattriquest (String key): searches from PageContext \ ServletRequest \ HttpSession \ ServletContext sequentially until it is found.
2. Obtain the other eight implicit objects: Used in common classes.

3. provides a simple method for forwarding and inclusion
PageContext. forward ("/scope/2.jsp ");
PageContext. include ("");

Summary of four domain objects
Indicates the range in which the Map is located. Constant remarks in PageContext
Page PageContext: Map PAGE_SCOPE development is almost unnecessary: use it during exercises
Request ServletRequest: Map REQUEST_SCOPE is commonly used in development: Forwarding only (A processes data ---- forwarding B displays data ). The data to be displayed in this range is useless, for example, query result data.
Session HttpSession: Commonly Used in Map SESSION_SCOPE Development: The data stored in this range is only for your own use multiple times. Such as shopping cart and login information.
Application ServletContext: Map APPLICATION_SCOPE is rarely used for development: synchronization is required

Related Article

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.