1, the emergence of JSP
2. JSP Scripts and annotations
(1) JSP script
①<%java Code%>-----Internal Java code to the inside of the service method;
②<%=java variable or expression >-----will be translated into service method internal out.print ();
The ③<%!java code%>----be translated into the content of the members of the servlet.
1<%@ page language= "java" contenttype= "text/html; Charset=iso-8859-1 "2pageencoding= "Iso-8859-1"%>3<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "HTTP://WWW.W3.ORG/TR/HTML4/LOOSE.DTD" >456<meta http-equiv= "Content-type" content= "text/html; Charset=iso-8859-1 ">7<title>insert title here</title>89<body>Ten<!--①--> One<% A inti = 0; - System.out.println (i); -%> the -<!--②--> -<%=i%> - +<!--③--> -<%! String str = "hello!"; %> +<%=str%> A</body> at(2) JSP Comment: Different annotation visible range is different
①html comment:<!--annotation Content------visible range JSP source code, translated servlet, page display HTML source;
②java Comment://single-line comment/* Multiline comment */---Visible range jsp source, translated Servlet;
③jsp Note: <%--comment content--%>---Visible range jsp source is visible.
3, JSP operation principle-----jsp essence is servlet
(1) When the JSP is first accessed, it is translated into a servlet by the Web container and executed;
(2) Process: First access---->helloservlet.jsp---->helloservlet_jsp.java----> Compile and run;
(3) The translated servlet can be found in the Tomcat work directory.
4, JSP instruction is to guide the JSP translation and operation of the command, JSP includes three major directives:
(1) Page directive---The most attributes of the instruction (the actual development of the page directive default);
The ① attribute is the most of an instruction, according to different attributes, to guide the entire page characteristics;
② Format: <%@ page property Name 1 = "Property value 1" Property Name 2 = "Property value 2" ...%>;
③ Common properties are as follows:
language:jsp The type of language that can be embedded in a script; Pageencoding: The current JSP file itself is encoded --- internal can contain contenttype ; ContentType:response.setContentType (text/html;charset=utf-8); session: Whether the JSP automatically creates a session when translating; Import: Importing Java packages; ErrorPage: Which page to jump to when the current page is faulted; Iserrorpage: The current page is a page that handles errors.
(2) include directive
The ① page contains a (statically included) directive that can include a JSP page in another JSP page;
② format: <%@ include file= "included file Address"%>.
(3) Taglib directive
① introduces the tag library in JSP page (jstl tag library, struts2 tag library);
② format: <%@ taglib uri= "tag Library address" prefix= "prefix"%>.
4, JSP nine large built-in/implicit objects (9)
(1) After the JSP is translated into a servlet, there are 9 objects defined and initialized in the service method, and we can use these 9 objects directly in the JSP script;
(2) Out object
Type of ①out: JspWriter;
②out function is to want the client output content----out.write ();
The ③out buffer defaults to 8KB, which can be set to 0, which means that the out buffer is closed and the content is written directly to the respons buffer.
(3) PageContext object
The context object for the JSP page, which acts as follows:
5. JSP tag (action)
(1) page contains (dynamically included): <jsp:include page= "included pages"/>;
(2) Request forwarding: <jsp:forward page= "resources to be forwarded"/>;
(3) What is the difference between static inclusion and dynamic inclusion?
03013_ Dynamic Page Technology-jsp