Top Banner
INFORMATION ABOUT JSP , SERVLETS & STRUTS Made by: ALKESH KHARE
54

Information About JSP ,Servlets,Struts

Dec 03, 2015

Download

Documents

Alkesh Khare

Advance Java Programming of two number addition using JSP (Java Server Pages) only and servlet only in Netbeans.
Using Struts framework for insertion in a Database Microsoft SQL server 2005 from JSP webpage.
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Information About JSP ,Servlets,Struts

INFORMATION ABOUT JSP ,SERVLETS & STRUTS

Made by:ALKESH KHARE

Page 2: Information About JSP ,Servlets,Struts

Contents1 Introduction to JSP

1.1 Advantages 1.2 Disadvantages 1.3 JSP Example 1.3.1 Program for addition in JSP

1.3.2 JSP Program using Request Dispatcher2 Introduction to Servlet

2.1 Advantages2.2 Disadvantages2.3 Servlet Example2.3.1 Program for addition in Servlet

3 JSP & Servlet works in MVC Format4 Introduction to Struts

4.1 Advantages4.2 Disadvantages4.3 Struts Example4.3.1 Program for inserting data in Database

Page 3: Information About JSP ,Servlets,Struts

JavaServer Pages

JavaServer Pages (JSP) is a technology that helps software developers to create dynamically generated web pages based on HTML, XML, or other document types. Released in 1999 by Sun Microsystems, JSP is similar to PHP, but it uses the Java programming language.

Page 4: Information About JSP ,Servlets,Struts

Advantages of JSP :Following is the list of other advantages of using JSP over other

technologies vs. Active Server Pages (ASP): The advantages of JSP are

twofold. First, the dynamic part is written in Java, not Visual Basic or other MS specific language, so it is more powerful and easier to use. Second, it is portable to other operating systems and non-Microsoft Web servers.

vs. Pure Servlets: It is more convenient to write (and to modify!) regular HTML than to have plenty of println statements that generate the HTML.

vs. Server-Side Includes (SSI): SSI is really only intended for simple inclusions, not for "real" programs that use form data, make database connections, and the like.

vs. JavaScript: JavaScript can generate HTML dynamically on the client but can hardly interact with the web server to perform complex tasks like database access and image processing etc.

vs. Static HTML: Regular HTML, of course, cannot contain dynamic information.

Page 5: Information About JSP ,Servlets,Struts

Disadvantages of JSP

JSP pages require about double the disk space to hold the page.

JSP pages must be compiled on the server when first accessed. This initial compilation produces a noticeable delay when accessing the JSP page for the first time.

Page 6: Information About JSP ,Servlets,Struts

JSP Example

We can be choose any smarter way of coding.

I choose NetBeans IDE 8.0.1 for making JSP Programs. It provide a Software Development Platform.

-Before preparing any jsp servlet program. Many things we have to keep in mind that which application server or web server we are using(for example that I am using application server of glassfish)

Page 7: Information About JSP ,Servlets,Struts

Program for addition in Jsp.

Page 8: Information About JSP ,Servlets,Struts

#addition.jsp

Page 9: Information About JSP ,Servlets,Struts

Output

Page 10: Information About JSP ,Servlets,Struts

Output:

Page 11: Information About JSP ,Servlets,Struts

JSP Program using Request Dispatcher

Page 12: Information About JSP ,Servlets,Struts

#newjsp.jsp

Page 13: Information About JSP ,Servlets,Struts

Output

Page 14: Information About JSP ,Servlets,Struts

Output

Page 15: Information About JSP ,Servlets,Struts

Servlet

A servlet is a Java programming language class that is used to extend the capabilities of servers that host applications accessed by means of a request-response programming model. Although servlets can respond to any type of request, they are commonly used to extend the applications hosted by web servers.

Page 16: Information About JSP ,Servlets,Struts

Advantages of Servlet Servlets provide a way to generate dynamic

documents that is both easier to write and faster to run.

provide all the powerful features of JAVA, such as Exception handling and garbage collection.

Servlet enables easy portability across Web Servers.

Servlet can communicate with different servlet and servers.

Since all web applications are stateless protocol, servlet uses its own API to maintain  session

Page 17: Information About JSP ,Servlets,Struts

Disadvantages of Servlets

Designing in servlet is difficult and slows down the application.

Writing complex business logic makes the application difficult to understand.

You need a Java Runtime Environment on the server to run servlets. 

Page 18: Information About JSP ,Servlets,Struts

Servlet Example:Program for addition in Servlet

Page 19: Information About JSP ,Servlets,Struts

#addition.java(Servlet)

Page 20: Information About JSP ,Servlets,Struts

Output:

Page 21: Information About JSP ,Servlets,Struts

Output:

Page 22: Information About JSP ,Servlets,Struts

JSP and Servlet works in Model ,View , Controller

format (MVC format).

Page 23: Information About JSP ,Servlets,Struts

Struts

Struts is the most popular framework for developing Java based web applications. Struts is being developed as an open source project started by Apache Software Foundation . Struts framework is based on Model View Controller (MVC) architecture.

Page 24: Information About JSP ,Servlets,Struts

Advantages of Struts Centralized File-Based Configuration.

Rather than hard-coding information into Java programs, many Struts values are represented in XML or property files. This loose coupling means that many changes can be made without modifying or recompiling Java code, and that wholesale changes can be made by editing a single file. This approach also lets Java and Web developers focus on their specific tasks (implementing business logic, presenting certain values to clients, etc.) without needing to know about the overall system layout.

