<!-- HTML注释 --> html注释被当作模版元素输出到了浏览器上,浏览器认识html注释不予显示
代码:
<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title></title> <meta http-equiv=" pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> </head> <!-- 去哪里看被翻译的jsp呢?tomcat目录的work目录下的localhost....找出相应的翻译的源代码 --> <body> <%--jsp表达式(不以分号结束)--> 在翻译过来的servlet直接计算出结果,使用out输出到浏览器中--%> <%=1+1 %> <%--jsp脚本片段-->直接拷贝内容到jsp被翻译的servlet中 --%> <% int i=0; out.print(i); %> <%--jsp声明-->在翻译过来的servlet直接放到与service()方法同级的 位置,变成了类的成员--%> <%!int j=7; %> </body> </html>对应翻译的代码:
package org.apache.jsp.jsp; import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import java.util.*; public final class jspDemo1_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { int j=7; private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); private static java.util.List _jspx_dependants; private javax.el.ExpressionFactory _el_expressionfactory; private org.apache.AnnotationProcessor _jsp_annotationprocessor; public Object getDependants() { return _jspx_dependants; } public void _jspInit() { _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory(); _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName()); } public void _jspDestroy() { } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; 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("\r\n"); out.write("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\r\n"); out.write("<html>\r\n"); out.write(" <head>\r\n"); out.write(" \r\n"); out.write(" \r\n"); out.write(" <title></title>\r\n"); out.write(" \r\n"); out.write("\t<meta http-equiv=\" pragma\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"cache-control\" content=\"no-cache\">\r\n"); out.write("\t<meta http-equiv=\"expires\" content=\"0\"> \r\n"); out.write("\t\r\n"); out.write(" </head>\r\n"); out.write(" <!-- 去哪里看被翻译的jsp呢?--> -->\r\n"); out.write(" <body>\r\n"); out.write(" "); out.write("\r\n"); out.write(" "); out.print(1+1 ); out.write("\r\n"); out.write(" "); out.write("\r\n"); out.write(" "); int i=0; out.print(i); out.write("\r\n"); out.write(" "); out.write("\r\n"); out.write(" "); out.write("\r\n"); out.write(" </body>\r\n"); out.write("</html>\r\n"); } catch (Throwable t) { if (!(t instanceof 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); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } } }我们可以看到j变量放在了与service 同级位置作为成员属性。i是service()的方法的局部变量
对于表达式。直接计算。
原文:http://blog.csdn.net/u014010769/article/details/46551569