Basic grammar learning of JSP
Page instruction Description:
Language: Used to define the scripting language to use; The scripting language used by the language= "Java" definition is java.
ContentType: Defines the encoding of the JSP character and the MIME type of the page response; The MIME type------>mime (Multipurpose Internet Mail Extensions) is the Internet standard that describes the message content type (the following type is text/html; character encoding is utf-8).
Pageencoding:jsp the character encoding of the page; The following character encoding is utf-8.
<%@ page language= "java" contenttype= "text/html; Charset=utf-8 "
pageencoding= "Utf-8"%>
Scriptlet Tags:
through The scriptlet tag we can embed java code in the JSP ;
The First kind:<%!%> We can define global variables, methods, classes in it;
The second kind:<%%> We can define global variables and write statements in them;
The Third Kind:<%=%> We output a variable or a specific content inside;
For example, code:
<%!
String str= "global variable";
public void Fun () {
System.out.println ("global Method");
}
public class a{
private int b=1;
public void Fun1 () {
SYSTEM.OUT.PRINTLN ("Global Class");
}
}
%>
<%
int a=1234;
String b= "Java";
Out.println (b+a+ "local variable");
%>
<%=b%>
JSP comments:
<!---->html Note client visible
<%----%>jsp Note Client is not visible
Java Single-line comment not visible
/* */java Multi-line annotations are not visible
Code:
<!--HTML comment client Visible-
<%--JSP Note Client is not visible--%>
<%
int Temp=1;//java single-line comment
/* int c=2;
int d=3; Multiple lines of Java comments
*/
%>
JSP contains directives:
<%@ include file= " the files to include " %> static contains first, post-compile processing;
<jsp:include page= " the files to include " > dynamic contains the first compile processing, after the inclusion;
Later we use dynamic inclusion;
Code:
<% @include file= "common/head.html"%>
<p>content content!! </p>
<% @include file= "common/footer.jsp"%>
<jsp:include page= "common/head.html" ></jsp:include>
<p>content</p>
<jsp:include page= "common/footer.jsp" ></jsp:include>
JSP Jump command:
<jsp:forward>
<jsp:param value= "" name= "" >
</jsp:forward>
Server internal jump, can take parameters;
<jsp:param value= "" Name= "" >
Code:
forward.jsp
<jsp:forward page= "target.jsp" >
<jsp:param value= "java" name= "username"/>
<jsp:param value= "123456" name= "password"/>
</jsp:forward>
target.jsp
<p>username:<%=request.getparameter ("username")%></p>
<p>password:<%=request.getparameter ("password")%></p>
JSP basic syntax