zoukankan      html  css  js  c++  java
  • JSP页面中的pageEncoding和contentType两种属性

    JSP page指令:

    JSP文件:

    复制代码
    <%@ page language="java"%>
    <%@ page import="java.util.*"%>
    <%@ page isThreadSafe="false"%>
    <%@ page contentType="text/html; charset=UTF-8"%>
    <%@ page isELIgnored="true"%>
    <%@ page isErrorPage="true"%>
    <%@ page errorPage="index0051.jsp"%>
    <!-- %@ page extends="org.apache.jsp"% -->
    <%@ page session="false"%>
    <%@ page buffer="none"%>
    <%@ page autoFlush="true"%>
    <%@ page info="infotext"%>
    <%@ page pageEncoding="UTF-8"%>
    <%
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
        pageContext.setAttribute("pca", "pageContextAttribute");
        //session.setAttribute("s", "session");
    %>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>005index</title>
    </head>
    <body>
        <p>Page指令</p>
        <p>Page指令可以在页面内随便放置,最好放在页首;</p>
        <p>language属性不写可以,写成别的会无法编译,异常为:org.apache.jasper.JasperException: /index005.jsp (line: 1, column: 2) Page directive: invalid language attribute</p>
        <%@ page import="a.b.*"%>
        <p>import属性,写了之后会自动添加到servlet的import语句中,但不进行包存在性的检查;反编译生成的class中就没有无效的包;</p>
        <p>isThreadSafe问你的应用是否是线程安全的,缺省为true,表示应用是线程安全的,可以同时响应多个请求;如果设置为false,生成的servlet会实现javax.servlet.SingleThreadModel线程,那么一次只能处理一个用户请求;</p>
        <p>${pageScope.pca }</p>
        <p>isELIgnored忽略el表达式</p>
        <p>errorPage="relativeURL" 设置处理异常事件的JSP文件。 isErrorPage="true | false" 设置此页是否为出错页,如果被设置为true,你就能使用exception对象.</p>
        <p>extends="package.class" 标明JSP编译时需要加入的Java Class的全名,但是得慎重的使用它,它会限制JSP的编译能力.写成别的就无法转换了。org.apache.jasper.JasperException: Unable to compile class for JSP:</p>
        <p>session="false"就没有session对象了;</p>
        <p>contentType属性设置发送到客户端文档的响应报头的MIME类型和字符编码。多个使用;号分开。 pageEncodeing属性只用于更改字符编码。</p>
        <p>buffer属性指定out对象(JspWriter)使用的缓冲区大小,以kb为单位,默认8kb。 none表示不使用缓冲区。这样要求设置报头或状态代码的jsp元素要出现在文件的顶部,任何HTML内容之前。 autoFlush属性控制当缓冲区满了后,是自动清空输出缓冲区(默认true),还是在缓冲区溢出后抛出异常(false)。
            在buffer=none的时候,autoFlush=false是错误的。</p>
        <p>定义一个可以在servlet中通过getServletInfo方法获取的字符串。 jsp容器做的是在servlet中生成getServletInfo方法返回info属性指定的String。</p>
    </body>
    </html>
    复制代码

     

    JSP转换的java文件:

    复制代码
    /*
     * Generated by the Jasper component of Apache Tomcat
     * Version: Apache Tomcat/7.0.35
     * Generated at: 2015-10-20 00:27:17 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.*;
    import java.util.*;
    import a.b.*;
    
    public final class index005_jsp extends org.apache.jasper.runtime.HttpJspBase
        implements org.apache.jasper.runtime.JspSourceDependent,
                     javax.servlet.SingleThreadModel {
    
      public java.lang.String getServletInfo() {
        return "infotext";
      }
    
      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;
        java.lang.Throwable exception = org.apache.jasper.runtime.JspRuntimeLibrary.getThrowable(request);
        if (exception != null) {
          response.setStatus(javax.servlet.http.HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
        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,
                      "index0051.jsp", false, 0, true);
          _jspx_page_context = pageContext;
          application = pageContext.getServletContext();
          config = pageContext.getServletConfig();
          out = pageContext.getOut();
          _jspx_out = out;
    
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("<!-- %@ page extends="org.apache.jsp"% -->
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
    
        String path = request.getContextPath();
        String basePath = request.getScheme() + "://" + request.getServerName() + ":" + request.getServerPort() + path + "/";
        pageContext.setAttribute("pca", "pageContextAttribute");
        //session.setAttribute("s", "session");
    
          out.write("
    ");
          out.write("<!DOCTYPE html>
    ");
          out.write("<html>
    ");
          out.write("<head>
    ");
          out.write("<meta charset="UTF-8">
    ");
          out.write("<title>005index</title>
    ");
          out.write("</head>
    ");
          out.write("<body>
    ");
          out.write("	<p>Page指令</p>
    ");
          out.write("	<p>Page指令可以在页面内随便放置,最好放在页首;</p>
    ");
          out.write("	<p>language属性不写可以,写成别的会无法编译,异常为:org.apache.jasper.JasperException: /index005.jsp (line: 1, column: 2) Page directive: invalid language attribute</p>
    ");
          out.write("	
    ");
          out.write("	<p>import属性,写了之后会自动添加到servlet的import语句中,但不进行包存在性的检查;反编译生成的class中就没有无效的包;</p>
    ");
          out.write("	<p>isThreadSafe问你的应用是否是线程安全的,缺省为true,表示应用是线程安全的,可以同时响应多个请求;如果设置为false,生成的servlet会实现javax.servlet.SingleThreadModel线程,那么一次只能处理一个用户请求;</p>
    ");
          out.write("	<p>${pageScope.pca }</p>
    ");
          out.write("	<p>isELIgnored忽略el表达式</p>
    ");
          out.write("	<p>errorPage="relativeURL" 设置处理异常事件的JSP文件。 isErrorPage="true | false" 设置此页是否为出错页,如果被设置为true,你就能使用exception对象.</p>
    ");
          out.write("	<p>extends="package.class" 标明JSP编译时需要加入的Java Class的全名,但是得慎重的使用它,它会限制JSP的编译能力.写成别的就无法转换了。org.apache.jasper.JasperException: Unable to compile class for JSP:</p>
    ");
          out.write("	<p>session="false"就没有session对象了;</p>
    ");
          out.write("	<p>contentType属性设置发送到客户端文档的响应报头的MIME类型和字符编码。多个使用;号分开。 pageEncodeing属性只用于更改字符编码。</p>
    ");
          out.write("	<p>buffer属性指定out对象(JspWriter)使用的缓冲区大小,以kb为单位,默认8kb。 none表示不使用缓冲区。这样要求设置报头或状态代码的jsp元素要出现在文件的顶部,任何HTML内容之前。 autoFlush属性控制当缓冲区满了后,是自动清空输出缓冲区(默认true),还是在缓冲区溢出后抛出异常(false)。
    ");
          out.write("		在buffer=none的时候,autoFlush=false是错误的。</p>
    ");
          out.write("	<p>定义一个可以在servlet中通过getServletInfo方法获取的字符串。 jsp容器做的是在servlet中生成getServletInfo方法返回info属性指定的String。</p>
    ");
          out.write("</body>
    ");
          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);
        }
      }
    }
    复制代码

     

    反编译class文件:

    复制代码
    package org.apache.jsp;
    
    import java.io.IOException;
    import java.util.Map;
    import javax.el.ExpressionFactory;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletException;
    import javax.servlet.SingleThreadModel;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.jsp.JspApplicationContext;
    import javax.servlet.jsp.JspFactory;
    import javax.servlet.jsp.JspWriter;
    import javax.servlet.jsp.PageContext;
    import javax.servlet.jsp.SkipPageException;
    import org.apache.jasper.runtime.HttpJspBase;
    import org.apache.jasper.runtime.InstanceManagerFactory;
    import org.apache.jasper.runtime.JspRuntimeLibrary;
    import org.apache.jasper.runtime.JspSourceDependent;
    import org.apache.tomcat.InstanceManager;
    
    public final class index005_jsp extends HttpJspBase
      implements JspSourceDependent, SingleThreadModel
    {
      private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
      private static Map<String, Long> _jspx_dependants;
      private ExpressionFactory _el_expressionfactory;
      private InstanceManager _jsp_instancemanager;
    
      public String getServletInfo()
      {
        return "infotext";
      }
    
      public Map<String, Long> getDependants()
      {
        return _jspx_dependants;
      }
    
      public void _jspInit() {
        this._el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
        this._jsp_instancemanager = InstanceManagerFactory.getInstanceManager(getServletConfig());
      }
    
      public void _jspDestroy()
      {
      }
    
      public void _jspService(HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException
      {
        Throwable exception = JspRuntimeLibrary.getThrowable(request);
        if (exception != null) {
          response.setStatus(500);
        }
    
        JspWriter out = null;
    
        JspWriter _jspx_out = null;
        PageContext _jspx_page_context = null;
        try
        {
          response.setContentType("text/html; charset=UTF-8");
          PageContext pageContext = _jspxFactory.getPageContext(this, request, response, 
            "index0051.jsp", false, 0, true);
          _jspx_page_context = pageContext;
          pageContext.getServletContext();
          pageContext.getServletConfig();
          out = pageContext.getOut();
          _jspx_out = out;
    
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("<!-- %@ page extends="org.apache.jsp"% -->
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
          out.write("
    ");
    
          String path = request.getContextPath();
          new StringBuilder(String.valueOf(request.getScheme())).append("://").append(request.getServerName()).append(":").append(request.getServerPort()).append(path).append("/").toString();
          pageContext.setAttribute("pca", "pageContextAttribute");
    
          out.write("
    ");
          out.write("<!DOCTYPE html>
    ");
          out.write("<html>
    ");
          out.write("<head>
    ");
          out.write("<meta charset="UTF-8">
    ");
          out.write("<title>005index</title>
    ");
          out.write("</head>
    ");
          out.write("<body>
    ");
          out.write("	<p>Page指令</p>
    ");
          out.write("	<p>Page指令可以在页面内随便放置,最好放在页首;</p>
    ");
          out.write("	<p>language属性不写可以,写成别的会无法编译,异常为:org.apache.jasper.JasperException: /index005.jsp (line: 1, column: 2) Page directive: invalid language attribute</p>
    ");
          out.write("	
    ");
          out.write("	<p>import属性,写了之后会自动添加到servlet的import语句中,但不进行包存在性的检查;反编译生成的class中就没有无效的包;</p>
    ");
          out.write("	<p>isThreadSafe问你的应用是否是线程安全的,缺省为true,表示应用是线程安全的,可以同时响应多个请求;如果设置为false,生成的servlet会实现javax.servlet.SingleThreadModel线程,那么一次只能处理一个用户请求;</p>
    ");
          out.write("	<p>${pageScope.pca }</p>
    ");
          out.write("	<p>isELIgnored忽略el表达式</p>
    ");
          out.write("	<p>errorPage="relativeURL" 设置处理异常事件的JSP文件。 isErrorPage="true | false" 设置此页是否为出错页,如果被设置为true,你就能使用exception对象.</p>
    ");
          out.write("	<p>extends="package.class" 标明JSP编译时需要加入的Java Class的全名,但是得慎重的使用它,它会限制JSP的编译能力.写成别的就无法转换了。org.apache.jasper.JasperException: Unable to compile class for JSP:</p>
    ");
          out.write("	<p>session="false"就没有session对象了;</p>
    ");
          out.write("	<p>contentType属性设置发送到客户端文档的响应报头的MIME类型和字符编码。多个使用;号分开。 pageEncodeing属性只用于更改字符编码。</p>
    ");
          out.write("	<p>buffer属性指定out对象(JspWriter)使用的缓冲区大小,以kb为单位,默认8kb。 none表示不使用缓冲区。这样要求设置报头或状态代码的jsp元素要出现在文件的顶部,任何HTML内容之前。 autoFlush属性控制当缓冲区满了后,是自动清空输出缓冲区(默认true),还是在缓冲区溢出后抛出异常(false)。
    ");
          out.write("		在buffer=none的时候,autoFlush=false是错误的。</p>
    ");
          out.write("	<p>定义一个可以在servlet中通过getServletInfo方法获取的字符串。 jsp容器做的是在servlet中生成getServletInfo方法返回info属性指定的String。</p>
    ");
          out.write("</body>
    ");
          out.write("</html>
    ");
        } catch (Throwable t) {
          if (!(t instanceof SkipPageException)) {
            out = _jspx_out;
            if ((out != null) && (out.getBufferSize() != 0)) try {
                out.clearBuffer(); } catch (IOException localIOException) { }
            if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
            else throw new ServletException(t);
          }
    
          _jspxFactory.releasePageContext(_jspx_page_context); } finally { _jspxFactory.releasePageContext(_jspx_page_context);
        }
      }
    }
  • 相关阅读:
    堆排序
    jdk8 永久代变更
    oracle 区分大小写遇到的坑
    日志统计分析
    zookeeper 服务挂掉重启后,dubbo 服务是不会自动重新注册上的
    代码质量管理
    快速排序算法
    python flask 项目结构
    项目架构
    JS中的循环---最全的循环总结
  • 原文地址:https://www.cnblogs.com/jinhengyu/p/10258113.html
Copyright © 2011-2022 走看看