Main Page | See live article | Alphabetical index

JavaServer page example output

For the input, the java code for the resulting servlet class would look something like the following:

\r\n package jsp_servlet;\r\n import java.util.*;\r\n import java.io.*;\r\n import javax.servlet.*;\r\n import javax.servlet.http.*;\r\n import javax.servlet.jsp.*;\r\n import javax.servlet.jsp.tagext.*;\r\n\r\n import com.foo.bar; //imported as a result of <%@ page import="com.foo.bar" %>\r\n import ...\r\n\r\n class _myserlvet implements javax.servlet.Servlet, javax.servlet.jsp.HttpJspPage {\r\n     //inserted as a\r\n     //result of <%! int serverInstanceVariable = 1;%>\r\n     int serverInstanceVariable = 1; \r\n     ...\r\n\r\n     public void _jspService( javax.servlet.http.HttpServletRequest request,\r\n                              javax.servlet.http.HttpServletResponse response )\r\n       throws javax.servlet.ServletException,\r\n              java.io.IOException\r\n     {\r\n         javax.servlet.ServletConfig config = ...;//get the servlet config\r\n         Object page = this;\r\n         PageContext pageContext = ...;//get the page context for this request \r\n         javax.servlet.jsp.JspWriter out = pageContext.getOut();\r\n         HttpSession session = request.getSession( true );\r\n         try {\r\n             out.print( "\\r\\n" );\r\n             out.print( "\\r\\n" );\r\n             ...\r\n             //from <% int localStackBasedVariable = 1; %>\r\n             int localStackBasedVariable = 1; \r\n             ...\r\n             out.print( "\\r\\n" );\r\n             out.print( "   \\r\\n" );\r\n             ...\r\n         } catch ( Exception _exception ) {\r\n             //clean up and redirect to error page in <%@ page errorPage="myerror.jsp" %>\r\n         }\r\n    }\r\n }\r\n
" );\r\n //note, toStringOrBlank() converts the expression into a string or if\r\n // the expression is null, it uses the empty string.\r\n //from <%= "expanded inline data " + 1 %>\r\n out.print( toStringOrBlank( \\"expanded inline data \\" + 1 ) );\r\n out.print( "
Fact-index.com financially supports the Wikimedia Foundation. Displaying this page does not burden Wikipedia hardware resources.
This article is from Wikipedia. All text is available under the terms of the GNU Free Documentation License.