Download - Java Server Pages
-
Java Server Pagesby Jon Pearce
-
JSP DocumentsJSP docs are XHTML Documents containing:Fixed-Template Data: FTDHTML ComponentsXML markupJSP Components:
-
demo.jsp
Demo
FTD FTD FTD ...
-
JSP Components Scriptlets
-
JSP FactsThe container compiles a JSP to a servlet the first time it is served.Use JSPs when ratio of FTD to Dynamic Content is highJSPs decouple design from programmingJSP = HTML containing JavaServlet = Java containing HTMLJSPs replace views
-
JSP Compilation
-
Scriptlets
-
Examples of Scripting Componentscounter = 5) { counter = 0; } %>HTML
ALTERNATIVE HTML
-
Implicit ObjectsApplication ScopeapplicationSession ScopesessionRequest ScoperequestPage Scoperesponse, out, page, pageContext
-
Example
Hello
Hello John Doe
-
javax.servlet.jsp
-
The JSP to Servlet Translationpublic class MyJSP implements HttpJspPage { // ... public void _jspService(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException { JspFactory factory = JspFactory.getDefaultFactory(); PageContext pageContext = factory.getPageContext(...); HttpSession session = pageContext.getSession(); JspWriter out = pageContext.getOut(); Object page = this; try { // body of translated JSP goes here ... } catch (Exception e) { out.clear(); pageContext.handlePageException(e); } finally { out.close(); factory.releasePageContext(pageContext); } }}
-
Examplesclock.jsp
scriptTest.jsp
Pallindrome TesterbeanTest.jsp
various counterspersonView.jsp
-
Standard Actions ... includeforwardpluginparamuseBeansetPropertygetProperty
-
Directives
-
Include Directive
-
Include Directive vs. Actionfoo.html included after each changefoo.html included once at compile timeStatic (html) or dynamic (jsp) files can be included
-
forward
-
useBeanAccessing Bean Properties
Setting Bean Properties
-
Example
result =
-
Custom Tag Libraries