1 / 9

CSC 485 IST 350

CSC 485 IST 350. JSP. What Is JSP. JSP stands for JavaServer Page Available since 1999 (JSP 1.0), and now in JSP 1.2 Part of the J2EE API: considered as Web Components, together with Java Servlet

kumiko
Download Presentation

CSC 485 IST 350

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. CSC 485IST 350 JSP

  2. What Is JSP • JSP stands for JavaServer Page • Available since 1999 (JSP 1.0), and now in JSP 1.2 • Part of the J2EE API: • considered as Web Components, together with Java Servlet JavaServer Pages (JSP) technology provides a simplified, fast way to create web pages that display dynamically-generated content.

  3. A Simple JSP Page • A JSP page is like a regular HTML page with special tags <html><head><title>Current Time</title> </head><body>Current time is <%= new java.util.Date() %></body><html>

  4. How Is a JSP Processed? Web Server Host Sample URL http://www.server.com:8080/servlet/JSPFile Host Machine File System /servlet/JSPFile.jsp Send a request URL Web Server Process servlet Generate response Get JSP file Request servlet HTML returned Servlet Engine JSP Translator Web Browser Get servlet

  5. How Does JSP Work? (older view) • A client requests a JSP page from a web server • The web server must support JSP (such as the Tomcat server) • The JSP pages must have a .jsp extension • The web server • Translates the JSP into a Java servlet • Compiles the servlet, and • Executes it • The result of the execution, an HTML page, will be sent back to the browser

  6. How Does JSP Work? (current view) • JSP pages use XML tags and scriptlets written in the Java programming language to encapsulate the logic that generates the content for the page. • It passes any formatting (HTML or XML) tags directly back to the response page. In this way, JSP pages separate the page logic from its design and display. • JSP technology is part of the Java technology family. JSP pages are compiled into servlets and may call JavaBeans components (beans) or Enterprise JavaBeans components (enterprise beans) to perform processing on the server.

  7. JSP Constructs • Scripting constructs • Expressions: <%= java-expr %> • Scriptlets: <% java-statement(s); %> • Declarations: <% java method or field declaration %> • Comments: <%-- JSP comment --%> <!-- HTML comment --> • Directives: <%@ directive attr1=“value1”[attr2=“value2”] %> • Actions

  8. Using JavaBeans in JSP • A JavaBeans component may be used in a JSP to provide information needed in generating dynamic contents • A class is a JavaBeans component if • The class is public • The class has an no-args public constructor • The class is serializable • The syntax is<jsp:useBean id=“objName” scope=“...”class=“ClassName” />

  9. Getting and Setting Properties • The JavaBeans components normally have getters and setters • These methods can be used as follows • Passing information into the page<jsp:getProperty id=“beanId” property=“sample” /> • Retrieving information from the page<jsp:setProperty id=“beanId” property=“sample” value=“test1”/> • Typically, these constructs will be missed up with HTML tags

More Related