JSP and Servlets in Java Aabha Sharma, Nikhita Upreti & Divya Bali

Similar documents
SSC - Web development Model-View-Controller for Java web application development

Building Web Applications, Servlets, JSP and JDBC

Course Name: Course in JSP Course Code: P5

Client-Server Architecture & J2EE Platform Technologies Overview Ahmed K. Ezzat

How to Build an E-Commerce Application using J2EE. Carol McDonald Code Camp Engineer

Efficiency of Web Based SAX XML Distributed Processing

What Is the Java TM 2 Platform, Enterprise Edition?

Web Pages. Static Web Pages SHTML

IT6503 WEB PROGRAMMING. Unit-I

Apache Jakarta Tomcat

For Course Details, visit:

Server-Side Web Development JSP. Today. Web Servers. Static HTML Directives. Actions Comments Tag Libraries Implicit Objects. Apache.

CrownPeak Java Web Hosting. Version 0.20

An introduction to creating JSF applications in Rational Application Developer Version 8.0

A Comparative Study of Web Development Technologies Using Open Source and Proprietary Software

Developing XML Solutions with JavaServer Pages Technology

Contents. Client-server and multi-tier architectures. The Java 2 Enterprise Edition (J2EE) platform

Oracle WebLogic Foundation of Oracle Fusion Middleware. Lawrence Manickam Toyork Systems Inc

Agenda. Summary of Previous Session. Application Servers G Session 3 - Main Theme Page-Based Application Servers (Part II)

A framework for web-based product data management using J2EE

INTRODUCTION TO JAVA PROGRAMMING LANGUAGE

WEB APPLICATION DEVELOPMENT. UNIT I J2EE Platform 9

CS Developing Web Applications with Java Technologies

Virtual Credit Card Processing System

JSP Java Server Pages

MVC pattern in java web programming

JReport Server Deployment Scenarios

Glassfish, JAVA EE, Servlets, JSP, EJB

3-Tier Architecture. 3-Tier Architecture. Prepared By. Channu Kambalyal. Page 1 of 19

Complete Java Web Development

JEE Web Applications Jeff Zhuk

Chapter 13 Computer Programs and Programming Languages. Discovering Computers Your Interactive Guide to the Digital World

Case Studies of Running the Platform. NetBeans UML Servlet JSP GlassFish EJB

Japan Communication India Skill Development Center

Credits: Some of the slides are based on material adapted from

White paper. IBM WebSphere Application Server architecture

CSC 551: Web Programming. Spring 2004

In this chapter, we lay the foundation for all our further discussions. We start

Ministry of Education and Advanced Education. OAS 10g High Level Architecture And Functionality

Fig (1) (a) Server-side scripting with PHP. (b) Client-side scripting with JavaScript.

A Comparison of Software Architectures for E-Business Applications

Net-WMS FP Net-WMS SPECIFIC TARGETED RESEARCH OR INNOVATION PROJECT. Networked Businesses. D.8.1 Networked architecture J2EE compliant

Developing ASP.NET MVC 4 Web Applications MOC 20486

Performance Comparison of Database Access over the Internet - Java Servlets vs CGI. T. Andrew Yang Ralph F. Grove

Enterprise Application Development In Java with AJAX and ORM

Client/server is a network architecture that divides functions into client and server

Developing ASP.NET MVC 4 Web Applications

Tutorial: Building a Web Application with Struts

Oracle WebLogic Server 11g: Administration Essentials

Developing ASP.NET MVC 4 Web Applications Course 20486A; 5 Days, Instructor-led

Web Container Components Servlet JSP Tag Libraries

-8*6-DYD6HPLQDU 6HUYOHW$UFKLWHFWXUHV 5DLQHU+LVV$QGUHDV.DSS 6<6725$*

Course Number: IAC-SOFT-WDAD Web Design and Application Development

Introduction to J2EE Web Technologies

Web Application Architecture (based J2EE 1.4 Tutorial)

Web Development. Owen Sacco. ICS2205/ICS2230 Web Intelligence

