JSP learning notes (1): JSP basics and jsp learning notes Basics
I. Principles1. HttpServlet is first compiled from the source code into a class file and then deployed to the server. Compile and deploy the SDK. 2. JSP first deploys the source code and then compiles it into the class file, and then compiles it. JSP will be compiled into the HttpJspPage class when the client first requests the JSP file. This class will be temporarily stored in the working directory of the server by the server.
3. instance: the client requests myFirst for the first time. in jsp, Tomcat first sets myFirst. jsp is converted to the standard Java source code myFirst_jsp.java, stored in the directory % atat_path % \ work \ Cataline \ localhost \ % Java_Web %, and myFirst_jsp.java is compiled into the class file myFirst_jsp.class. This class file is the corresponding Servlet. After compilation, run the class file to respond to the client request. When the client accesses myFirst. jsp, the server will not re-compile the JSP file, but will call the myFirst_jsp.class file in MB.
Ii. Syntax(1) Script 1, <%>: java code block 2, <% = %>: Output 3, <%! %>: Method and global variable
(2) commands (can be replaced by JSP behavior labels <jsp: directive>) 1. Page command: Specify attributes of the JSP Page. 1) instance:
<%@ page contentType="text/html; charset=gb2312" language="java" errorPage="" %> <%@ page import="java.util.Date"%>
2) common attributes:
2. include command 1) instance: include. jsp contains head. jsp.
<%@include file="../common/jsp/head.jsp"%>
2) essence: First include and then compile. The compiled jsp file contains the file content to be included. Add the source code of head. jsp to include. jsp and compile it into a class file.
3. taglib command: 1) instance:
<%@ taglib url="http://java.sun.com/jsp/jstl/core" prefix="c" %>
(3) Jsp Behavior 1. include behavior: <jsp: include> 1) instance: include. jsp contains head. jsp.
<jsp:include page="/head.jsp" flush="true" ></jsp:include >
2) essence: first run and then include. Execute head. jsp separately during the runtime, and then include the execution result in include. jsp, which is a behavior that includes after the first run. The compiled include. jsp file does not contain the header. jsp file.
2. JavaBean behavior: 1) define the javaBean object: <jsp: useBean id = "" class = "" scope = ""/> 2) obtain the javaBean attribute: <jsp: getProperty name = "" prperty = ""/> 3) set the javaBean attribute: <jsp: setProperty name = "" prperty = "" value = ""/> the name is the name of the JavaBean, that is, the id attribute of useBean behavior. property is the JavaBean attribute and value is the attribute value.
3. forwarding behavior: <jsp: forward> 1) instance:
<jsp:forward page="/somapage.jsp"> <jsp:param name="param1" value="value1"> <jsp:param name="param2" value="value2"> </jsp:forward>
4. Command Behavior: <jsp: directive> is equivalent to JSP commands. 1) instance: The <jsp: directive. page/> action is equivalent to the <% @ page %> command. <Jsp: directive. include/> is equivalent to the <% @ include %> command. <Jsp: directive. taglib/> the behavior is equivalent to the <% @ taglib %> command.