av激情亚洲男人的天堂国语,日韩欧美精品一中文字幕,无码av一区二区三区无码,国产又色又爽又刺激的a片,国产又色又爽又刺激的a片

JSP轉譯成Servlet詳細過程

很多人都會認為JSP的執(zhí)行性能會和Servlet相差很多,其實執(zhí)行性能上的差別只在***次的執(zhí)行。因為JSP在執(zhí)行***次后,會被編譯成Servlet的類文件,即.class,當再重復調用執(zhí)行時,就直接執(zhí)行***次所產生的Servlet,而不再重新把JSP編譯成Servelt。

因此,除了***次的編譯會花較久的時間之外,之后JSP和Servlet的執(zhí)行速度就幾乎相同了。Web容器處理JSP文件請求的執(zhí)行過程主要包括以下4個部分:

1.客戶端發(fā)出Request請求

2.JSP Container 將JSP轉譯成Servlet的源代碼

3.將產生的Servlet源代碼經過編譯后,并加載到內存執(zhí)行

4.把結果Response(響應)至客戶端

在執(zhí)行JSP網頁時,通??梢苑譃閮蓚€時期:轉譯時期(Translation Time)和請求時期(Request Time)。

◆轉譯時期:JSP網頁轉移成Servlet類。

◆請求時期:Servlet類執(zhí)行后,響應結果至客戶端。

轉譯期間做了兩件事情:

◆轉譯時期:將JSP網頁轉移為Servlet源代碼 .java.

◆編譯時期:將Servlet 源代碼 .java編譯成 Servlet類 .class.

當JSP網頁在執(zhí)行時,JSP Container會做檢查工作,如果發(fā)現(xiàn)JSP網頁有更新修改時,JSP Container才會再次編譯JSP成Servlet; 如果JSP沒有更新時,就直接執(zhí)行前面所產生的Servlet。

 
 
 
  1. (showdate.jsp)     
  2. <%@ page language="java" contentType="text/html;charset=gb2312" import="java.text.*,java.util.*;"%>     
  3.      
  4.      
  5. Show time     
  6.      
  7.       
  8.      Hello :      
  9.      <%     
  10.          SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");     
  11.          String str = format.format(new Date());     
  12.       %>     
  13.       <%=str %>     
  14.      
  15.  

當部署好 showdate.jsp之后,啟動Tomcat服務器。

1.在IE瀏覽器中輸入配置好的路徑 .... showdate.jsp 請求這個頁面。

2.JSP Container 即Tomcat 服務器會將 showdate.jsp 轉譯成 showdate_jsp.java 源文件。

3.同時將 showdate_jsp.java 源文件編譯成 showdate_jsp.class。

