Review the JSP script element and annotation section today, the case writes out, everybody oneself debugging, the overall summary is as follows,
1, JSP declaration statement:
<%! Declaration Statement%>
A variable with a declaration statement is a global variable, and multiple users execute the JSP page, and the variable is shared.
Such as:
Copy Code code as follows:
<html>
<head>
<title>jsp demo</title>
</head>
<body>
<%! int a = 1;%>
<%
out.println ("a=" +a);
a++;
%>
</body>
</html>
The results are as follows:
Refresh again, you will find the following a value plus one, because variable a is a global variable, a++ operation multiple cumulative, multiple customer service end sharing:
2, JSP Scriptlets:
<% Java Code%>
In the JSP scriptlets can contain several statements, such as: methods, variables, expressions, etc.;
Such as:
Copy Code code as follows:
<html>
<head>
<title>test demo</title>
</head>
<body>
<%
String str = "hello,xiaomo!";
out.println (str);
%>
</body>
</html>
The results are as follows:
3, JSP expression:
<%= Java Code%>
A simple output form that must have a value that can be output, the code in the expression executes first, and then converted to a string to display to the page.
Such as:
Copy Code code as follows:
<html>
<head>
<title>test demo</title>
</head>
<body>
<% String str = "hello,xiaomo!"; %>
<%= str%>
</body>
</html>
The results are as follows:
4, JSP comments:
<!----> HTML comments, which are displayed on the client side;
<%----%>jsp annotation, will not be displayed on the client;
Such as:
Copy Code code as follows:
<html>
<head>
<title>test demo</title>
</head>
<body>
<!--This is a Web page annotation-->
<%--This is a JSP annotation--%>
</body>
</html>
The results are as follows:
We found that there is nothing to show, click the browser right button to see the source code can be seen in the comments are in the JSP, this is only in the JSP source code can see:
Copy Code code as follows:
<html>
<head>
<title>test demo</title>
</head>
<body>
<!--This is a Web page annotation-->
</body>
</html>
It should be known to many people, JSP page is translated into a servlet after the conversion of the server into the HTML code sent to the client display, the following for you to see the case of JSP page converted into a servlet after the source code (which is marked as converted to the foreground of the HTML codes):
Copy Code code as follows:
/*
* Generated by the Jasper component of Apache Tomcat
* Version:apache tomcat/7.0.34
* Generated at:2013-07-03 01:27:37 UTC
* Note:the Last modified time of this file is set to
* The last modified time of the source file after
* generation to assist with modification tracking.
*/
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
public final class helloxiaomo_jsp extends Org.apache.jasper.runtime.HttpJspBase
Implements Org.apache.jasper.runtime.JspSourceDependent {
private static final javax.servlet.jsp.JspFactory _jspxfactory =
javax.servlet.jsp.JspFactory.getDefaultFactory ();
private static java.util.map<java.lang.string,java.lang.long> _jspx_dependants;
private Javax.el.ExpressionFactory _el_expressionfactory;
private Org.apache.tomcat.InstanceManager _jsp_instancemanager;
public java.util.map<java.lang.string,java.lang.long> getdependants () {
return _jspx_dependants;
}
public void _jspinit () {
_el_expressionfactory = _jspxfactory.getjspapplicationcontext (Getservletconfig (). GetServletContext ()). Getexpressionfactory ();
_jsp_instancemanager = Org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager (Getservletconfig ( ));
}
public void _jspdestroy () {
}
public void _jspservice (final javax.servlet.http.HttpServletRequest request, final Javax.servlet.http.HttpServletResponse response)
throws Java.io.IOException, javax.servlet.ServletException {
final Javax.servlet.jsp.PageContext PageContext;
javax.servlet.http.HttpSession session = NULL;
final Javax.servlet.ServletContext Application;
Final Javax.servlet.ServletConfig config;
javax.servlet.jsp.JspWriter out = null;
Final Java.lang.Object page = this;
Javax.servlet.jsp.JspWriter _jspx_out = null;
Javax.servlet.jsp.PageContext _jspx_page_context = null;
try {
Response.setcontenttype ("Text/html;charset=utf-8");
PageContext = _jspxfactory.getpagecontext (this, request, response,
null, True, 8192, true);
_jspx_page_context = PageContext;
application = Pagecontext.getservletcontext ();
config = Pagecontext.getservletconfig ();
session = Pagecontext.getsession ();
out = Pagecontext.getout ();
_jspx_out = out;
out.write ("RN");
out.write ("<html>rn");
out.write ("T<head>rn");
out.write ("Tt<title>test demo</title>rn");
out.write ("T</head>rn");
out.write ("T<body>rn");
out.write ("tt<!--This is a page annotation-->rn");
out.write ("tt");
out.write ("RN");
out.write ("T</body>rn");
out.write ("</html>");
} catch (Java.lang.Throwable t) {
if (!) ( T instanceof Javax.servlet.jsp.SkipPageException)) {
out = _jspx_out;
if (out!= null && out.getbuffersize ()!= 0)
try {out.clearbuffer ();} catch (Java.io.IOException e) {}
if (_jspx_page_context!= null) _jspx_page_context.handlepageexception (t);
Else throw new servletexception (t);
}
} finally {
_jspxfactory.releasepagecontext (_jspx_page_context);
}
}
}