日韩av黄I国产麻豆传媒I国产91av视频在线观看I日韩一区二区三区在线看I美女国产在线I麻豆视频国产在线观看I成人黄色短片

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 >

#tomcat#生成的jsp转换问题

發(fā)布時(shí)間:2025/7/25 48 豆豆
生活随笔 收集整理的這篇文章主要介紹了 #tomcat#生成的jsp转换问题 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

轉(zhuǎn)載!

Eclipse中JSP生成的class文件去了哪里?

?

大家都知道,JSP在請(qǐng)求的時(shí)候,會(huì)先轉(zhuǎn)化成Servlet(其實(shí)就是個(gè)java類),然后生成class文件,再提供服務(wù)。

那么生成的java、class文件在哪呢?Eclipse中根本找不到呀!

  首先應(yīng)該了解的是Tomcat在Eclipse的映射關(guān)系,參考前一篇博文所述:Tomcat的服務(wù)器目錄配置

  可以了解到,Tomcat在Eclipse中提供了三種位置配置選項(xiàng):

  1 Use workspace metadata

  2 Use Tomcat installation

  3 Use custom location

  分別對(duì)應(yīng)三種情況說一下,注意要把Server中發(fā)布的目錄全部刪除,然后clean后才能修改該配置項(xiàng)。

  如果你在Eclipse中雙擊Server配置選項(xiàng),在Server Location中分別選了如下的選項(xiàng):

  如果Server Locations選擇了第一項(xiàng)Use workspace metadata

  選了上面這項(xiàng),你的服務(wù)器目錄和發(fā)布目錄將會(huì)如下:

  服務(wù)器目錄,即生成的字節(jié)碼和java文件所在的目錄。它在你的eclipse的工作目錄中,比如我的工作目錄是在F://workspace,那么在該目錄下就可以看到這個(gè).metadata目錄了。

  參考上面的配置目錄F:\workspace\.metadata\.plugins\org.eclipse.wst.server.core\tmp0

  這就是Tomcat映射的目錄,在這個(gè)目錄中有一個(gè)work目錄和一個(gè)wtpwebapps目錄

  work目錄中順著:work\Catalina\localhost\項(xiàng)目名字\org\apache\jsp?就可以找到你的項(xiàng)目對(duì)應(yīng)的java文件和class文件(注意要訪問jsp后才會(huì)出現(xiàn)!)

  wtpwebapps目錄則存放對(duì)應(yīng)的部署資源文件

  如果選擇的是第二項(xiàng),Use Tomcat installation

  如果勾選的use tomcat installation,那么你的tomcat目錄將被選定為tomcat所安裝的目錄。

  還是推薦選擇這個(gè)吧,畢竟好找一點(diǎn)。

  如果勾選第三項(xiàng),Use custom location

  目錄的結(jié)構(gòu)與上面的類似,上面這兩個(gè)都是不可以修改的,要么是workspace所在的目錄,要么是tomcat的目錄。

  選擇該項(xiàng),可以自定義生成的空間。

  另外說一點(diǎn),JSP的生命周期

  這是老生常談的問題了,用戶把工程部署到tomcat中,然后啟動(dòng)tomcat!此時(shí)就可以訪問jsp了、

  1 第一次訪問JSP,會(huì)驗(yàn)證一下是否第一次訪問,然后把JSP轉(zhuǎn)化成java(Servlet),再編譯成class文件。

  2 生成的class文件中會(huì)自動(dòng)生成幾個(gè)方法:jspInit()、jspDestroy()、jspService().Tomcat僅僅在第一次請(qǐng)求時(shí),調(diào)用jspInit方法,然后調(diào)用jspService進(jìn)行處理。

  3 之后的每個(gè)請(qǐng)求,都會(huì)分配一個(gè)線程調(diào)用jspService方法。

  4 如果頁面被銷毀或者關(guān)閉,都會(huì)調(diào)用jspDestroy

  由于該文件是常駐內(nèi)存的,又是多線程調(diào)用,所以訪問的效率和速度都會(huì)很快。

  按照前面所述的方法,就可以看到生成的文件結(jié)構(gòu)了。

  

  按照前面所述的方法,就可以看到生成的文件結(jié)構(gòu)了。

  為了展示,這里給出一個(gè)樣例的JSP

<%@ page language="java" import="java.util.*,java.io.*" contentType="text/html; charset=utf-8"%>
<%--
language 腳本使用的語言
import 加載類文件
contentType 編碼方式
--%>
<!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=utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>JSP</h1>

<!-- 客戶端可見 -->
<%-- 客戶端不可見 --%>
<%!
String s = "xingoo";//聲明變量
int add(int a,int b){//聲明函數(shù)
return a+b;
}
%>
s=<%=s %><br> <%--表達(dá)式不以分號(hào)結(jié)束 --%>
1+2=<%=add(1,2) %><br>
<%
//單行注釋 ————————————————快捷鍵ctrl+/
/* 多行注釋 ____________快捷鍵ctrl+shift+/ */
out.println("s="+s+"<br>");
%>
</body>
</html>

  里面含有一些注釋,變量聲明和打印輸出等等。

  在生成.java文件中,可以看到生成的java文件:

