1 / 26

JSP (Java Server Pages)

JSP (Java Server Pages). DotCom Offsite Meeting 00 Raymond Gao September 28, 2000. HTML Web Server Model. PCs. <html>. HTML, CSS, JHTML, SHTML JSPs, Servlets, and Applets. Web Server. Java Beans, JMS, EJB (Session Beans). Application Server. JDBC, EJB (Entity Beans). EIS.

karif
Télécharger la présentation

JSP (Java Server Pages)

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JSP (Java Server Pages) DotCom Offsite Meeting 00 Raymond Gao September 28, 2000

  2. HTML Web Server Model PCs <html>

  3. HTML, CSS, JHTML, SHTML JSPs, Servlets, and Applets Web Server Java Beans, JMS, EJB (Session Beans) Application Server JDBC, EJB (Entity Beans) EIS Java In The 3-Tier Web Architecture <html> Javascripts, CSS, applets </html>

  4. J2EE Blueprint

  5. JDK 1.3 Layout

  6. What is JSP? • Separates the presentation from the business logic • Extends the Java servlet technology • Dynamic page reloading

  7. JSP Extends The Java Servlet Technology • Includes 2 main packages • javax.servlet.jsp.* • javax.servlet.jsp.tagext.* • Lifecycle of JSP • Precompiling --> Dynamic Reloading • jspInit() --> _jspService() --> jspDestroy()

  8. JSP’s Main Components • Scriptlet <% %> <% code fragment %> • Directives <%@ page …%> <%@ include …%> • TagLib Directive <%tag uri=“…” prefix=“…”%> • Beans <jsp:useBean …>

  9. JSP Syntax Guide

  10. First JSP Example - HelloWorld <html> <head> <title>Greetings</title> </head> <body> <% for(int i=0;i<5;i++) { %> <h1>Hello World!</h1> <% } %> </body> </html>

  11. A little bit more fancy <HTML> <HEAD><TITLE>Creating Hello World with Incremental Text Size Increase</TITLE></HEAD> <% for(int i = 1;i < 8;i++) { %> <FONT SIZE=<%=i%>>Hello World</FONT><BR> <% } %> <% for(int i = 7;i > 0;i--) { %> <FONT SIZE=<%=i%>>Hello World</FONT><BR> <% } %> </BODY> </HTML>

  12. What about using variables? <HTML> <HEAD><TITLE>Creating Hello World with Incremental Text Size Increase</TITLE></HEAD> <% for(int i = 1;i < 8;i++) { %> <FONT SIZE=<%=i%>>Hello World</FONT><BR> <% } %> <% for(int i = 7;i > 0;i--) { %> <FONT SIZE=<%=i%>>Hello World</FONT><BR> <% } %> <Font size = 5> <% long t_mill = System.currentTimeMillis(); java.util.Date d = new java.util.Date (t_mill); out.println("The current time is --> " + d); %> </FONT><BR> </BODY> </HTML>

  13. Look at the Dynamic Compiling • From: • H:\apps2\Allaire\JRun\servers\default\RG\OFFSITE00 • To: • H:\apps2\Allaire\JRun\servers\default\RG\WEB-INF\jsp • JSP • jspInit() --> _jspService() --> jspDestroy()

  14. Getting user Inputs - Page 1 <HTML> <TITLE>Login</TITLE> <BODY BGCOLOR=#FFFFFF> <CENTER> <FORM METHOD=post ACTION=/rg/OFFSITE00/login.jsp> <TABLE BORDER=2 CELLPADDING=4 CELLSPACING=0 BACKGROUND=/rg/OFFSITE00/images/marble.gif><TR><TD> <TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0> <TR> <TD><FONT FACE=Arial,Helvetica> <B>USERNAME</B> </FONT></TD> <TD><FONT FACE=Arial,Helvetica> <INPUT TYPE=text NAME=user SIZE=10> </FONT></TD> </TR> <TR> <TD><FONT FACE=Arial,Helvetica> <B>PASSWORD</B> </FONT></TD> <TD><FONT FACE=Arial,Helvetica> <INPUT TYPE=password NAME=pass SIZE=10>

  15. Getting user input - page 2 </FONT></TD> </TR> <TR> <TD COLSPAN=2 ALIGN=right><FONT FACE=Arial,Helvetica> <INPUT TYPE=submit VALUE=login> </FONT></TD> </TR> </TABLE> </TD></TR></TABLE> </FORM> The user name is <b><%= request.getParameter("user") %></b><BR> The password is <b><%= request.getParameter("pass") %></b> </CENTER> </BODY> </HTML>

  16. What is a Java Bean? • Java Bean is reusable components to be visually manipulated. • Java Bean relies on accepted convention. • setXXX() method. • getXXX() method. • Java Bean allows reflection and introspection. -- BeanInfo class.

  17. JSP Tag library Overview • Why? Better separation of the “noun” (tags & the content) from the “verb” (Java code and scripts). • How? - It has 4 pieces • Java tag classes • JSP file • TLD - taglib.tld • web.xml - optional

  18. JSP Methods That Are Pertinent To Tag Library setPageContext(PageContext pctx) setParent(Tag Parent) doStartTag() doInitBody() - BodyTag doAfterBody() - BodyTag doEndTag() Release()

  19. JSP TagLib Example -The Java File The Java File - Page 1 import java.util.*; import javax.servlet.jsp.*; import javax.servlet.jsp.tagext.*; public class Greetings implements Tag { private PageContext pageContext; private Tag parent; private String world = "world"; public int doStartTag() throws javax.servlet.jsp.JspTagException { return SKIP_BODY; }

  20. JSP TagLib Example - The Java File The Java File - Page 2 public int doEndTag() throws JspTagException { JspWriter out = pageContext.getOut(); try { out.println(“Today is “ + new Date()); out.println("Hello "+ world); } catch (Exception ex) { throw new JspTagException(ex.getMessage()); } finally { return EVAL_PAGE; } }

  21. JSP TagLib Example - The Java File The Java File - Page 3 public void release() {} public void setPageContext(final PageContext pageContext) { this.pageContext = pageContext; } public void setParent(javax.servlet.jsp.tagext.Tag parent) { this.parent=parent; } public Tag getParent() { return parent; } }

  22. JSP TagLib Example -The TLD File The TLD File <?xml version="1.0"?> <taglib> <tlibversion>1.0</tlibversion> <jspversion>1.1</jspversion> <shortname>rgdemo</shortname> <info>My Tag Library Demo</info> <tag> <name>greetings</name> <tagclass>Greetings</tagclass> <bodycontent>empty</bodycontent> </tag> </taglib>

  23. JSP TagLib Example - The JSP File The JSP file <html> <head> <title>ray's jsp demo with taglib</title> </header> <body> <%@ taglib uri="WEB-INF/rgdemo.tld" prefix=“rgdemo” %> <p> <rgdemo:greetings/></p> </body> </html>

  24. Lifecycle of JSP Tag Library

  25. Where To Get More Information About JSP • http://www.javasoft.com/products/jsp • http://www.javasoft.com/products/servlet • http://www.javasoft.com/j2ee • http://www.jsptags.com • jsp-interest@java.sun.com

  26. Assembling Java For Result

More Related