JSP Learning Summary---learning notes

Source: Internet
Author: User

What is JSP

1) Why is the servlet a dynamic web development technology?
Servlet is a kind of dynamic interaction technology based on the service side,
HttpServletRequest represents the client-to-server object
HttpServletResponse represents a service-to-client object
2) JSP is a dynamic web development technology developed by Sun company based on server
3) JSP code structure/content =html+jsp all element content
4) In IDE tools, development jsp,pageencoding has two meanings:
A) indicates how the Chinese in the current JSP is encoded (if outside the IDE tools)
b) Indicate how the current JSP page is encoded when it is saved
5) in the project, JSP best practices mode:
Servlet: Suitable for controller
JSP: Suitable for display
JavaBean: Model

* * JSP working principle

1) The Web container depends on the resource class accessed by the client (the Web container is determined based on the first line of the resource), and if you are accessing a JSP resource, you are referred to the JSP engine for processing
If you are accessing a servlet resource, you are referred to the servlet engine for processing
2) If it is a JSP resource, the JSP engine translates it into a servlet resource, passing in the related object, if it is a static resource, output in Out.write () Form, and if it is a dynamic resource, output in Out.print () Form.
3) When the JSP engine is translated correctly, it outputs it to the servlet engine, which is treated as a servlet.
4) If you visit the same date.jsp file again, the translation is still working, the servlet engine can be reduced, so this is the reason why the nth time is faster than the 1th time.

3 JSP syntax

1) JSP template elements
Template elements are static content in HTML, <body>,<table>,<form> tags ...

2) JSP expression
A) Syntax: <%= "string variable or expression"%>
b) End No semicolon
c) Default output to Browser

3) JSP script fragment
A) syntax: <% java code; %>
b) The comment symbol in the script fragment is consistent with the Java code
Note: After the JSP is modified, no redeployment is required, and the Web container automatically compares the old and new two versions of the JSP
c) variables defined in multiple JSP script fragments, essentially local variables in the _jspservice () method, can be accessed
4) JSP Declaration
A) syntax: <%! ... Java code%>
b) A variable or method declared by a JSP that becomes an instance variable or an instance method or a common method of a servlet
c) A local method cannot be defined in a JSP script fragment, and the method can only be defined in the JSP declaration

5) JSP annotations
1)语法:<%-- 注释的内容 --%>    2)对于HTML注释来说,JSP引擎会将其翻译成servlet内容,  对于JSP注释来说,JSP引擎不会将其翻译成servlet内容    3)注释不能嵌套使用

6) JSP Instructions
1) instructions are the basis for programmers to control what the JSP engine does
2) There are three categories:
A) page
b) Include
c) tablib
3) The properties of the page directive are
Language= "indicates the language supported by the JSP, default to the Java language"
Import= "The current JSP page, the package that needs to be imported, where import can be written multiple times"
Session= "True indicates that server creation is required Session/false does not require server creation session", by default True
Buffer= the cache size used by the "none|8kb|sizekb" JSP output, default 8kb
Autoflush= "True indicates that when the cache is full, the Web container is automatically refreshed to the client/false needs to be manually refreshed to the client", by default True
Isthreadsafe= "True indicates that the Web server ensures thread safety/false does not ensure thread safety", by default True
info= "Text" represents the relevant description of the JSP, which can be obtained by Getservletinfo () to the JSP information
errorpage= "The current JSP page error, forwarding to the target page"
Iserrorpage= "true" (when a JSP page has this property, the Web container automatically creates the exception object
The above exception handling belongs to the local exception handling
In the Web. xml file:
<error-page>
<error-code>500</error-code>
<location>/s_500.jsp</location>
</error-page>
<error-page>
<exception-type>java.lang.NumberFormatException</exception-type>
<location>/s1_500.jsp</location>
</error-page>
The above exception handling belongs to all exception handling
If there is code and type in the global, both are displayed at the same time
Local exceptions take precedence when global and local exceptions occur at the same time
pageencoding= "UTF-8"
Prerequisites in the IDE tool
A) JSP page in Chinese using UTF-8 mode encoding
b) JSP is saved with UTF-8 encoding
c) Instruct the browser to view in UTF-8 mode
Contenttype= "Text/html;charset=utf-8"
Iselignored= "False table method JSP engine does not ignore El Expression language/true table method JSP engine ignores El expression language"

9) How to find errors in JSP pages

4 JSP Error post-processing method 5 M (Javabean) V (JSP) C (Servlet) mode 6 @include directive [static inclusion]

1) The Include directive contains multiple JSP pages, and finally the JSP engine translates only the total JSP page, the index.jsp page
2) The include directive contains multiple JSP pages, so the included JSP pages go into the total JSP page intact, that is, the index.jsp page, resulting in a very confusing HTML structure
3) The include directive contains multiple JSP pages, and multiple JSPs are eventually translated into a servlet, the Index_jsp.java page

*7 JSP Nine implicit/built-in objects
1)request2)response3)session    访问jsp页面时,默认web服务器创建session    访问servlet时,必须通过request.getSession()才能创建session    在转发和重定向情况下,session域不会销毁4)application=ServletContext对象  5)config:取得jsp在web.xml文件中的映射信息6)exception:该对象只能在<%@isErroPage="true"%>的情况下,容器才会创建,否则容器不予创建7)out:out的类型是JspWriter,它是具体缓存功能的PrintWriter对象8)pageContext: 表示Jsp行运过程中的环境对象  a)能够取得其它8个内置对象  b)具有转发和包含的功能   c)域对象[pageContext/request/session/application]9)page

JSP Learning Summary---learning notes

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.