4.編譯執(zhí)行showdate_jsp.class 類,處理請求,返回響應,容器將生成的頁面返回給客戶端顯示。

 
 
 
  1. (轉移成的java源文件  showdate_jsp.java)  
  2. package org.apache.jsp.ch04;      
  3.      
  4. import javax.servlet.*;      
  5. import javax.servlet.http.*;      
  6. import javax.servlet.jsp.*;      
  7. import java.text.*;      
  8. import java.util.*;;      
  9.      
  10. public final class showdate_jsp extends org.apache.jasper.runtime.HttpJspBase      
  11.     implements org.apache.jasper.runtime.JspSourceDependent {      
  12.      
  13.   private static java.util.List _jspx_dependants;      
  14.      
  15.   public Object getDependants() {      
  16.     return _jspx_dependants;      
  17.   }      
  18.      
  19.   public void _jspService(HttpServletRequest request, HttpServletResponse response)      
  20.         throws java.io.IOException, ServletException {      
  21.      
  22.     JspFactory _jspxFactory = null;      
  23.     PageContext pageContext = null;      
  24.     HttpSession session = null;      
  25.     ServletContext application = null;      
  26.     ServletConfig config = null;      
  27.     JspWriter out = null;      
  28.     Object page = this;      
  29.     JspWriter _jspx_out = null;      
  30.     PageContext _jspx_page_context = null;      
  31.      
  32.     try {      
  33.       _jspxFactory = JspFactory.getDefaultFactory();      
  34.       response.setContentType("text/html;charset=gb2312");      
  35.       pageContext = _jspxFactory.getPageContext(this, request, response,      
  36.                    null, true, 8192, true);      
  37.       _jspx_page_context = pageContext;      
  38.       application = pageContext.getServletContext();      
  39.       config = pageContext.getServletConfig();      
  40.       session = pageContext.getSession();      
  41.       out = pageContext.getOut();      
  42.       _jspx_out = out;      
  43.      
  44.       out.write("\r\n");      
  45.       out.write("\r\n");      
  46.       out.write("\r\n");      
  47.       out.write("Show time\r\n");      
  48.       out.write("\r\n");      
  49.       out.write(" \r\n");      
  50.       out.write("\tHello : \r\n");      
  51.       out.write("\t");      
  52.      
  53.          SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");      
  54.          String str = format.format(new Date());      
  55.      
  56.       out.write("\r\n");      
  57.       out.write("\t ");      
  58.       out.print(str );      
  59.       out.write("\r\n");      
  60.       out.write("\r\n");      
  61.       out.write("");      
  62.     } catch (Throwable t) {      
  63.      
  64.       if (!(t instanceof SkipPageException)){      
  65.         out = _jspx_out;      
  66.         if (out != null && out.getBufferSize() != 0)      
  67.           out.clearBuffer();      
  68.         if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);      
  69.       }      
  70.      
  71.     } finally {      
  72.      
  73.       if (_jspxFactory != null) _jspxFactory.releasePageContext(_jspx_page_context);      
  74.     }      
  75.   }      

當JSP頁面被轉譯成Servlet時,內容主要包含三個部分:

 
 
 
  1. public void _jspInit(){ ..}       
  2. -- 當JSP網頁一開始執(zhí)行時,***執(zhí)行此方法,執(zhí)行初始化工作     
  3. public void _jspDestory(){...} – JSP網頁***執(zhí)行的方法     
  4. public void _jspService(HttpServletRequest request, HttpServletResponse response)     
  5.         throws java.io.IOException, ServletException { 

JSP網頁中最主要的程序都是在此執(zhí)行,將showdate.jsp和showdate_jsp.java做一個簡單對比:

***部分:頁面屬性的對比

 
 
 
  1. <%@ page language="java" contentType="text/html;charset=gb2312" %> 
  2. response.setContentType("text/html;charset=gb2312");    
  3. //通過 response響應設置返回客戶端的頁面屬性 

第二部分:HTML標簽

 
 
 
  1.       
  2.       
  3. Show time      
  4.       
  5. ..      
  6.  
  7.  
  8. out.write("\r\n");  
  9. out.write("\r\n");  
  10. out.write("\r\n");  
  11. out.write("Show time\r\n");  
  12. out.write("\r\n");  
  13. out.write(" \r\n");  
  14. out.write("\tHello : \r\n");  
  15. out.write("\t");  
  16. //通過 out對象 向客戶端寫HTML標簽 

第三部分:聲明的對象

 
 
 
  1. <%      
  2.          SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");      
  3.          String str = format.format(new Date());      
  4. %> 

在_jspService 方法中聲明的局部變量:

 
 
 
  1. SimpleDateFormat format = new SimpleDateFormat("yyyy/MM/dd");      
  2. String str = format.format(new Date());    

第四部分:表達式

 
 
 
  1. <%=str %>      
  2. out.print(str ); //寫即打印str變量的值 

網頁題目:JSP轉譯成Servlet詳細過程
標題網址:http://uogjgqi.cn/article/ccedhge.html
掃二維碼與項目經理溝通

我們在微信上24小時期待你的聲音

解答本文疑問/技術咨詢/運營咨詢/技術建議/互聯(lián)網交流