package org.apache.jsp;import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import java.util.*; import java.io.*; public final class test1_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { String s = "xingoo";//聲明變量 int add(int a,int b){//聲明函數(shù) return a+b; } private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); private static java.util.List _jspx_dependants; private javax.el.ExpressionFactory _el_expressionfactory; private org.apache.AnnotationProcessor _jsp_annotationprocessor; public Object getDependants() { return _jspx_dependants; } public void _jspInit() { _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory(); _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName()); } public void _jspDestroy() { } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; 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'); out.write('\n'); out.write(' '); 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=utf-8\">\r\n"); out.write("<title>Insert title here</title>\r\n"); out.write("</head>\r\n"); out.write("<body>\r\n"); out.write("\t<h1>JSP</h1>\r\n"); out.write("\t\r\n"); out.write("\t<!-- 客戶端可見 -->\r\n"); out.write("\t"); out.write('\r'); out.write('\n'); out.write(' '); out.write("\r\n"); out.write("\ts="); out.print(s ); out.write("<br> "); out.write("\r\n"); out.write("\t1+2="); out.print(add(1,2) ); out.write("<br>\r\n"); out.write("\t"); //單行注釋 ————————————————快捷鍵ctrl+/ /* 多行注釋 ____________快捷鍵ctrl+shift+/ */ out.println("s="+s+"<br>"); out.write("\r\n"); out.write("</body>\r\n"); out.write("</html>"); } catch (Throwable t) { if (!(t instanceof 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 log(t.getMessage(), t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } } }

package org.apache.jsp;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;
import java.io.*;

public final class test1_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {


String s = "xingoo";//聲明變量
int add(int a,int b){//聲明函數(shù)
return a+b;
}

private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();

private static java.util.List _jspx_dependants;

private javax.el.ExpressionFactory _el_expressionfactory;
private org.apache.AnnotationProcessor _jsp_annotationprocessor;

public Object getDependants() {
return _jspx_dependants;
}

public void _jspInit() {
_el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory();
_jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName());
}

public void _jspDestroy() {
}

public void _jspService(HttpServletRequest request, HttpServletResponse response)
throws java.io.IOException, ServletException {

PageContext pageContext = null;
HttpSession session = null;
ServletContext application = null;
ServletConfig config = null;
JspWriter out = null;
Object page = this;
JspWriter _jspx_out = null;
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');
out.write('\n');
out.write(' ');
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=utf-8\">\r\n");
out.write("<title>Insert title here</title>\r\n");
out.write("</head>\r\n");
out.write("<body>\r\n");
out.write("\t<h1>JSP</h1>\r\n");
out.write("\t\r\n");
out.write("\t<!-- 客戶端可見 -->\r\n");
out.write("\t");
out.write('\r');
out.write('\n');
out.write(' ');
out.write("\r\n");
out.write("\ts=");
out.print(s );
out.write("<br> ");
out.write("\r\n");
out.write("\t1+2=");
out.print(add(1,2) );
out.write("<br>\r\n");
out.write("\t");

//單行注釋 ————————————————快捷鍵ctrl+/
/* 多行注釋 ____________快捷鍵ctrl+shift+/ */
out.println("s="+s+"<br>");

out.write("\r\n");
out.write("</body>\r\n");
out.write("</html>");
} catch (Throwable t) {
if (!(t instanceof 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 log(t.getMessage(), t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}

  聲明注釋,都可以很詳細(xì)的看到。

package org.apache.jsp;import javax.servlet.*; import javax.servlet.http.*; import javax.servlet.jsp.*; import java.util.*; import java.io.*; public final class test1_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { String s = "xingoo";//聲明變量 int add(int a,int b){//聲明函數(shù) return a+b; } private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory(); private static java.util.List _jspx_dependants; private javax.el.ExpressionFactory _el_expressionfactory; private org.apache.AnnotationProcessor _jsp_annotationprocessor; public Object getDependants() { return _jspx_dependants; } public void _jspInit() { _el_expressionfactory = _jspxFactory.getJspApplicationContext(getServletConfig().getServletContext()).getExpressionFactory(); _jsp_annotationprocessor = (org.apache.AnnotationProcessor) getServletConfig().getServletContext().getAttribute(org.apache.AnnotationProcessor.class.getName()); } public void _jspDestroy() { } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; 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'); out.write('\n'); out.write(' '); 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=utf-8\">\r\n"); out.write("<title>Insert title here</title>\r\n"); out.write("</head>\r\n"); out.write("<body>\r\n"); out.write("\t<h1>JSP</h1>\r\n"); out.write("\t\r\n"); out.write("\t<!-- 客戶端可見 -->\r\n"); out.write("\t"); out.write('\r'); out.write('\n'); out.write(' '); out.write("\r\n"); out.write("\ts="); out.print(s ); out.write("<br> "); out.write("\r\n"); out.write("\t1+2="); out.print(add(1,2) ); out.write("<br>\r\n"); out.write("\t"); //單行注釋 ————————————————快捷鍵ctrl+/ /* 多行注釋 ____________快捷鍵ctrl+shift+/ */ out.println("s="+s+"<br>"); out.write("\r\n"); out.write("</body>\r\n"); out.write("</html>"); } catch (Throwable t) { if (!(t instanceof 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 log(t.getMessage(), t); } } finally { _jspxFactory.releasePageContext(_jspx_page_context); } } }

轉(zhuǎn)載于:https://www.cnblogs.com/tnt-33/p/8624536.html

總結(jié)

以上是生活随笔為你收集整理的#tomcat#生成的jsp转换问题的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。