JSP Intro and Overview: For Live J2EE Training, See Training Courses On JSP, Servlets, Struts, JSF, AJAX, and
JSP Intro and Overview: For Live J2EE Training, See Training Courses On JSP, Servlets, Struts, JSF, AJAX, and
For live J2EE training, see training courses on JSP, servlets, Struts, JSF, AJAX, and Java 5 at http://courses.coreservlets.com/.
Taught by the author of Core Servlets and JSP, More Servlets and JSP, and this tutorial. Available at public venues, or customized versions can be JSP, Servlet, Struts, JSF, AJAX, & at your organization. held on-site Java 5 Training: http://courses.coreservlets.com
3
J2EE Books from Sun Press: http://www.coreservlets.com Additional topics available upon request.
Agenda
Understanding the need for JSP Evaluating the benefits of JSP Comparing JSP to other technologies Avoiding JSP misconceptions Understanding the JSP lifecycle Installing JSP pages Looking at JSP in the real world
Example:
<!DOCTYPE > <HTML> <HEAD> <TITLE>Order Confirmation</TITLE> <LINK REL=STYLESHEET HREF="JSP-Styles.css" TYPE="text/css"> </HEAD> <BODY> <H2>Order Confirmation</H2> Thanks for ordering <I><%= request.getParameter("title") %></I>! </BODY></HTML>
6
Benefits of JSP
Although JSP technically can't do anything servlets can't do, JSP makes it easier to:
Write HTML Read and maintain the HTML
Versus PHP
Better language for dynamic part Better tool support
More convenient to create HTML Can use standard tools (e.g., DreamWeaver) Divide and conquer JSP programmers still need to know servlet programming
J2EE training: http://courses.coreservlets.com
Caveats
Previous rules about CLASSPATH, install dirs, etc., still apply to regular Java classes used by a JSP page
10
Example
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML> <HEAD> <TITLE>JSP Expressions</TITLE> <META NAME="keywords" CONTENT="JSP,expressions,JavaServer Pages"> <META NAME="description" CONTENT="A quick example of JSP expressions."> <LINK REL=STYLESHEET HREF="JSP-Styles.css" TYPE="text/css"> </HEAD>
11
Example (Continued)
<BODY> <H2>JSP Expressions</H2> <UL> <LI>Current time: <%= new java.util.Date() %> <LI>Server: <%= application.getServerInfo() %> <LI>Session ID: <%= session.getId() %> <LI>The <CODE>testParam</CODE> form parameter: <%= request.getParameter("testParam") %> </UL> </BODY></HTML>
12
Example: Result
If location was
C:\jakarta-tomcat-xx\webapps\ROOT\ jsp-scripting\Expressions.jsp or C:\JRun4\servers\default\default-ear\default-war\ jsp-scripting\Expressions.jsp
URL would be
http://localhost/jsp-scripting/Expressions.jsp
13
Similar questions
How do I put a normal applet in a JSP page? Answer: send an <APPLET> tag to the client How do I put an image in a JSP page? Answer: send an <IMG > tag to the client How do I use JavaScript/Acrobat/Shockwave/Etc? Answer: send the appropriate HTML tags
14
Yes Yes
No No
No Yes
No Page modified No
Yes Yes
No No
Server restarted
Yes
No
Yes
No
Yes
No
Yes
Yes
Yes
Yes
Yes
Yes
16
Delta Airlines United Airlines AirTran American Airlines British Airways KLM Air China Saudi Arabian Airlines Iceland Air
J2EE training: http://courses.coreservlets.com
18
20
21
22
23
25
Summary
JSP makes it easier to create and maintain HTML, while still providing full access to servlet code JSP pages get translated into servlets
It is the servlets that run at request time Client does not see anything JSP-related
26
Other technologies use similar approach, but aren't as portable and don't let you use Java for the "real code"
J2EE training: http://courses.coreservlets.com
Questions?
27
JSP, Servlet, Struts, JSF, AJAX, & Java 5 Training: http://courses.coreservlets.com J2EE Books from Sun Press: http://www.coreservlets.com