After six months, back to the JSP review finishing, warm so know new.
How JSP works:
The JSP Server Management JSP page is divided into two phases: the transition phase (translation phase) and the execution phase (execution phase).
When the client sends the request, the server verifies that the JSO syntax is correct, then translates it into a servlet source file, and then calls the Javac tool class cheap servlet source file to generate the class file, which is the transition phase.
Next, the servlet container loads the transformed Servlet class, instantiating an object to handle the client's request. After the request is processed, the response object is received by the JSP server and the server is sent to the client in HTML-formatted response information. This phase is the execution phase.
Directory structure for Web apps:
This is necessary to understand, no matter what IDE you use, you create a Web project, will default to you a directory structure. The following are common:
Directory |
Describe |
/jsp_example |
root directory, placing all jsp and html files |
/jsp_example/web-inf |
Store Web. XML and custom label files *.tld |
/jsp.example/web-inf/classes |
Store various class files,servlet files |
/jsp.example/web-inf/lib |
the various jar files required to place a web app (for example, a drive-loaded class that connects to a database) |
▲ here to read Web. XML
The Javaweb app configures its publishing information through an XML-based publish descriptor file . This file mainly contains the following configuration information:
1 ' servlet definition;
Initialization parameters of the 2 ' servlet;
3 ' servlet and JSP mapping;
Definition of 4 ' filter;
5 ' Security Domain configuration parameters;
List of 6 ' Welcome documents;
7 ' resource references;
8 ' definition of the environment variable.
JSP basic syntax
JSP pages are divided into two parts: script and Web page data.
The latter is the part that the JSP server does not process, and the script must be processed by the JSP server, and most scripts are based on XML, and the casing must be consistent.
There are four types of scripts: compile instructions, JSP scripts, action tags, Expression language (EL).
(1) jsp Two kinds of annotation methods :
1 ' HTML comment, client can see (browser page, right click when viewing source code)
<!--Comment--
2 ' JSP comments, Programmer's annotations, not displayed on the client (reverse)
<%--Comment--%>
(2) script elements :
1 ' declaration statement, declaring a variable or function
<%! int i=0; %>
2 ' JSP script (Scriptlet), containing a valid program segment
<% out.println ("lalala,la!"); %>
3 ' expression, direct output display (result)
<%= expression%>
(3) JSP three compiler instructions :
Format: <%@ ...%>
1 ' page directive, to set the properties of the entire JSP page and related functions. The syntax is as follows:
<%@ page language= "java" import= "java.util.*" pageencoding= "iso-8859-1" %>
▲ Common Instruction Parameters:
1. Language properties
Set the language used by the JSP page, currently Java only, default value is Java
<%@ page language="java"%>
2. Extends properties
The JSP page inherits the Java class, the JSP page will be parsed into the servlet by the server before execution, and the servlet is defined by the Java class, so both the JSP and the servlet can inherit the specified parent class, which is not commonly used and may affect the performance optimization of the server.
3. Import Properties
Set up a JSP-imported class package, and the embedded Java snippet needs to be imported into the appropriate class package.
<%@ page import="java.util.*"%>
4. Pageencoding Properties
Specifies the page encoding format, if set to Iso-8859-1, the page does not support Chinese, usually set to GBK or UTF-8
<%@ page pageencoding="GB18030"%>
5. ContentType Properties
Set the MIME type and encoding for a page
<%@ page contenttype="text/html; Charset=utf-8 "%>
6. Session Properties
Specifies whether the page uses the Session object for HTTP, the default value is True
<%@ page session="true"%>
7. Buffer Property
Set the buffer size of the page out output object, default is 8KB, the unit can only use KB, we recommend using multiples of 8 as the property value
<%@ page buffer="128kb"%>
8. AutoFlush Properties
Sets whether the cache is automatically refreshed when the page cache is full, the default is true, and if set to False, an exception is thrown when the cache is full
<%@ page autoflush="false"%>
9. Iserrorpage Properties
You can set the current page as an error handling page to handle the error of another JSP page, which is the exception handling page
<%@ page iserrorpage="true"%>
10. ErrorPage Properties
Set the exception handling page for the current page, the corresponding exception handling page iserrorpage must be set to true, if the property is set, any error handling pages defined in the Web. xml file will be ignored, giving precedence to the exception handling page defined by the property.
2 ' include directive, which contains a static file in the JSP file while parsing the JSP statements in the file
<@ include file= "a.jsp" @>
▲ the difference between attention and jsp:include
The 3 ' taglib directive, which introduces a tag library, allows users to customize new tags. For example:
<%@ taglib uri= "uritotaglibrary" prefix= "TagPrefix" %>
The URI refers to the specified label inventory placement, prefix refers to the prefix used by the specified tag library to differentiate multiple custom labels.
(4) JSP action elements
1 ' <jsp:forward page= "loginsuccess.jsp"/> Forward tag jump page, page value can be given, can also be calculated dynamically on request.
2 ' <jsp:include page= "a.jsp"/> Insert File dynamically
3 ' <jsp:usebean id= "name" class= "Package.class"/> can use Java component reuse, set bean properties via <jsp:setproperty/>, <jsp : GetProperty/> Read Bean.
4 ' <jsp:param/>
5 ' <jsp:plugin/>
6 ' <jsp:params/>
7 ' <jsp:fallback/> (after a few are not used, do not do an explanation)
The road long its repair far XI, I will go up and down and quest.
Poor is to be spared, the way of learning far-reaching! Very far!
(I original, without consent, not reproduced, thank you)
JSP basic Syntax Summary "1" (JSP working principle, script element, instruction element, action Element)