Next page So how does a JSP actually work?
来源:互联网 发布:淘宝手机找回是真的吗 编辑:程序博客网 时间:2024/06/07 02:39
So how does a JSP actually work?
It is turned into a special kind of servlet. The code is generated by a JSP compiler, which generates Java code out of it. This is the Java code that will be run while you test your JSPs. Sometimes, you’ll need to take a look a the code to understand what his happening
Tomcat, for example, places the intermediate .java files in “tomcat_root"/work/Catalina/localhost/"webapp name
“.
JBoss places these in “jboss home"/server/default/work/jboss.web/localhost/"webapp name
”
Tomcat retains the .java source by default. This will vary by servlet container implementation, some require you to turn a debug option on to save source
Tomcat, by default, places the JSP code in the org.apache.jsp
package.
Here is the code that is generated by Tomcat for the example above:
import javax.servlet.jsp.*;public final class hello_jsp extends org.apache.jasper.runtime.HttpJspBase implements org.apache.jasper.runtime.JspSourceDependent { private static java.util.Vector _jspx_dependants; public java.util.List getDependants() { return _jspx_dependants; } public void _jspService(HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, ServletException { JspFactory _jspxFactory = null; PageContext pageContext = null; HttpSession session = null; ServletContext application = null; ServletConfig config = null; JspWriter out = null; Object page = this; JspWriter _jspx_out = null; try { _jspxFactory = JspFactory.getDefaultFactory(); response.setContentType("text/html"); pageContext = _jspxFactory.getPageContext(this, request, response, null, true, 8192, true); application = pageContext.getServletContext(); config = pageContext.getServletConfig(); session = pageContext.getSession(); out = pageContext.getOut(); _jspx_out = out; out.write("\n"); out.write("<html>\n "); out.write("<head>\n "); out.write("<title>Hello JSP"); out.write("</title>\n "); out.write("</head>\n "); out.write("<body>\n "); out.write("<h1>Hello World"); out.write("</h1>\n The time is "); out.write(String.valueOf( new java.util.Date() )); out.write("\n "); out.write("</body>\n"); out.write("</html>\n"); } catch (Throwable t) { if (!(t instanceof javax.servlet.jsp.SkipPageException)){ out = _jspx_out; if (out != null && out.getBufferSize() != 0) out.clearBuffer(); if (pageContext != null) pageContext.handlePageException(t); } } finally { if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext); } }}
Based on what you already know about Servlets, what do you think of the time writing this as a JSP has saved you? We’ll look at some more detail on other convenient things done for you by the JSP compiler later. If you study this code above, you can probably figure most of them out without the specification!
- Next page So how does a JSP actually work?
- UEFI boot: how does that actually work, then?
- How does a computer work?
- HOW DOES A DATABASE WORK
- How does a relational database work
- How does a HashMap work in JAVA
- How does netstat work
- How does XVCL work?
- How does JNA work?
- How does cas work
- how does wifi work?
- How does google work
- How does browsersync work?
- How does maven work?
- How does a relational database work - Coding Geek
- What is a GPU and how does it work?
- How does garbage collector work?
- How does an app work?
- Java——equals方法与== 及其重写
- spring学习笔记:bean的配置
- leetcode---Factorial Trailing Zeroes
- 分隔条的使用方法和效果
- Android OnLowMemory和OnTrimMemory
- Next page So how does a JSP actually work?
- windows和linux下的分隔符
- Android富文本图文混排、粗体、斜体、图片、下划线、删除线等
- Android 自定义ViewGroup手把手教你实现ArcMenu
- 多态
- filter
- 当用svn切换了项目后,相应的配置需要更改
- IoTF service(a special MQTT Broker) Connectivity for Applications and Devices
- C/C++回调函数