One, JSP three kinds of scriptlet (script applet)
1, <%%>: Define local variables, write statements, and so on.
<% = "Hello world!" ;//define local variable out.println (str);//write Statement %>
2, <%! %>: Defines global variables, methods, and classes. (although this party can write classes, it is not recommended.) We usually call the class by JavaBean form)
<%! Public Static Final String INFO = "JAVA Web"; //define global variables %><%! Public int Add (intint y) {//define method return x+y; } %><%! class person{//defines the class }%><%//writes the normal script out.println ("INFO");//Call global variable out.println (add ( 3,5));//Call Method %>
3, <%=%>: Lose a variable or a specific content
<% = "java"; %>//Using an expression output variable
Second, including
1. Static inclusion
<%@ include file= "a.html"%>
<%@ include file= "a.jsp"%>
2. Dynamic inclusion
2.1 With no parameters
<jsp:include page= "a.html"/>
<jsp:include page= "a.jsp"/>
2.2 With parameters
<jsp:include page= "a.jsp" >//pass two parameters to the included page
<jsp:param name= "name" value= "<%=username%>"/>
<jsp:param name= "Info" value= "java Web"/>
</jsp:include>
Static is the first containing the re-processing, dynamic is the row after the inclusion, so we should be more dynamic inclusion.
Example: a.jsp file
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><%@ page contenttype= " TEXT/HTML;CHARSET=GBK "pageencoding=" GBK "%><% int i = +; %>
index.jsp
<! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01//en" "HTTP://WWW.W3.ORG/TR/HTML4/STRICT.DTD" ><%@ page language= "Java" pageencoding= "GBK"%><%@ include file= "a.jsp"%>//static contains <% int i=10; %>
If static loading will be an error, because the static is merged and then processed, when the merge is defined two the same I variable, so show the times wrong.
However, if it is dynamic, then the merge is processed first, so two results can be displayed normally.
Java Web Development Combat Classic (I)