Servlet-Jsp,jspservlet

來源:互聯網
上載者:User

Servlet-Jsp,jspservlet

  Jsp實際就是Servlet。


  我們訪問Http://localhost:8080/Web/index.jsp的流程:

  1 【jsp檔案名稱】.jsp轉義為【jsp檔案名稱_jsp】.java,檔案儲存體在Tomcat下的Work目錄下的org的apache的jsp檔案中。
  2 編譯jsp檔案名稱_jsp.java為.class檔案,檔案儲存體位置和【jsp檔案名稱_jsp】.java位置相同。
  3 JVM執行.class檔案。

 

   查看轉義後的.java檔案:

   public final class index_jsp extends org.apache.jasper.runtime.HttpJspBase

   而HttpJspBase又繼承了HttpServlet,可見產生的.java檔案是個Servlet類。

   疑問:

   我們在<%中使用的對象%>來源於哪裡呢?

   解決:查看原始碼

   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;

   這裡面的對象是我們編寫jsp頁面的時候使用的對象。

  

   Jasper:解析JSP的引擎

  Jasper是tomcat中使用的JSP引擎,在Tomcat 6中使用的是Jasper 2,相對於原來的版本作了不少的改進,比如:JSP的標籤緩衝池、背景編譯、頁面改變時自動重新編譯、Eclipse中JDT編譯等等。

  在Tomcat中可以通過配置 CATALINA_HOME/conf/web.xml 中的內容,配置Jasper的選項:

     <servlet>        <servlet-name>jsp</servlet-name>        <servlet-class>org.apache.jasper.servlet.JspServlet</servlet-class>        <init-param>            <param-name>fork</param-name>            <param-value>false</param-value>        </init-param>        <init-param>            <param-name>xpoweredBy</param-name>            <param-value>false</param-value>        </init-param>        <load-on-startup>3</load-on-startup>    </servlet>

  Tomcat下的Work工作目錄:(這裡只是我至今發現的功能,可能還有其它功能)

  1 存放.jsp檔案轉義的.java檔案和.class檔案。

  2 當伺服器停止時,存放位於HttpSession中的對象的序列化檔案,用於伺服器開啟時重新讀入到記憶體中。

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.