Basic jsp knowledge (1)

Source: Internet
Author: User

Basic jsp knowledge (1)

1. JSP stands for Java Server Pages. Like servle technology, JSP is a technology defined by SUN to develop dynamic web resources.

2. JSP technology is also a dynamic web Resource Development Technology
JSP technology allows you to nest java code on pages to generate dynamic data. When the web server executes jsp, the web server transmits the web development-related objects to jsp, jsp can interact with browsers through these objects. Therefore, jsp is also a dynamic web resource development technology.

3. Comparison between JSP and Servlet

I learned Servlet first. Servlet seems to be writing pure java code, while jsp can both write java code and script language. To a large extent, jsp and servlet are very similar, except that the jsp site is higher and many servlet operations are encapsulated. Both JSP and Servlet can be used to develop dynamic web resources. However, due to their respective characteristics, servlet is gradually used as a controller component in web applications in long-term software practices, JSP technology is used as a data display template.

4. Schematic diagram of JSP:


Principles:

(1) The Web Container depends on the resource type accessed by the client (the Web container is determined based on the first line of code of the resource). If you access a JSP resource, it is handled by the JSP Engine. If Servlet resources are accessed, they are handled by the Servlet engine.
(2) if it is a JSP resource, the JSP Engine translates it into a Servlet resource and transmits the relevant object. If it is a static resource. write () format output. If it is a dynamic resource, it is output in the out. output in print () format. (This view C: \ apache-tomcat-7.0.22-windows-x86 \ apache-tomcat-7.0.22 \ wZ restart? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> keys/rXE1LS0 + sLrvs2/keys + bU2ret0uvV/keys + keys/cfmuaTX97/keys + HDtLXaTrTOvc + 12j1_zr/ stcTUrdLyPC9zdHJvbmc + response + ciag6gyo6lku1cx7btvyr0gpgjypgogicagicagige + 0 ++ 3qKO6PCU9 "string variable or expression" %>
B> end with no semicolon
C> output to the browser by default


(3) JSP script snippets
A> Syntax: <%... java code; %>
B> the annotator in the script snippet is consistent with the java code.
C> variables defined in multiple JSP script fragments are essentially local variables in the _ jspService () method and can be accessed.

Note: After the JSP is modified, you do not need to redeploy it and refresh it directly. The Web Container will automatically compare the new and old JSP versions.


(4) JSP Declaration
A> Syntax: <%! ... Java code %>
B> variables or methods declared by JSP become instance variables of Servlet, instance methods, or common methods.
C> Local methods cannot be defined in JSP script fragments. methods can only be defined in JSP declarations.

5) JSP comments
A> Syntax: <% -- Comment content -- %>
B> for HTML comments, the JSP Engine translates them into servlet content,
For JSP comments, the JSP engine does not translate them into servlet content.

Therefore, based on the above, jsp annotation should be preferred for annotations.

C> annotations cannot be nested.

6) JSP commands
A> commands are the basis for programmers to control the JSP Engine.
B> there are three types:
Page
Include
Tablib
C> the page directive has the following attributes:
Language = "specifies the language supported by JSP. The default is java language"
Import = "the package to be imported on the current JSP page, where import can be written multiple times"
Session = "true indicates that the server needs to create a session/false, and the server does not need to create a session". The default value is true.
Buffer = "none | 8kb | sizekb" the cache size used by JSP output. The default value is 8 KB.
AutoFlush = "true indicates that when the cache is full, the web container is automatically refreshed to the client/false and needs to be manually refreshed to the client". The default value is true.
IsThreadSafe = "true indicates that the web server ensures thread security./false indicates that thread security is not ensured." The default value is true.
Info = "text" indicates the description of the jsp. You can use getServletInfo () to obtain the jsp information.
ErrorPage = "the target page forwarded to after an error occurs on the current jsp page"
IsErrorPage = "true" (when a jsp page has this attribute, the web Container automatically creates an exception object.
The above exception handling is a local Exception Handling
In the web. xml file:

500
/Error_500.jsp


Java. lang. NumberFormatException
/Error_500.jsp

The Configuration File Code shows that when a browser code 500 exception occurs, the page will jump to the error_500.jsp page. If a NumberFormatException occurs, the page will also jump to error_500.jsp, you can modify the page as needed. The parameter value can be used to handle exceptions in the configuration file.

If there is code and type in the global, both are displayed at the same time.
When both global and local exceptions occur, local exceptions take precedence.

A) JSP pages are encoded in UTF-8
B) JSP adopts UTF-8 encoding when saving
C) Instruct the browser to view in UTF-8

ContentType = "text/html; charsets = UTF-8"
IsELIgnored = "false table method JSP engine does not ignore EL Expression Language/true table method JSP Engine ignores EL Expression Language"

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.