1 / 23

What is JSP?

What is JSP?. Team 3D: Diana Diamond Rujul Inamadar Luis Rubio Gabriel Familia. CS612 Fall ‘07 Concepts and Structures in Internet Computing Prof. C. Scharff Pace University, NY. Project website: http://f07-cs612-team3.wikispaces.com. Overview. Introduction What is JSP?

zuwena
Download Presentation

What is JSP?

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. What is JSP? Team 3D: Diana Diamond Rujul Inamadar Luis Rubio Gabriel Familia CS612 Fall ‘07 Concepts and Structures in Internet Computing Prof. C. Scharff Pace University, NY Project website: http://f07-cs612-team3.wikispaces.com

  2. Overview • Introduction • What is JSP? • Reasons why the JSP technology was created • Type of JSP project we're discussing • Body • Developing JSP pages • Show the demo of the application • Explanation of the application • How is it different from using Servlets? • Conclusion • Summary of the topic • Why is it better to use JSP than Servlets?

  3. The basics of JSP • JSP, short of JAVA SERVER PAGES . harmonizes how web designers and programmers create dynamic web pages. • Created by Sun Microsystems in (as an extension to the Java servlet technology) it allows HTML to be combined with Java on the same page. The Java provides the processing, and the HTML provides the page layout that will be rendered in the Web browser.

  4. The JSP Approach • JSPs are compiled into Java Servlets by a JSP compiler. A JSP compiler may generate a servlet in Java code that is then compiled by the Java compiler, or it may generate byte code for the servlet directly. JSPs can also be interpreted on-the-fly reducing the time taken to reload changes.

  5. Why JSP ? • Many Web pages that are built by CGI programs are mostly static, with the dynamic part limited to a few small locations. But most CGI variations, including servlets, make you generate the entire page via your program, even though most of it is always the same.

  6. Example • JSP lets you create the two parts separately. Here's an example: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <HEAD><TITLE>Welcome to Our store </TITLE></HEAD> <BODY> <H1>Welcome to Our Store</H1> <SMALL>Welcome, <!-- User name is "New User" for first-time visitors --> <% out.println(Utils.getUserNameFromCookie(request)); %> To access your account settings, click <A HREF="Account-Settings.html">here.</A></SMALL> <P> Regular HTML for all the rest of the on-line store's Web page. </BODY></HTML> • whenever there is a change in the code, we dont have to recompile the jsp. it automatically does the compilation. • By using custom tags and tag libraries the length of the java code is reduced.

  7. More reasons for JSP • JSP is Java base so it can run in Win or Unix/Linux. • Fast development using Model View Controller by separating request processing, Business Logic and Presentation layers. • Ease of maintenance • Allow web designers to develop web pages without knowing all the intricate parts of Java • To make $$$$

  8. Writing JSP Pages JSP tools – JSP capable web-server or application server: Blazix, Jetty, Tomcat, WebLogic, WebSphere JSP Elements • Directive Elements • Scripting Elements • Declaration • Scriptlets • Expressions • Action Elements • Directory Structure

  9. Writing JSP Pages, part 2 • A few tags embed different types of Java code within the HTML: • <%@ %> used as directive for “import” statements; • <%! %> used to add variable/method declarations; • <%= %> used to enclose Java expressions that will be evaluated at run time; • <% %> used to add blocks of Java code (“scriplets”) that will be executed every time the JSP is invoked;

  10. How/Where it does it • JSP is executed in the Server. • Html is produced and rendered to the client. • Client only requires a browser with JRE if plug-in need to be deployed. • JSP allow you to use Java Bean, Java scriplets or JSP tags.

  11. Server process for creating and running JSP servlets

  12. How/Where it does it • Main thing to remember is that JSP is Server-Side Technology. • When the page is requested, the JSP gets translated into a Java file, compiled (once), and loaded. (basic example of code) <HTML> <HEAD> <H2>Time check</H2> </HEAD> <BODY> What time is it? <%= new java.util.Date() %> </BODY> </HTML> ****save as timeck.jsp and not timeck.html Special tags allow you to embed Java expressions.

  13. Sample Code/Syntax <--Author: Gabriel Familia --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <title>Add</title> </head> <body> <% String a = request.getParameter( "firstNumber" ); %> <% String b = request.getParameter( "secondNumber" ); %> <% int firstNumber = Integer.parseInt( a ); %> <% int secondNumber = Integer.parseInt( b ); %> <% int sum = firstNumber + secondNumber; %> The sum of the two integers is: <%=sum %> </body> </html>

  14. Project Description Objective • Demonstrated a simple way to validate data in JSP. Results • Validated a user form by using JSP.

  15. Demo of the application Go to f07-cs612-team3.wikispaces.com to view the video under the “Files” section and click on the AVI file

  16. userinfoinput.jsp N userinfovalidate.jsp Y userinfovalid.jsp Flow • In this example we will use three JSP pages. • userinfoinput.jsp – Which will collect the data • userinfovalidate.jsp - Which will validate the data. On success will continue to the userinfo Valid or send back to userinfoinput.jsp on error. • userinfovalid.jsp – Shows on a succesful validation. Presentation layer Business Logic / Request Processing Presentation layer

  17. Userinfoinput.jsp <%@ page contentType="text/html" %> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <html> <head> <title>User Info Entry Form</title> </head> <body bgcolor="white"> <jsp:useBean id="userInfo" scope="request" class="com.ora.jsp.beans.userinfo.UserInfoBean" /> Create or use a data class container to carry info Define the scope of the data

  18. Userinfoinput.jsp (Cont) • <form action="userinfovalidate.jsp" method="post"> • <input type="hidden" name="submitted" value="true"> • <table> • <c:if test="${param.submitted && !userInfo.userNameValid}"> • <tr><td></td> • <td colspan="2"><font color="red"> • Please enter your Name • </font></td></tr> • </c:if> • <tr> • <td>Name:</td> • <td> • <input type="text" name="userName" • value="<c:out value="${userInfo.userName}" />"> • </td> • </tr> Retrieves data from the useBean if page is redirected back Post to the validation JSP page

  19. userinfovalidate.jsp <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> <jsp:useBean id="userInfo" scope="request" class="com.ora.jsp.beans.userinfo.UserInfoBean"> <jsp:setProperty name="userInfo" property="*" /> </jsp:useBean> <c:choose> <c:when test="${userInfo.valid}"> <jsp:forward page="userinfovalid.jsp" /> </c:when> <c:otherwise> <jsp:forward page="userinfoinput.jsp" /> </c:otherwise> </c:choose> Userinfobean is use to validate No Html is used here On Success we forward to the next page On fail it redirects back to the input and displays the errors.

  20. userinfovalidate.jsp • <html> • <head> • <title>User Info Validated</title> • </head> • <body bgcolor="white"> • <font color="green" size="+3"> • Thanks for entering valid information! • </font> • </body> • </html> The user get this page on success only

  21. How is it different from using Servlets? • JSP and Servlet are both executed on the server. The main different is that JSP embeds scripts in Html. Servlet is Java code and has Html ouputs embeded on the code.

  22. Thanks for watching the presentation!

  23. Possible graphics/toons Even geeks have a sense of humor too…

More Related