Form Beans.In JSP, you can use property="*" with jsp:setProperty to automatically populate a JavaBean component based on incoming request parameters. Unfortunately, however, in the standard API this capability is unavailable to servlets, even though with MVC it is really servlets, not JSP pages, that should usually be the target of form submissions. Apache Struts extends this capability to Java code and adds in several useful utilities, all of which serve to greatly simplify the processing of request parameters.

Bean Tags.Apache Struts provides a set of custom JSP tags (bean:write, in particular) that let you easily output the properties of JavaBeans components. Basically, these are concise and powerful variations of the standard jsp:useBean and jsp:getProperty tags.

HTML Tags.Apache Struts provides a set of custom JSP tags to create HTML forms that are associated with JavaBeans components. This bean/form association serves two useful purposes: It lets you get initial form-field values from Java objects. It lets you redisplay forms with some or all previously entered values intact.

Form Field Validation.Apache Struts has builtin capabilities for checking that form values are in the required format. If values are missing or in an improper format, the form can be automatically redisplayed with error messages and with the previously entered values maintained.    This validation can be performed on the server (in Java), or both on the server and on the client (in JavaScript).

Consistent Approach.Struts encourages consistent use of MVC throughout your application.

Page 25: Information About JSP ,Servlets,Struts

Disadvantages of struts Bigger Learning Curve.

To use MVC with the standard RequestDispatcher, you need to be comfortable with the standard JSP and servlet APIs. To use MVC with Struts, you have to be comfortable with the standard JSP and servlet APIs and a large and elaborate framework that is almost equal in size to the core system. This drawback is especially significant with smaller projects, near-term deadlines, and less experienced developers; you could spend as much time learning Struts as building your actual system.

Worse Documentation.Compared to the standard servlet and JSP APIs, Struts has fewer online resources, and many first-time users find the online Apache documentation confusing and poorly organized. There are also fewer books on Apache Struts than on standard servlets and JSP.

Less Transparent.With Struts applications, there is a lot more going on behind the scenes than with normal Java-based Web applications. As a result, Struts applications are: Harder to understand Harder to benchmark and optimize

Rigid Approach.The flip side of the benefit that Struts encourages a consistent approach to MVC is that Struts makes it difficult (but by no means impossible) to use other approaches.

Page 26: Information About JSP ,Servlets,Struts

Struts Example with Beginning: Program for inserting data in

Database

Page 27: Information About JSP ,Servlets,Struts

Struts Project Name

Page 28: Information About JSP ,Servlets,Struts

Set Server

Page 29: Information About JSP ,Servlets,Struts

Add Struts Framework

Page 30: Information About JSP ,Servlets,Struts

These things get automatically added when I click finish button

Page 31: Information About JSP ,Servlets,Struts

These things are added by me.

IN THE WEBPAGES FOLDER Insertbook.jsp Insertsuccess.jsp Error.jsp IN THE com.myapp.struts Bookaction.java Bookactionform.java IN THE LIBRARY Sqljdbc.jar

Page 32: Information About JSP ,Servlets,Struts

#Insertbook.jsp

Page 33: Information About JSP ,Servlets,Struts

#Insertsuccess.jsp

Page 34: Information About JSP ,Servlets,Struts

#error.jsp

Page 35: Information About JSP ,Servlets,Struts

For creating bookaction.java

Page 36: Information About JSP ,Servlets,Struts

For creating bookaction.java

Page 37: Information About JSP ,Servlets,Struts

For creating bookaction.java

Page 38: Information About JSP ,Servlets,Struts

#bookaction.java

Page 39: Information About JSP ,Servlets,Struts

#bookaction.java

Page 40: Information About JSP ,Servlets,Struts

#bookaction.java

Page 41: Information About JSP ,Servlets,Struts

#bookaction.java

Page 42: Information About JSP ,Servlets,Struts

I made database login in the SQL Server Management Studio where I

made rows and columns for the insertion

Page 43: Information About JSP ,Servlets,Struts

#bookactionform.java

Page 44: Information About JSP ,Servlets,Struts

#bookactionform.java(for creating bookactionform(Strutsactionfrom) we have to follow same procedure like bookaction(Strutsaction))

Page 45: Information About JSP ,Servlets,Struts

#bookactionform.java

Page 46: Information About JSP ,Servlets,Struts

#bookactionform.java

Page 47: Information About JSP ,Servlets,Struts

#ApplicationResource.properties

Page 48: Information About JSP ,Servlets,Struts

#struts-config.xml

Page 49: Information About JSP ,Servlets,Struts

Deploy the strutsprog

Page 50: Information About JSP ,Servlets,Struts

Output

Page 51: Information About JSP ,Servlets,Struts

Output

Page 52: Information About JSP ,Servlets,Struts

Checking the insertion in the Database

Page 53: Information About JSP ,Servlets,Struts

Conclusion

In JSP I show that how we do backend coding or how to make business logic which is not possible in simple html page.

In Servlet I show similar type of coding which is performed by me in jsp pages. I do coding inside the processrequest which contain both method of doget and dopost.

In the Struts I show how to add validation in the jsp page(or any view page).And how to connect these pages to the Database that in my project I connect Insertbook.jsp page to the Database Login.

Page 54: Information About JSP ,Servlets,Struts

THANK-YOU