服务热线:13616026886

技术文档 欢迎使用技术文档,我们为你提供从新手到专业开发者的所有资源,你也可以通过它日益精进

位置:首页 > 技术文档 > JAVA > 新手入门 > 基础入门 > 查看文档

jsp研究(一)

用jsp开发了程序好些时间了,但感觉对jsp的掌握还是不够。现在先分析一下*.jsp文件编译后的*_jsp.java 文件。
先写一个简单的my.jsp文件如下:

<%@ page contenttype="text/html; charset=gb2312" language="java" import="java.sql.*" errorpage="" %>
<!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=gb2312">
<title>baiming</title>
</head>

<body>
hello
</body>
</html>
****************************************************************
把改文件方到 tomcat根目录/webapps/root 下。
运行tomcat,在地址栏里输入http://localhost:8080/my.jsp
在 tomcat根目录/work/catalina/localhost/_/org/apache/jsp 下就会生成my_jsp.java文件。
我们现在来看看这个文件:
package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.sql.*;

public final class my_jsp extends org.apache.jasper.runtime.httpjspbase
    implements org.apache.jasper.runtime.jspsourcedependent {

  private static java.util.vector _jspx_dependants;

  public java.util.list getdependants() {
    return _jspx_dependants;
  }

  public void _jspservice(httpservletrequest request, httpservletresponse response)
        throws java.io.ioexception, servletexception {

    jspfactory _jspxfactory = null;
    pagecontext pagecontext = null;
    httpsession session = null;
    servletcontext application = null;
    servletconfig config = null;
    jspwriter out = null;
    object page = this;
    jspwriter _jspx_out = null;


    try {
      _jspxfactory = jspfactory.getdefaultfactory();
      response.setcontenttype("text/html; charset=gb2312");
      pagecontext = _jspxfactory.getpagecontext(this, request, response,
         "", true, 8192, true);
      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=gb2312/">/r/n");
      out.write("<title>baiming</title>/r/n");
      out.write("</head>/r/n");
      out.write("/r/n");
      out.write("<body>/r/n");
      out.write("hello/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)
          out.clearbuffer();
        if (pagecontext != null) pagecontext.handlepageexception(t);
      }
    } finally {
      if (_jspxfactory != null) _jspxfactory.releasepagecontext(pagecontext);
    }
  }
}

你会发现jsp里使用的8个隐含的对象。

扫描关注微信公众号