JSP ———— > servlet
My 1th Java Web application--index.jsp
My 2nd Java Web application--welcome-file
My 3rd Java Web application--conf/server.xml
My 4th Java Web application--jsp page
My 5th Java Web application--jsp script
My 6th Java Web application--jsp declaration
My 7th Java Web application--jsp expression
My 8th Java Web application--jsp page life cycle
My 8th Java Web application-my multiplication table!
1
<!DOCTYPE HTML><HTMLLang= "en"> <Head> <MetaCharSet= "UTF-8"> <Metaname= "Generator"content= "editplus®"> <Metaname= "Author"content=""> <Metaname= "Keywords"content=""> <Metaname= "Description"content=""> <title>Document</title> </Head> <Body> <H1>???????</H1> </Body></HTML>
<? ?><xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE" Xmlns:xsi = "Http://www.w3.org/2001/XMLSchema-instance" xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/ Web-app_2_4.xsd " version=" 2.4 "></Web-app >
2
<?XML version= "1.0" encoding= "Iso-8859-1"?><Web-appxmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"version= "2.4"> <welcome-file-list> <Welcome-file>/index.jsp</Welcome-file> </welcome-file-list></Web-app>
3
4
Jsp=java Server Page
<%@ page language= "java" import= "java.util.*" contenttype= "Text/html;charset=utf-8"%><HTML> <Body> <H1Align= "Center">Beer recommendation</H1> <P> <% ListStyles= (List) request.getattribute ("Styles"); Iterator It= Styles.iterator (); While (It.hasnext ()) {Out.print ("<br>try: "+ it.next ()); }%></Body></HTML>
5
Import= "java.util.*" contenttype= "Text/html;charset=utf-8"%> = (List) request.getattribute ("Styles" ); = styles.iterator (); while (It.hasnext ()) { out.print ("<br>try:" + It.next ()); } %> <% out.print ("<br/><br/> The weather looks good today!" "); Out is a built-in Object! %> </body>
6
Differences between the two methods of declaration. Reference: http://www.cnblogs.com/zengmiaogen/archive/2012/04/15/2450414.html
We can declare variables in <%%>, and we can declare variables in <%!%>.
So what is the difference between the two ways of declaring? In fact,,<%!%> equals the instance domain of the class, and <%%> equals the method body.
To-do
7
Import= "java.util.*" contenttype= "Text/html;charset=utf-8"%> a simple test</p> <%! = "This was a simple test." ; int sum (intint y) { return x + y; } %> <p>words=<%=words%></p> <p>3+4=<%=sum (3,4)%> </p> </body>
8
When we visit the JSP page, the JSP engine (Web container) first determines whether it is the first request ...
This time I think, if you can see the compiled bytecode directly, then where to view it? --the answer is in the Tomcat work directory, not only the bytecode, but also the source code, we look at the previous section of the code.
/** Generated by the Jasper component of Apache Tomcat * Version:apache tomcat/7.0.77 * Generated at:2017-06-09 10:07 : 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. */ Packageorg.apache.jsp;Importjavax.servlet.*;Importjavax.servlet.http.*;Importjavax.servlet.jsp.*;ImportJava.util.*; Public Final classtest_jspextendsOrg.apache.jasper.runtime.HttpJspBaseImplementsorg.apache.jasper.runtime.JspSourceDependent {String words= "This was a simple test."; intSumintXinty) {returnX +y; } Private Static FinalJavax.servlet.jsp.JspFactory _jspxfactory =javax.servlet.jsp.JspFactory.getDefaultFactory (); Private StaticJava.util.map<java.lang.string,java.lang.long>_jspx_dependants; Private volatilejavax.el.ExpressionFactory _el_expressionfactory; Private volatileOrg.apache.tomcat.InstanceManager _jsp_instancemanager; PublicJava.util.map<java.lang.string,java.lang.long>getdependants () {return_jspx_dependants; } Publicjavax.el.ExpressionFactory _jsp_getexpressionfactory () {if(_el_expressionfactory = =NULL) { synchronized( This) { if(_el_expressionfactory = =NULL) {_el_expressionfactory=_jspxfactory.getjspapplicationcontext (Getservletconfig (). Getservletcontext ()). Getexpressionfactory (); } } } return_el_expressionfactory; } PublicOrg.apache.tomcat.InstanceManager _jsp_getinstancemanager () {if(_jsp_instancemanager = =NULL) { synchronized( This) { if(_jsp_instancemanager = =NULL) {_jsp_instancemanager=Org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager (Getservletconfig ()); } } } return_jsp_instancemanager; } Public void _jspinit () {} 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 {fi NAL 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 ("\ r \ n"); Out.write ("\ r \ n"); Out.write (" {_jspxfactory.releasepagecontext (_jspx_page_context); } }}
9
Import= "java.util.*" contenttype= "Text/html;charset=utf-8"%> for (int i = 1; I <= 9; + +i) {for (int j = 1; J <= I; + +J) {+ "*" + j + "=" + I*j + " "); } Out.print ("<br/>"); } %> </body>
After watching the video modified, is a space placeholder
<%@ page language= "Java"Import= "java.util.*" contenttype= "Text/html;charset=utf-8"%>voidprinttable () { for(inti = 1; I <= 9; ++i) { for(intj = 1; J <= I; ++j) {Out.print (i+ "*" + j + "=" + I*j + " "); } out.print ("<br/>"); } } %> <%printtable (); %> </body>
JSP Note 01--Basic syntax