Understanding the XML view
The core JSP syntax is made up of scriptlets, actions, directives, expressions and declarations defined by the JSP specification. Web browsers do not understand JSP syntax as they do HTML. For the browser to display the contents of a JSP page, JRun must first compile the JSP source as a servlet which JRun then uses to generate the response. The response is HTML or whatever markup language is requested. However, the JSP-to-servlet compilation process is not a direct one. The JSP must first be transformed into XML.
The following steps occur when a JSP is requested for the first time:
- A client requests a JSP for the first time.
- JRun converts the JSP into a temporary XML representation called the XML view.
- JRun validates the XML view of the JSP page.
- JRun transforms the XML view into a .java class file that extends
jrun.jsp.runtime.HttpJSPServlet
and implementsjrun.jsp.runtime.JRunJspPage
. You can view the servlet's source code as described in "Viewing servlet source code". - JRun compiles the new class into a servlet.
- The servlet generates the output based on the client request.
The following image shows the lifecycle of a JSP page when it is first requested by a client and finally compiled into a servlet. The servlet then returns the request to the client.
Viewing servlet source code
You can view the source code of the servlet representation of the JSP page. You cannot view the XML view of the JSP page because it is only maintained in memory temporarily while JRun constructs the servlet.
JRun does not keep servlets generated from JSP source code by default. This section shows you how to configure JRun to keep the Java files and where to view them.
To keep generated JSPs:
- In the jrun_root/servers/jrun_server/SERVER-INF/default-web.xml file, set the JSPServlet's
keepGenerated
initialization parameter totrue
, as shown in the following example:<servlet> <servlet-name>JSPServlet</servlet-name> <servlet-class>jrun.jsp.JSPServlet</servlet-class> <init-param> <param-name>keepGenerated</param-name> <param-value>true</param-value> </init-param> </servlet> - Delete the JSP class files in the web application's /WEB-INF/jsp directory.
Doing this removes the already-generated servlet class files. JRun checks for the existence of the class file before recompiling a JSP. If the class files were still available, JRun would not recompile the JSP. JRun also checks the data/time stamp of the JSP, so you can change the JSP source code and save the JSP file to cause JRun to regenerate the Java source code and recompile the class.
- Restart the JRun server.
- Request the JSP.
- Open the JSP's generated Java class file (*.java) in the web application's /WEB-INF/jsp directory. JRun names the source code files starting with "jrun__" and appends version information to the name.