今天在測試Jsp程式時候,想看看jsp被伺服器翻譯成的Java代碼是什麼樣子的,於是在GlassFish的目錄下搜尋,找到了被翻譯的Java代碼如下:
package org.apache.jsp;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.jsp.*;
import java.util.*;
public final class TestJsp_jsp extends org.apache.jasper.runtime.HttpJspBase
implements org.apache.jasper.runtime.JspSourceDependent {
private static final JspFactory _jspxFactory = JspFactory.getDefaultFactory();
private static java.util.Vector _jspx_dependants;
private org.apache.jasper.runtime.ResourceInjector _jspx_resourceInjector;
public Object getDependants() {
return _jspx_dependants;
}
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=GB18030");
response.setHeader("X-Powered-By", "JSP/2.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;
_jspx_resourceInjector = (org.apache.jasper.runtime.ResourceInjector) application.getAttribute("com.sun.appserv.jsp.resource.injector");
out.write("/r/n");
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=GB18030/">/r/n");
out.write("<title>Insert title here</title>/r/n");
out.write("</head>/r/n");
out.write("<body>/r/n");
Calendar curTime = new GregorianCalendar();
int h = curTime.get(curTime.HOUR_OF_DAY);
out.println(h);
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)
out.clearBuffer();
if (_jspx_page_context != null) _jspx_page_context.handlePageException(t);
}
} finally {
_jspxFactory.releasePageContext(_jspx_page_context);
}
}
}