Session 5 : intro to jsp  - Giáo trình Bách Khoa Aptech
Upcoming SlideShare
Loading in...5
×

Like this? Share it with your network

Share
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
1,445
On Slideshare
893
From Embeds
552
Number of Embeds
1

Actions

Shares
Downloads
65
Comments
0
Likes
0

Embeds 552

http://forum.hoclaptrinhweb.com 552

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. Slide 1 of 20 Introduction to JSP
  • 2. Slide 2 of 20 Objectives  JSP  Benefits of JSP  JSP Request – Response Cycle  Servlet – JSP  JSP Life Cycle  Elements / Tags of JSP  Implicit Objects
  • 3. Slide 3 of 20 JSP  Java Server Page (JSP) is a server side script language  Saved with .jsp extension  A simple, yet powerful Java technology for creating and maintaining dynamic-content webs pages  JSP page are converted by the web container into a Servlet instance  It focus on the presentation logic of the web application
  • 4. Slide 4 of 20 Benefits of JSP  Segregation of the work profiles of a Web designer and a Web developer  Emphasizing Reusable Components  Simplified Page Development
  • 5. Slide 5 of 20 JSP Request-Response Cycle
  • 6. Slide 6 of 30 Servlet - JSP Servlet JSP HTML Code inside Java Java Code inside HTML Extensive Coding Less Coding Saved with .java Saved with .jsp Designed for Business Logic Designed for Presentation Logic Any changes are made to the html code, then necessary to compile and test the HTML code No need to compile again and again to obtain the required changes. Manual Compilation is required to changes made to any files Automatically incorporates changes made to any files
  • 7. Slide 7 of 20 JSP Life Cycle Translation Compilation Execution
  • 8. Slide 8 of 30 Elements / Tags of JSP  Types of Tags – Scripting-oriented tags – XML-based tags Elements / Tags Syntax Comments <%-- --%> Directives <%@ %> Declarations <%! %> Expression <%= %> Scriptlet <% %> Actions <jsp: />, <jsp: > </jsp: >
  • 9. Slide 9 of 30 Page Directives  Defines attributes that notify the JSP engine about the general settings of a JSP page – <%@page attribute1=“value” attribute2=“value” %> – <jsp:directive.page attribute1=“value” attribute2=“value” /> Attribute Default Value Examples language “java” “java” contentType “text/htm” contentType=“text/html” contentType=“text/xml” extends None extends=“com.Login” import None import=“java.util.Vector, java.sql.*”
  • 10. Slide 10 of 30 Page Directives Attribute Default Value Examples session “true” session=“false” info None info=“Registration Form” buffer “8kb” Buffer=“12kb” Buffer=“false” autoFlush “true” autoFlush=“true” isThreadSafe “true” isThreadSafe=“false” errorPage None errorPage=“results/error.jsp ” isErrorPage “false” isErrorPage=“true”
  • 11. Slide 11 of 20 Include / Taglib Directory  Include directory is used to include contents of one file in another. – <%@include file=“footer.jsp” %> – <jsp:directive.include file=“footer.jsp” />  Taglib directory is used custom tag – <%@taglib uri=“ATMTag.tld” prefix=“atm” %> – <jsp:directive.taglib uri=“ATMTag.tld” prefix=“atm” />
  • 12. Slide 12 of 30 Implicit Objects Object Class / Interface page javax.servlet.jsp.HttpJspPage config javax.servlet.ServletConfig request javax.servlet.http.HttpServletRequest response javax.servlet.http.HttpServletResponse out javax.servlet.jsp.JspWriter session javax.servlet.http.HttpSession application javax.servlet.ServletContext pageContext javax.servlet.jsp.PageContext exception java.lang.Throwable
  • 13. Slide 13 of 20 Action Tags / Elements  Forward  Include  Plug-in  Bean tags
  • 14. Slide 14 of 20 Forward  To permanently transfer control from a JSP page to another location on the local server – <jsp:forward page=“/user/UserHome.jsp” /> – <jsp:forward page=“/user/ChangePassword.jsp”> • <jsp:param name=“UserId” value=“common” /> – </jsp:forward>
  • 15. Slide 15 of 20 Include  To incorporate the content or insert a file from another page into current page – <jsp:include page=“ChangePwd.jsp” flush=“true” /> – <jsp:include page=“ChangePwd.jsp” flush=“true”> <jsp:param name=“UserId” value=“common” /> – </jsp:include>  The include directive inserts the file at the time the JSP page is translated into a Servlet  The include action inserts the file at the time the page is requested
  • 16. Slide 16 of 20 Plug-in – The <jsp:plugin> action is used to generate browser- specific HTML for specifying Java applets which rely on Sun Microsystem’s Java plug-in <jsp:plugin type=“applet” code=“test.AppletTest” codebase=“/classes/applets” height=“150” width=“100”> <jsp:params> <jsp:param name=“color” value=“blue” /> <jsp:param name=“speed” value=“fast” /> </jsp:params> <jsp:fallback> Your browser can’t display this applet text </jsp:fallback> </jsp:plugin>
  • 17. Slide 17 of 20 Java Bean
  • 18. Slide 18 of 20 Bean Tags – <jsp:useBean /> action tag is used to create a reference and include an existing bean component in JSP – <jsp:useBean id=“myCar” class=“cars.CarBean” scope=“page | request | session | application” /> – <jsp:setProperty name=“myCar” property=“make” value=“Ford” /> – <jsp:setProperty name=“myCar” property=“make” param=“txtMake” /> – <jsp:getProperty name=“myCar” property=“make” />
  • 19. Slide 19 of 20 Summary  JSP  Benefits of JSP  JSP Request – Response Cycle  JSP Life Cycle  Elements / Tags of JSP – Comments – Directives – Declarations – Expression – Scriptlet
  • 20. Slide 20 of 20 Summary  Implicit Objects  Action Tags – Forward – Include – Plug-in – Bean Tags