Pentesting Web Frameworks (preview of next year's SEC642 update)

A Guide to Understanding Web Application Development Corey Benson, SAS Institute, Inc., Cary, NC Robert Girardin, SAS Institute, Inc.

Design Approaches of Web Application with Efficient Performance in JAVA

Web application development landscape: technologies and models

CatDV Pro Workgroup Serve r

ASP.NET: THE NEW PARADIGM FOR WEB APPLICATION DEVELOPMENT

ACM Crossroads Student Magazine The ACM's First Electronic Publication

Equipment Room Database and Web-Based Inventory Management

If your organization is not already

Internet Engineering: Web Application Architecture. Ali Kamandi Sharif University of Technology Fall 2007

Web. Services. Web Technologies. Today. Web. Technologies. Internet WWW. Protocols TCP/IP HTTP. Apache. Next Time. Lecture # Apache.

Japan Communication India Skill Development Center

Database Applications Recitation 10. Project 3: CMUQFlix CMUQ s Movies Recommendation System

Getting Started with Web Applications

Applets, RMI, JDBC Exam Review

Outline. CS 112 Introduction to Programming. Recap: HTML/CSS/Javascript. Admin. Outline

IBM Rational Web Developer for WebSphere Software Version 6.0

As you learned about in Chapter 1, WebSphere Application Server V6 supports the

10. Java Servelet. Introduction

Java EE Web Development Course Program

Portals, Portlets & Liferay Platform

Java EE Introduction, Content. Component Architecture: Why and How Java EE: Enterprise Java

Web Application Development

Java 2 Platform, Enterprise Edition (J2EE) Bruno Souza Java Technologist, Sun Microsystems, Inc.

Japan Communication India Skill Development Center

AN OVERVIEW OF SERVLET AND JSP TECHNOLOGY

HPC Portal Development Platform with E-Business and HPC Portlets

How To Develop A Web Dialog For An Org Database With A Database On A Computer (Oracle)

Java Application Developer Certificate Program Competencies

HPC PORTAL DEVELOPMENT PLATFORM

Web Frameworks. web development done right. Course of Web Technologies A.A. 2010/2011 Valerio Maggio, PhD Student Prof.

S3 Monitor Design and Implementation Plans

2012 LABVANTAGE Solutions, Inc. All Rights Reserved.

Cache Database: Introduction to a New Generation Database

Chapter 2 TOPOLOGY SELECTION. SYS-ED/ Computer Education Techniques, Inc.

Transcription:

JSP and Servlets in Java Aabha Sharma, Nikhita Upreti & Divya Bali (aabha6@gmail.com), (nikhita.upreti@gmail.com), (divyabali16@gmail.com) Abstract: The paper presents an approach for statically reasoning about the behavior of Web applications that are developed using Java Servlets and JSP.it basically depicts the use of java server pages as well as servlets in building a web application in j2ee.we will be covering variety of topics in this paper including: Introduction to jsp and servlets. Life cycle and architecture of servlet and jsp. Working of both Difference between jsp and servlets. Keywords: API, jdbc,taglib,cgi, http, EJB. 1. Introduction: 1.1 JSP: JavaServer Pages (JSP) is a server-side programming technology that enables the creation of dynamic, platform-independent method for building Web-based applications. JSP have access to the entire family of Java APIs, including the JDBC API to access enterprise databases. JSP is a Java view technology running on the server machine which allows you to write template text in (the client side languages like HTML, CSS, JavaScript and so on). JSP supports taglibs, which are backed by pieces of Java code that let you control the page flow or output dynamically. 1.2 SERVLETS: The servlet is a Java programming language class used to extend the capabilities of a server. Although servlets can respond to any types of requests, they are commonly used to extend the applications hosted by web servers, so they can be thought of as Java applets that run on servers instead of in web browsers. Servlet is basically a Java application programming interface (API) running on the server machine, which intercepts requests made by the client and generates/sends a response. A well known example is the HttpServlet which provides methods to hook on HTTP requests using the popular HTTP methods such as GET and POST. 2. Advantages of JSP and Servlets over CGI 2.1 WHY JSP? JavaServer Pages often serve the same purpose as programs implemented using the Common Gateway Interface (CGI). But JSP offer several advantages in comparison with the CGI. Performance is significantly better because JSP allows embedding Dynamic Elements in HTML Pages itself instead of having a separate CGI files. JavaServer Pages are built on top of the Java Servlets API, so like Servlets, JSP also has access to all the powerful Enterprise Java APIs, including JDBC, JNDI, EJB, JAXP etc. JSP pages can be used in combination with servlets that handle the business logic, the model supported by Java servlet template engines. 2.2 WHY Servlets? Performance is significantly better. P a g e 701

Servlets execute within the address space of a Web server. It is not necessary to create a separate process to handle each client request. Servlets are platform-independent because they are written in Java. Java security manager on the server enforces a set of restrictions to protect the resources on a server machine. So servlets are trusted. 3. JSP Architecture and Life Cycle The full functionality of the Java class libraries is available to a servlet. It can communicate with applets, databases, or other software via the sockets and RMI mechanisms that you have seen already. 3.1 JSP Architecture: The following steps explain how the web server creates the web page using JSP: As with a normal page, your browser sends an HTTP request to the web server. The web server recognizes that the HTTP request is for a JSP page and forwards it to a JSP engine. This is done by using the URL or JSP page which ends with.jsp instead of.html. The JSP engine loads the JSP page from disk and converts it into a servlet content. This conversion is very simple in which all template text is converted to println( ) statements and all JSP elements are converted to Java code that implements the corresponding dynamic behavior of the page. A part of the web server called the servlet engine loads the Servlet class and executes it. During execution, the servlet produces an output in HTML format, which the servlet engine passes to the web server inside an HTTP response. The web server forwards the HTTP response to your browser in terms of static HTML content. Finally web browser handles the dynamically generated HTML page inside the HTTP response exactly as if it were a static page. 3.2 JSP Life Cycle: JSP lifecycle is consists of jspinit(), jspservice() and jspdestroy(), and these methods are called life cycle methods of the JSP. The JSP engine compiles the servlet into an executable class and forwards the original request to a servlet engine. P a g e 702

4. Servlet Architecture and lifecycle 4.1 Servlet Architecture: Servlets perform the following major tasks: Read the explicit data sent by the clients (browsers). This includes an HTML form on a Web page or it could also come from an applet or a custom HTTP client program. Read the implicit HTTP request data sent by the clients (browsers). This includes cookies, media types and compression schemes the browser understands, and so forth. Process the data and generate the results. This process may require talking to a database, executing invoking a Web service, or computing the response directly. Send the explicit data (i.e., the document) to the clients (browsers). This document can be sent in a variety of formats, including text (HTML or XML), binary (GIF images), Excel, etc. Send the implicit HTTP response to the clients (browsers). This includes telling the browsers or other clients what type of document is being returned (e.g., HTML), setting cookies and caching parameters, and other such tasks. 4.2 Life Cycle of Servlet: The web container maintains the life cycle of a P a g e 703

servlet instance. Let's see the life cycle of the servlet: 1. Servlet class is loaded. 2. Servlet instance is created. 3. init method is invoked. 4. service method is invoked. 5. destroy method is invoked. 5.JSP vs Servlet JSP Servlets JSP is a webpage scripting language that can generate dynamic content. Servlets are Java programs that are already compiled which also creates dynamic web content. JSP run slower compared to Servlet as it takes compilation time to convert into Java Servlets. Servlets run faster compared to JSP. It s easier to code in JSP than in Java Servlets. Its little much code to write here. In MVC, jsp act as a view. In MVC, servlet act as a controller. JSP are generally preferred when there is not much processing of data required. servlets are best for use when there is more processing and manipulation involved. The advantage of JSP programming over servlets is that we can build custom tags which can directly call Java beans. There is no such custom tag facility in servlets. We can achieve functionality of JSP at client side by running JavaScript at client side. There are no such methods for servlets. P a g e 704

Conclusion: In this paper we have taken into consideration all aspects of java server pages as well as servlets, discussed about their architectures and life cycles and their working. Comparison between the two technologies has also been made towards the end of the paper. On comparing and contrasting the two we find out that main difference between them is, In servlets both the presentation and business logic are place it together. Where as in jsp both are separated by defining by java beans.in jsp's the overall code is modulated so the developer who doesn't know about java can write jsp pages by simply knowing the additional tags and class names. One more important to be considered is servlet take less time to compile. Jsp is a tool to simplify the process and make the process automate. Both are web applications used to produce web content that mean dynamic web pages. Both are used to take the requests and service the clients. References: [1] http://www.tutorialspoint.com/jsp/ [2] http://users.polytech.unice.fr/~buffa/cours/ internet/polys/servlets/servlet-tutorial- Overview.html [3] http://www.tutorialspoint.com/servlets/ [4] http://en.wikipedia.org/wiki/java_servlet [5] http://stackoverflow.com/questions/20953 97/what-is-the-difference-between-jsfservlet-and-jsp [6] http://www.javatpoint.com/life-cycleof-a-servlet [7]http://www.allinterview.com/showansw ers/10953.html P a g e 705