JSP

JavaServer Pages

The Typical Web server, different clients connecting via the Internet to a Web server. In this example, the Web server is running on Unix and is the very popular Apache Web server. server.

First static web pages were displayed. Afterwards Perl and C were languages used on the web server to provide dynamic content. Soon most languages including Visualbasic, Visualbasic, Delphi, C++ and Java could be used to write applications that provided dynamic content using data from text files or database requests. These were known as CGI server side applications. ASP was developed by Microsoft to allow HTML developers to easily provide dynamic content supported as standard by Internet Information Server (IIS). JSP was developed by Sun Microsystems.

JSP was developed by Sun Microsystems to allow server side development. . JSP files are HTML files with special Tags containing Java source code that provide the dynamic content.Introduction to Java Server Pages  JavaServer Pages (JSP) is a technology based on the Java language and enables the development of dynamic web sites.

.

JSP source code runs on the web server in the JSP Servlet Engine. The JSP Servlet engine dynamically generates the HTML and sends the HTML output to the client's web browser« .

Why use JSP? JSP is easy to learn and allows developers to quickly produce web sites and applications in an open and standard way. an object oriented language. JSP is based on Java. JSP offers a robust platform for web development. . Advantages of Java. Main reasons to use JSP: JSP: Multi platform (windows n unix) unix) Component reuse by using Javabeans and EJB.

short- Text files containing HTML Java code .What are Java Server Pages? Conceptually seen as ³scripts´ Adopt more procedural style of coding OO techniques are still possible Adopt a modern web development style Simplified syntax Many built-in short-cuts built.

web server or JSP Servlet engine. . Moving JSP file from one platform to another.You can take one JSP file and move it to another platform.

HTML and graphics displayed on the web browser are classed as the presentation layer.. JavaServer Pages Implementation JSP Java developers presentation web designers .

one servlet copy. persistence Convenient: Convenient: lots of high-level utilities highPowerful: Powerful: talking to server.Advantages of Servlets Efficient: Efficient: threads instead of OS processes. sharing data. pooling. persistence Portable: Portable: run on virtually all operating systems and servers Secure: Secure: no shell escapes. no buffer overflows Inexpensive: Inexpensive: inexpensive plug-ins if servlet plugsupport not bundled .

Pro l ith r l t r l t development requires high-level of d lopment highunderstanding of many concepts Too much overhead in development cycle (implementation n design concatenated) Limited uilt-in productivity mechanisms uiltClunky syntax (unorganised) (unorganised) .

richer language server-side. portable Versus PHP: better language for dynamic part Versus pure servlets: more convenient to create servlets: HTML Versus SSI: much more flexible and powerful Versus JavaScript: server-side.Advantages f J P Versus ASP: better language for dynamic part. Versus static HTML: dynamic features .

JSP or Servlets: How do I choose? Servlets: Servlets Servlets usage Minimal HTML generation Somewhat constant logic Complex Java logic Servlet disadvantages No pre-built set of reusable components Hard to maintain when HTML intensive Require Java expertise Development cycle Servlet benefits Complete control Advanced development Flexible JSP JSP usage Complex HTML Dynamic logic ³simple´ Java logic JSP disadvantages Can get messy Can be misused JSP benefits Pre-built components Expression language Convenience features Requires minimal Java knowledge Development cycle Flexible .

It then compiles the source file into a class file. Any time after this the special compiled servlet is executed and is therefore returns faster.jsp rather than .jsp servlet source file.jsp and creates a Java . The JSP file extension is . . These JSP tags can contain Java code. JSPs are essential an HTML page with special JSP tags re embedded.html.jsp .JSP rchitect re JSPs re b ilt on top of SUN's servlet technology.htm The JSP engine parses the . .htm or . this is done the first time and this why the JSP is probably slower the first time it is accessed.

.

HTML results are displayed on the user's web browser. 3. 2. otherwise go to step 7.jsp). The web browser makes the request .jsp). therefore passes the JSP file to the JSP Servlet Engine.jsp). the JSP file is parsed.jsp). 6. The user goes to a JSP page (ending with . calling the init and service methods. All the HTML required is converted to println statements. The Servlet is instantiated. The Web server recognises that the file required is special (. 5. 9. . 7. (.Steps required for a JSP request: 1. via the Internet. HTML from the Servlet output is sent via the Internet. The Servlet source code is compiled into a class. The user goes to a web site made using JSP. 8. The JSP request gets sent to the Web server. If the JSP file has been called the first time. The next step is to generate a special Servlet from the JSP file. 4.

Installing a software Java 2 Standard addition Software Development Kit(J2SE SDK)  Apache Jakarta Tomcat   Tomcat is known as servlet container. world. In java. servlet container is responsible for receiving web requests and passing them to the java web application. .

.

.

.

.

.

.

.

.

.

.

JSP Syntax Tags  6 primary JSP syntax tags <%-<%-.« --%> --%> Comment Server side comment style Single or multi-line multi<%@ « %> Directive Used to describe page characteristics Provides execution information to container <%! « %> Declaration Used to declare variables or methods Can inadvertently create a non-thread safe JSP non- .

]  6 primary JSP syntax tags <% « %> Scriptlet Used to apply ³business logic´ to HTML generation Typically intermixed with HTML throughout page <%= « %> Expression Used to convert Java value into HTML text Easy way to write out a value <jsp:«> « </jsp:«> jsp:«> </jsp:«> JSP action Predefined executable tags Simplifies JSP syntax .JSP Syntax Tags [cont.

JSP evelopment Like writing an HTML document JSP has its own set of tags Contains HTML presentation logic Includes conditional Java logic Can include JavaScript or XML Normally stored in a .jsp file .jsp Handles request Generates response .

com/ Java Web Server: http://www.com/software/jwebserver/try/ .gefionsoftware.ht ml JRun: http://www.apache.allaire.com/ LiteWebServer: http://www.sun.com/products/jrun/ ServletExec: http://newatlanta.Free Servlet and S Software Tomcat: http://jakarta.com/products/servlet/download.sun.org/ JSWDK: http://java.

Thank You Queries??? .