• <%!%>和<%%>的区别


    JSP 文件需要转换成 Java 类。在访问 JSP 文件的时候,并不直接执行 JSP 文件,而是执行 JSP 文件对应的 Java (class 文件) 的对象, 这个 Java 文件是服务器根据我们提供JSP 文件创建的。在 Tomcat 安装目录下的 work 目录中有 JSP 文件转换成的 Java 文件。<%!%>中定义的变量是类变量,<%%>中定义的变量是局部变量。举例如下:

    index.jsp

    <%@ page language="java" contentType="text/html; charset=GB18030"
        pageEncoding="GB18030"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=GB18030">
    <title>欢迎页面</title>
    </head>
    <body>
    <%!int hitnumber=1; %>
    <%int jubu=1; %>
    </body>
    </html>

    对应的Java类:

    index_jsp.java

    /*
     * Generated by the Jasper component of Apache Tomcat
     * Version: Apache Tomcat/8.0.3
     * Generated at: 2015-05-06 06:16:43 UTC
     * Note: The last modified time of this file was 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 xixihaha_jsp extends org.apache.jasper.runtime.HttpJspBase
        implements org.apache.jasper.runtime.JspSourceDependent {
    
    int hitnumber=1; 
      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=GB18030");
          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("<!DOCTYPE html PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\" \"http://www.w3.org/TR/html4/loose.dtd\">\r\n");
          out.write("<html>\r\n");
          out.write("<head>\r\n");
          out.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=GB18030\">\r\n");
          out.write("<title>欢迎页面</title>\r\n");
          out.write("</head>\r\n");
          out.write("<body>\r\n");
          out.write('\r');
          out.write('\n');
    int jubu=1; 
          out.write("\r\n");
          out.write("</body>\r\n");
          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);
        }
      }
    }
  • 相关阅读:
    【BZOJ】1626: [Usaco2007 Dec]Building Roads 修建道路(kruskal)
    【BZOJ】1669: [Usaco2006 Oct]Hungry Cows饥饿的奶牛(lis)
    【BZOJ】1666: [Usaco2006 Oct]Another Cow Number Game 奶牛的数字游戏(刷水严重)
    【BZOJ】1699: [Usaco2007 Jan]Balanced Lineup排队(rmq/树状数组)
    【BZOJ】1625: [Usaco2007 Dec]宝石手镯(01背包)
    【BZOJ】1617: [Usaco2008 Mar]River Crossing渡河问题(dp)
    【BZOJ】1618: [Usaco2008 Nov]Buying Hay 购买干草(dp)
    【BZOJ】1616: [Usaco2008 Mar]Cow Travelling游荡的奶牛(dp/-bfs)
    【BZOJ】1613: [Usaco2007 Jan]Running贝茜的晨练计划(dp)
    【BZOJ】1612: [Usaco2008 Jan]Cow Contest奶牛的比赛(floyd/dfs)
  • 原文地址:https://www.cnblogs.com/anan1688/p/4481954.html
Copyright © 2020-2023  润新知