Download presentation
Presentation is loading. Please wait.
1
CS320 Web and Internet Programming JSP Scripting Elements and Page Directives Chengyu Sun California State University, Los Angeles
2
Java Server Page (JSP) Why? It’s tedious to generate HTML using println() Separate presentation from processing How? Java code embedded in HTML documents
3
HelloJSP1.jsp Hello JSP 1 A JSP without J or S.
4
HelloJSP2.jsp JSP Hello World Hello World on.
5
How Does JSP Work? Look under $CATALINA_HOME/work/Catalina/localh ost/context_name JSPServlet convertcompile ByteCode execute automatically done by server
6
Some Simple Observations about the JSP/Servlets In package org.apache.jsp _jspService() handles everything replaces service() in HttpServlet What happened to doGet(), doPost(),...?? HTML text out.write(...)
7
Pre-defined Variables request, response, out session, application config, pageContext page The same request, response, session etc. that are used in servlets – see the Servlet API documentation for what you can do with them.
8
JSP Components HTML template text Code elements of Java Scripting elements Directives Beans Expression language Custom tag libraries
9
Comments
10
JSP Expressions What’s an expression?? in JSP out.write( expression ) in _jspService()
11
Example: Add.jsp Add two integer parameters and display the sum
12
JSP Scriptlets All code goes inside _jspService()
13
Example: Add.jsp Again Add the code to validate the parameters
14
Another Scriptlet Example Have a nice day! Have a lousy day!
15
JSP Declarations All code goes outside _jspService()
16
Example: RequestCounter.jsp Initialize a counter as a class variable Increment the counter each time the JSP is requested
17
JSP Scripting Elements JSP Expressions JSP Scriptlets JSP Declarations
18
Directives Affect the overall structure of the JSP Three type of directives page include taglib
19
Some Page Directives isELIgnored, errorPage, isErrorPage
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.