Javaweb----Part5 JSP

Source: Internet
Author: User

JSP is a combination of Java implementation logic and HTML.
The principle of JSP is that the JSP code will generate a Java file at the first execution,
It is then compiled into a class file, which is equivalent to the previously written servlet file.
The page directive in the JSP is used to guide certain features in the page
There are multiple properties. '
Language= "Java"
Pageencoding= "UTF-8"
Contenttype= "Text/html;charset=utf-8" Specifies the response header information
import= "" Java package that needs to be imported
Session= "Boolean"//whether to create session
errorpage= "url"//Specify page for this JSP error jump
Iserrorpage= "Boolean"//Specifies whether this JSP is error handling page can get exception information

Page inside set errorpage= "url" Specify error pages
1. Prevent the error message inside the system from leaking to the visitor through an error
2. Display the friendly Visual error page to avoid the user's panic
3. Have the opportunity to record the exception that the program does not handle, convenient for programmers to find errors
Configuring the Unified Configuration error page in XML
<error-page><error-type></error-type><loaction></location></error-page>
<error-page><error-code></error-code><loaction></location></error-page>
Location begins with "/"

The object of the JSP,
You can set properties by using the Setattrbute () key-value pair.
Then getattrbute to get the property

PageContext object has a Findattrbute () method
From the pagecontext/request/session/application in turn
Go to find the key value pair of Name=value and return the value;
Return as soon as it is found, and will not continue to look for coverage in the future.
Unified Configuration Error page
<error-page>
<exception-type>java.lang.Throwabke</exception-type>
<location>/Error.jsp</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/error/404.jsp</location>
</error-page>


1. The browser does not directly access the JSP file, but instead directly to find the servlet file
2.servlet prepare the data, then forward to the JSP to display
3.servlet and JSP pass data directly, do not pass Resuleset,
Instead, a common object or object collection is passed.

The difference between forward and sendredirect
1. If the logic is handled by the server, "/" can represent the project's directory
If the logic is handled by the browser, it cannot be added "/".
2.sendRedirect two requests, data of two requests are not shared;
The request for the first request from the browser, the second request after the redirect.
And Req.set is the site where the attribute exists on the first domain name.
Req.get will not be able to remove the second domain bar attribute.

Javaweb----Part5 JSP

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.