1 / 20

UNIT

Web Application fundamentals. UNIT. Topics:. What is a JSP JSP Custom tags. What is JSP. JSP stands for Java Server Pages . It is to used to write Java code inside HTML page (Show example menuItem.jsp ) Main advantages JSP are :

ebeebe
Download Presentation

UNIT

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. Web Application fundamentals • UNIT • Topics: • What is a JSP • JSP Custom tags

  2. What is JSP • JSP stands for Java Server Pages. It is to used to write Java code inside HTML page (Show example menuItem.jsp) • Main advantages JSP are: • Separation of static and dynamic contents: JSP enables the separation of static contents from dynamic contents.  The dynamic contents are generated via programming logic and inserted into the static template. This greatly simplifies the creation and maintenance of web contents. • Reuse of components and tag libraries: The dynamic contents can be provided by reusable components such as JavaBean and tag libraries - you do not have to re-inventing the wheels. • Java's power and portability

  3. JSP as View ( show kaizfood-view.xml)

  4. How is JSP file Processed? ( show deployed kaizfood.war)

  5. When a JSP page is first requested, Tomcat translates the JSP into a servlet, compiles the servlet, load, and execute the servlet. The best way to understand JSP is to check out the generated servlet and study the JSP-to-Servlet translation. The generated servlet for "first.jsp" is kept under Tomcat's "work" directory ("<CATALINA_HOME>\work\Catalina\localhost\hellojsp\..."). The relevant part of the generated servlet is extracted below: • When a JSP page is first requested, Tomcat translates the JSP into a servlet, compiles the servlet, load, and execute the servlet. • The best way to understand JSP is to check out the generated servlet and study the JSP-to-Servlet translation. The generated servlet for “index.jsp" is kept under Tomcat's "work" directory ("<CATALINA_HOME>\work\Catalina\localhost\kaizfood\..."). • Note: Show index.java • The methods _jspInit(), _jspDestroy() and _jspService() corresponds to init(), destroy() andservice() (doGet(), doPost()) of a regular servlet. • Similar to servlet's service(), _jspService() takes two parameters, request and response, encapsulating the HTTP request and response messages. AJspWriter called out, corresponding to servlet's PrintWriter, is allocated to write the response message over the network to the client. Behind the scenes

  6. JSP Scripting Elements ( show example on index.jsp)

  7. JSP Scripting Elements: Expressions ( show example on index.jsp)

  8. JSP Scripting Elements: Declarations ( show example on index.jsp)

  9. JSP Server Objects • JSP pre-defined seven variables, that are available to the script writer. They are: request, response, out, session, application, config, and page. • request: A HttpServletRequest object, keeping track of the HTTP request message. It is often used to retrieve the query parameters in the request message. For example, • response: A HttpServletResponse object, keeping track of the HTTP response message. • out: A Writer (JspWriter) object used to write response message to the client over the network socket, via methods print() or println().

  10. JSP Server Objects • session: A HttpSession object, keeping track of the current client session (from the moment the user accesses the first page, until he/she closes the browser or session timeout). You can use session's attributes to pass information between pages within this session, via methods getAttribute("name") and setAttribute("name", object). • application: A ServletContext object retrieved via getServletContext(), which maintains information about this web context (web application). You can use the application's attributes to pass information between JSP pages and servlets, via methods getAttribute("name") and setAttribute("name", object). • config: A ServletConfig object, obtained via getServletConfig(). It could be used to retrieve the servlet initialization parameters provided in "WEB-INF\web.xml", via method getInitParameter("paramName"). • page: Can be used to access the elements of this page.

  11. JSP Including files: <%jsp: include page=“” %> show menuItem.jsp

  12. JSP Including files: <%@ include file=“” %> show menuItem.jsp

  13. Developing error page

  14. Deploying error page

  15. JSP Directives

  16. JavaServer Pages Standard Tag Library (JSTL) • The JavaServer Pages Standard Tag Library (JSTL) is a collection of useful JSP tags which encapsulates core functionality common to many JSP applications. • JSTL has support for common, structural tasks such as iteration and conditionals, tags for manipulating XML documents, internationalization tags, and SQL tags. It also provides a framework for integrating existing custom tags with JSTL tags. • The JSTL tags can be classified, according to their functions, into following JSTL tag library groups that can be used when creating a JSP page: • Core Tags • Formatting tags • SQL tags • XML tags • JSTL Functions

  17. Installing Standard Tag Library (JSTL) Download the binary distribution from Apache Standard Taglib and unpack the compressed file. Show JSTL.jar and menuItem.jsp Core Tags: The core group of tags are the most frequently used JSTL tags. Following is the syntax to include JSTL Core library in your JSP: <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

  18. Core tags

  19. Interview Questions 1. What is JSP? JavaServer Pages (JSP) is a technology for developing web pages that support dynamic content which helps developers insert java code in HTML pages by making use of special JSP tags, most of which start with <% and end with %>. 2. What is the need of tag library? Tag library is a collection of custom tags. Custom actions helps recurring tasks will be handled more easily they can be reused across more than one application and increase productivity. JSP tag libraries are used by Web application designers who can focus on presentation issues rather than being concerned with how to access databases and other enterprise services. Some of the popular tag libraries are Apache display tag library and String tag library. You can also check my post on display tag library example on Spring.

More Related