1 / 22

JSP (Java Server Pages)

JSP (Java Server Pages). JSP is a technology based on the Java language that enables the development of dynamic web sites. JSP was developed by Sun Microsystems to allow server side programming.

rhea-tyson
Download Presentation

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) • JSP is a technology based on the Java language that enables the development of dynamic web sites. • JSP was developed by Sun Microsystems to allow server side programming. • JSP files are HTML files with special Tags containing Java source code that provide the dynamic content.

  2. JSP (Java Server Pages) • JSP pages use scriptlets to encapsulate the java code that generates content for the page. • JSP page has extension .jsp

  3. Why use JSP ? • A separation of presentation and implementation. • web designers work only on the presentation. • Java developers concentrate on implementing the application.

  4. Why use JSP ? • JSP can run on various web server including Apache & Netscape. • JSP pages uses components like enterprise java beans, java beans, which are reusable. This gives JSP reusability capabilities. This will keep pages simple & run faster.

  5. JSP Architecture Steps required for a JSP request: 1. The user goes to a web site made using JSP. The user goes to a JSP page (ending with .jsp). The web browser makes the request via the Internet. 2. The JSP request gets sent to the Web server.

  6. JSP Architecture 3. The Web server recognises that the file required is special (.jsp), therefore passes the JSP file to the JSP Servlet Engine. 4. If the JSP file has been called the first time,the JSP file is parsed,otherwise go to step 7.

  7. JSP Architecture 5. The next step is to generate a special Servlet from the JSP file. 6. The Servlet source code is compiled into a class. 7. The Servlet is instantiated,calling the init and service methods.

  8. JSP Architecture 8. HTML from the Servlet output is sent via the Internet. 9. HTML results are displayed on the user's web browser.

  9. JSP tags There are five main tags: • Declaration tag • Expression tag • Directive tag • Scriplet tag • Action tag

  10. Declaration tag ( <%!  %> ) • This tag allows the developer to declare variables or methods. • Before the declaration you must have <%! • At the end of the declaration, the developer must have %> • Code placed in this tag must end with a semicolon ;

  11. Declaration tag ( <%!  %> ) For Example,<%!          int count= 0 ;          String Account ; %>

  12. Expression tag ( <%=   %>) • This tag allows the developer to embed any Java expression and is short for out.println(). • A semicolon ( ; ) does not appear at the end of the code inside the tag.

  13. Expression tag ( <%=   %>) • For example, to show the current date and time. Date : <%= new java.util.Date() %>

  14. Directive tag ( <%@ directive ... %>) • Directives are instructions for JSP engine that are processed when JSP page is compiled into a servlet. • There are three main types of directives: 1)     page - is used to provide information about page. 2)     Include - is used to include a file in jsp page. 3)     Tag library - A tag lib is a collection of custom tags that can be used by the jsp pages.

  15. Directive tag ( <%@ directive ... %>) • <%@ page langauge=“java” import=“java.sql.* ” %> • <%@ include file = “abc.jsp" %> • <%@ taglib uri=“http://www.jspcentral.com/tags” prefix="tld" %> <tld:loop> </tld:loop>

  16. Scriptlet tag ( <% ... %> ) • Between <% and %> tags, any valid Java code is called a Scriptlet. •   For example, to print a variable.    <%          String username = “John”;          out.println( username ) ;   %>

  17. Action Tag • These are specific tags that affect the runtime behaviour of JSP. • <jsp:include> - this action allows a static or dynamic resource to be included in the JSP at request time. <jsp:include page=“header.jsp”/>

  18. Action Tag • <jsp:forward> - This action forwards a client request to an HTML file, .jsp file. <jsp:forward page=“one.jsp”/>

  19. First JSP page <html><head><title>My first JSP page</title></head><body><h3>Today is : <%= new java.util.Date() %></h3> </body></html>

  20. Output Today is : Tue Sep 09 12:43:33 2008

  21. JSP compared to Servlets • Servlet is a java class, that is both HTML tags & code exists in a class. • So when changes are made to code, modification & recompilation of servlet source file is required. • JSP page doesnot need to be recompiled if there are some changes made in the servlet. • JSP separates the look from the content.

More Related