jsp编译后的文件位置(Eclipse和tomcat)

java web开发人员都知道,jsp其实是转化成java代码,通过out.write()的方式生成页面。今天想看看转化的java源代码,通过查找发现Eclipse和tomcat的存储在不同的位置:
jsp其实是转化成java代码(通过tomcat将.jsp转换成.java同时还生成了.class(运行))
【Eclipse】

.metadata.plugins\org.eclipse.wst.server.core\tmpX\work\Catalina<项目名称>
eg:E:\eclipseProject.metadata.plugins\org.eclipse.wst.server.core\tmp0\work\Catalina\localhost\hh\org\apache\jsp


jsp编译后的文件位置(Eclipse和tomcat)_第1张图片
image.png

jsp.java内容如下:
/*

  • Generated by the Jasper component of Apache Tomcat
  • Version: Apache Tomcat/7.0.88
  • Generated at: 2018-07-19 02:22:57 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 NewFile_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 _jspx_dependants;

private volatile javax.el.ExpressionFactory _el_expressionfactory;
private volatile org.apache.tomcat.InstanceManager _jsp_instancemanager;

public java.util.Map getDependants() {
return _jspx_dependants;
}

public javax.el.ExpressionFactory _jsp_getExpressionFactory() {
if (_el_expressionfactory == null) {
synchronized (this) {
if (_el_expressionfactory == null) {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
}
}
}
return _el_expressionfactory;
}

public org.apache.tomcat.InstanceManager _jsp_getInstanceManager() {
if (_jsp_instancemanager == null) {
synchronized (this) {
if (_jsp_instancemanager == null) {
_jsp_instancemanager = org.apache.jasper.runtime.InstanceManagerFactory.getInstanceManager(getServletConfig());
}
}
}
return _jsp_instancemanager;
}

public void _jspInit() {
}

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=ISO-8859-1");
  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("\r\n");
  out.write("\r\n");
  out.write("\r\n");
  out.write("Insert title here\r\n");
  out.write("\r\n");
  out.write("\r\n");
  out.write("\t
\r\n"); out.write("\t\t \r\n"); out.write("\t
\r\n"); out.write("\r\n"); out.write(""); } 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); }

}
}
jsp.class内容如下:(通过反编译工具jd-gui)
package org.apache.jsp;

import java.util.Map;
import javax.el.ExpressionFactory;
import javax.servlet.ServletConfig;
import javax.servlet.jsp.JspApplicationContext;
import javax.servlet.jsp.JspFactory;
import org.apache.jasper.runtime.HttpJspBase;
import org.apache.jasper.runtime.InstanceManagerFactory;
import org.apache.jasper.runtime.JspSourceDependent;
import org.apache.tomcat.InstanceManager;

public final class NewFile_jsp
extends HttpJspBase
implements JspSourceDependent
{
private static final JspFactory _jspxFactory = ;
private static Map _jspx_dependants;
private volatile ExpressionFactory _el_expressionfactory;
private volatile InstanceManager _jsp_instancemanager;

public Map getDependants()
{
return _jspx_dependants;
}

public ExpressionFactory _jsp_getExpressionFactory()
{
if (this._el_expressionfactory == null) {
synchronized (this)
{
if (this._el_expressionfactory == null) {
this._el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
}
}
}
return this._el_expressionfactory;
}

public InstanceManager _jsp_getInstanceManager()
{
if (this._jsp_instancemanager == null) {
synchronized (this)
{
if (this._jsp_instancemanager == null) {
this._jsp_instancemanager = InstanceManagerFactory.getInstanceManager(getServletConfig());
}
}
}
return this._jsp_instancemanager;
}

public void _jspInit() {}

public void _jspDestroy() {}

/* Error */
public void _jspService(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response)
throws java.io.IOException, javax.servlet.ServletException
{
// Byte code:
// 0: aconst_null
// 1: astore 4
// 3: aconst_null
// 4: astore 5
// 6: aconst_null
// 7: astore 6
// 9: aload_2
// 10: ldc 85
// 12: invokeinterface 87 2 0
// 17: getstatic 26 org/apache/jsp/NewFile_jsp:_jspxFactory Ljavax/servlet/jsp/JspFactory;
// 20: aload_0
// 21: aload_1
// 22: aload_2
// 23: aconst_null
// 24: iconst_1
// 25: sipush 8192
// 28: iconst_1
// 29: invokevirtual 93 javax/servlet/jsp/JspFactory:getPageContext (Ljavax/servlet/Servlet;Ljavax/servlet/ServletRequest;Ljavax/servlet/ServletResponse;Ljava/lang/String;ZIZ)Ljavax/servlet/jsp/PageContext;
// 32: astore_3
// 33: aload_3
// 34: astore 6
// 36: aload_3
// 37: invokevirtual 97 javax/servlet/jsp/PageContext:getServletContext ()Ljavax/servlet/ServletContext;
// 40: pop
// 41: aload_3
// 42: invokevirtual 100 javax/servlet/jsp/PageContext:getServletConfig ()Ljavax/servlet/ServletConfig;
// 45: pop
// 46: aload_3
// 47: invokevirtual 101 javax/servlet/jsp/PageContext:getSession ()Ljavax/servlet/http/HttpSession;
// 50: pop
// 51: aload_3
// 52: invokevirtual 105 javax/servlet/jsp/PageContext:getOut ()Ljavax/servlet/jsp/JspWriter;
// 55: astore 4
// 57: aload 4
// 59: astore 5
// 61: aload 4
// 63: ldc 109
// 65: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 68: aload 4
// 70: ldc 116
// 72: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 75: aload 4
// 77: ldc 118
// 79: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 82: aload 4
// 84: ldc 120
// 86: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 89: aload 4
// 91: ldc 122
// 93: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 96: aload 4
// 98: ldc 124
// 100: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 103: aload 4
// 105: ldc 126
// 107: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 110: aload 4
// 112: ldc -128
// 114: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 117: aload 4
// 119: ldc -126
// 121: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 124: aload 4
// 126: ldc -124
// 128: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 131: aload 4
// 133: ldc -122
// 135: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 138: aload 4
// 140: ldc -120
// 142: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 145: aload 4
// 147: ldc -118
// 149: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 152: aload 4
// 154: ldc -116
// 156: invokevirtual 111 javax/servlet/jsp/JspWriter:write (Ljava/lang/String;)V
// 159: goto +105 -> 264
// 162: astore 7
// 164: aload 7
// 166: instanceof 142
// 169: ifne +71 -> 240
// 172: aload 5
// 174: astore 4
// 176: aload 4
// 178: ifnull +37 -> 215
// 181: aload 4
// 183: invokevirtual 144 javax/servlet/jsp/JspWriter:getBufferSize ()I
// 186: ifeq +29 -> 215
// 189: aload_2
// 190: invokeinterface 148 1 0
// 195: ifeq +11 -> 206
// 198: aload 4
// 200: invokevirtual 152 javax/servlet/jsp/JspWriter:flush ()V
// 203: goto +12 -> 215
// 206: aload 4
// 208: invokevirtual 155 javax/servlet/jsp/JspWriter:clearBuffer ()V
// 211: goto +4 -> 215
// 214: pop
// 215: aload 6
// 217: ifnull +13 -> 230
// 220: aload 6
// 222: aload 7
// 224: invokevirtual 158 javax/servlet/jsp/PageContext:handlePageException (Ljava/lang/Throwable;)V
// 227: goto +13 -> 240
// 230: new 83 javax/servlet/ServletException
// 233: dup
// 234: aload 7
// 236: invokespecial 162 javax/servlet/ServletException: (Ljava/lang/Throwable;)V
// 239: athrow
// 240: getstatic 26 org/apache/jsp/NewFile_jsp:_jspxFactory Ljavax/servlet/jsp/JspFactory;
// 243: aload 6
// 245: invokevirtual 164 javax/servlet/jsp/JspFactory:releasePageContext (Ljavax/servlet/jsp/PageContext;)V
// 248: goto +24 -> 272
// 251: astore 8
// 253: getstatic 26 org/apache/jsp/NewFile_jsp:_jspxFactory Ljavax/servlet/jsp/JspFactory;
// 256: aload 6
// 258: invokevirtual 164 javax/servlet/jsp/JspFactory:releasePageContext (Ljavax/servlet/jsp/PageContext;)V
// 261: aload 8
// 263: athrow
// 264: getstatic 26 org/apache/jsp/NewFile_jsp:_jspxFactory Ljavax/servlet/jsp/JspFactory;
// 267: aload 6
// 269: invokevirtual 164 javax/servlet/jsp/JspFactory:releasePageContext (Ljavax/servlet/jsp/PageContext;)V
// 272: return
// Line number table:
// Java source line #65 -> byte code offset #0
// Java source line #67 -> byte code offset #3
// Java source line #68 -> byte code offset #6
// Java source line #72 -> byte code offset #9
// Java source line #73 -> byte code offset #17
// Java source line #74 -> byte code offset #23
// Java source line #73 -> byte code offset #29
// Java source line #75 -> byte code offset #33
// Java source line #76 -> byte code offset #36
// Java source line #77 -> byte code offset #41
// Java source line #78 -> byte code offset #46
// Java source line #79 -> byte code offset #51
// Java source line #80 -> byte code offset #57
// Java source line #82 -> byte code offset #61
// Java source line #83 -> byte code offset #68
// Java source line #84 -> byte code offset #75
// Java source line #85 -> byte code offset #82
// Java source line #86 -> byte code offset #89
// Java source line #87 -> byte code offset #96
// Java source line #88 -> byte code offset #103
// Java source line #89 -> byte code offset #110
// Java source line #90 -> byte code offset #117
// Java source line #91 -> byte code offset #124
// Java source line #92 -> byte code offset #131
// Java source line #93 -> byte code offset #138
// Java source line #94 -> byte code offset #145
// Java source line #95 -> byte code offset #152
// Java source line #96 -> byte code offset #159
// Java source line #97 -> byte code offset #164
// Java source line #98 -> byte code offset #172
// Java source line #99 -> byte code offset #176
// Java source line #101 -> byte code offset #189
// Java source line #102 -> byte code offset #198
// Java source line #103 -> byte code offset #203
// Java source line #104 -> byte code offset #206
// Java source line #106 -> byte code offset #211
// Java source line #107 -> byte code offset #215
// Java source line #108 -> byte code offset #230
// Java source line #111 -> byte code offset #240
// Java source line #110 -> byte code offset #251
// Java source line #111 -> byte code offset #253
// Java source line #112 -> byte code offset #261
// Java source line #111 -> byte code offset #264
// Java source line #113 -> byte code offset #272
// Local variable table:
// start length slot name signature
// 0 273 0 this NewFile_jsp
// 0 273 1 request javax.servlet.http.HttpServletRequest
// 0 273 2 response javax.servlet.http.HttpServletResponse
// 32 20 3 pageContext javax.servlet.jsp.PageContext
// 1 206 4 out javax.servlet.jsp.JspWriter
// 4 169 5 _jspx_out javax.servlet.jsp.JspWriter
// 7 261 6 _jspx_page_context javax.servlet.jsp.PageContext
// 162 73 7 t Throwable
// 251 11 8 localObject Object
// 214 1 9 localIOException java.io.IOException
// Exception table:
// from to target type
// 9 159 162 java/lang/Throwable
// 189 211 214 java/io/IOException
// 9 240 251 finally
}
}
经过对比,发现tomcat中的内容与eclipse完全一样(应该是一样的,因为我用的是相同的tomcat7)
【tomcat】

\work\Catalina\localhost<项目名称>

你可能感兴趣的:(jsp编译后的文件位置(Eclipse和tomcat))