步骤 2 : hello_jsp.java 为什么是Servlet
1. 把 hello.jsp转译为hello_jsp.java
2. hello_jsp.java 位于 d:\tomcat\work\Catalina\localhost\_\org\apache\jsp 3. hello_jsp.java是一个servlet 4. 把hello_jsp.java 编译为hello_jsp.class 5. 执行hello_jsp,生成html 6. 通过http协议把html 响应返回给浏览器
在Servlet章节中,我们说HelloServlet是一个Servlet,不是因为它的类名里有一个"Servlet",而是因为它继承了 HttpServlet
打开转译hello.jsp 后得到的hello_jsp.java,可以发现它继承了类 (D:\tomcat\work\Catalina\localhost\_\org\apache\jsp\hello_jsp.java) org.apache.jasper.runtime.HttpJspBase 而HttpJspBase 继承了HttpServlet 所以我们说hello_.jsp.java 是一个Servlet /*
* Generated by the Jasper component of Apache Tomcat
* Version: Apache Tomcat/7.0.64
* Generated at: 2017-01-07 01:45: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.*;
public final class hello_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
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=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("你好 JSP\r\n");
out.write(" \r\n");
out.write("<br>\r\n");
out.write(" \r\n");
out.print(new Date().toLocaleString());
} catch (java.lang.Throwable t) {
if (!(t instanceof javax.servlet.jsp.SkipPageException)){
out = _jspx_out;
if (out != null && out.getBufferSize() != 0)
try {
if (response.isCommitted()) {
out.flush();
} else {
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);
}
}
}
HOW2J公众号,关注后实时获知最新的教程和优惠活动,谢谢。
问答区域
2019-11-13
我在自己部署的tomcat下的路径没有找到hello_jsp.java文件呀,路径文件都不存在
1 个答案
四叶猫 跳转到问题位置 答案时间:2019-12-26 你的项目是dynamic web吧,站长的例子是普通的java项目,所以路径可能不太一样。
给你参考一下我的路径:项目\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\j2eeCRUD\org\apache\jsp
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2017-10-29
哇哇哇,找到了!!
回答已经提交成功,正在审核。 请于 我的回答 处查看回答记录,谢谢
2017-10-29
站长,正常运行的IDEA,在哪里看转译之后的servlet?
2017-01-12
hello_jsp.class
提问之前请登陆
提问已经提交成功,正在审核。 请于 我的提问 处查看提问记录,谢谢
|