JSP研究(一)
2004-11-20 23:39
525 查看
用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个隐含的对象。
out.write( )用于输出html流,也就是客户端收到的html内容。
先写一个简单的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个隐含的对象。
out.write( )用于输出html流,也就是客户端收到的html内容。
相关文章推荐
- jsp的request及增进研究【1】--资料准备
- jsp的request及增进研究【3】--给自己的类加上文件上传功能
- jsp的request及增进研究【4】--URL传参,post传参乱码原因及修正
- 基于JSP的固定资产管理系统的研究与设计
- JSP Servlet中Request与Response所有成员方法的研究
- 研究了三天的文件上传(jspsmart实现)file和text表单同时提交的问题
- 研究了三天的文件上传(jspsmart实现)file和text表单同时提交的问题
- JSP中标签库的深入研究
- JSP研究(二)learn servlet
- jsp对于关闭mysql数据库的研究(数据库连接数过多)
- JSP 通过 URL 传变量时,出现乱码的几点研究和解决方法
- 网页模板技术研究:为什么要用模板生成网页而不用jsp等技术?
- jsp/servlet/jsf--标签库的深入研究
- JSP的相对路径深入研究(多次完善)
- JSP重复提交的研究
- JSP的相对路径如何计算深入研究
- Shark 工作流研究1-在Tomcat6上部署Shark Workflow的jspClient示例 收
- 基于JSP技术进行信息交互的研究与应用
- JSP的相对路径深入研究!
- JSP页面编码问题研究