struts 2 tutorial
DESCRIPTION
Struts 2 Tutorial with Examples.TRANSCRIPT
![Page 1: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/1.jpg)
Presented By: Prof. Vinod Pillai.
(M) 9909023599
http://vinodthebest.wordpress.com
![Page 2: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/2.jpg)
Agenda Part – I : Understanding Struts.
Introduction.
Jakarta Struts.
Struts 2 Architecture.
Part – II : Setting Up Struts.
Getting required Packages.
“Welcome to Struts 2” – Application.
Part – III : Application Development.
10 Applications using Struts 2.
2Prof. Vinod Pillai
![Page 3: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/3.jpg)
Part – IUnderstanding
Struts3Prof. Vinod Pillai
![Page 4: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/4.jpg)
Introduction Java Application = Desktop || Web || Mobile.
Struts = Apache Struts Web Framework.
Framework:
Peace of Software that Automates all tedioustask.
Use Design patterns commonly agreed byIndustry.
In built features that commonly needed by mostof project.
4Prof. Vinod Pillai
![Page 5: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/5.jpg)
Jakarta Struts The Apache Struts web framework is a free open-
source solution for creating Java web applications.
Apache Struts was launched in May 2000, withversion 1.0 officially released in July 2001.
Why we need it?
Web applications based on JSP sometimes combinesdatabase code, page design code, and control flow code.
In practice, we find that unless these concerns areseparated, larger applications become difficult tomaintain.
5Prof. Vinod Pillai
![Page 6: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/6.jpg)
Jakarta Struts One way to separate concerns in a software
application => Model-View-Controller (MVC)architecture.
MVC
Model = Business or database code
View = Page design code
Controller = Navigational code.
Struts framework is designed to help developerscreate web applications that utilize a MVCarchitecture.
6Prof. Vinod Pillai
![Page 7: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/7.jpg)
Model View Controller (MVC)
7Prof. Vinod Pillai
![Page 8: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/8.jpg)
Struts 2 Apache Struts Project offers two major versions:
Struts 1 is recognized as the most popular web applicationframework for Java.
Struts 2 was originally known as WebWork 2.WebWorkand Struts communities joined forces to create Struts 2.
Struts 2 is a pull-MVC framework. i.e. the data that is tobe displayed to user has to be pulled from the Action.
Action class in Struts 2 act as the model in the webapplication.
Unlike Struts, Struts 2 Action class are plain POJOobjects thus simplifying the testing of the code.
8Prof. Vinod Pillai
![Page 9: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/9.jpg)
Struts 2 Struts2 also comes with power APIs to configure
Interceptors that reduce greatly the coupling inapplication.
The view part of Struts 2 is highly configurable and itsupports different result-types such as Velocity,FreeMarker, JSP, etc.
9Prof. Vinod Pillai
![Page 10: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/10.jpg)
Struts 2 Architecture
10Prof. Vinod Pillai
![Page 11: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/11.jpg)
Struts 2 Architecture1. Request is generated by user and sent to Servlet
container.
2. Servlet container invokes FilterDispatcher filter which inturn determines appropriate action.
3. One by one Intercetors are applied before calling theAction. Interceptors performs tasks such as Logging,Validation, File Upload, Double-submit guard etc.
4. Action is executed and the Result is generated byAction.
5. The output of Action is rendered in the view (JSP,Velocity, etc) and the result is returned to the user.
11Prof. Vinod Pillai
![Page 12: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/12.jpg)
Part – II
Setting Up Struts
12Prof. Vinod Pillai
![Page 13: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/13.jpg)
Setting Up Struts*Before we start we need the following tools:
JDK 1.7 (Download)
Eclipse Java EE IDE for Web Developers (Indigo)
Tomcat 7 or any other container (Glassfish, JBoss,Websphere, Weblogic etc) (Download)
Apache Struts-2.0.6 JAR (Download)
MySQL Database.
MySQL Query Browser.
MySQL Java JAR File – Database connectivity.
13Prof. Vinod Pillai
![Page 14: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/14.jpg)
JDK 1.7
http://www.oracle.com/technetwork/java/javase/downloads/index.html 14Prof. Vinod Pillai
![Page 15: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/15.jpg)
Eclipse Java EE IDE
http://eclipse.org/downloads/ 15Prof. Vinod Pillai
![Page 16: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/16.jpg)
Apache Tomcat 7
http://tomcat.apache.org/download-70.cgi 16Prof. Vinod Pillai
![Page 17: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/17.jpg)
Apache Struts 2
http://struts.apache.org/download.cgi 17Prof. Vinod Pillai
![Page 18: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/18.jpg)
MySQL
http://dev.mysql.com/downloads/ 18Prof. Vinod Pillai
![Page 19: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/19.jpg)
Setting Up Struts
JDK 1.7 = .exe
Eclipse Java EE IDE = zip
Tomcat 7 = zip
Apache Struts-2.0.6 JAR = zip
MySQL Database = .exe
Simply Install the software & make sure you remember thepath.
19Prof. Vinod Pillai
![Page 20: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/20.jpg)
Setting Up Struts
20Prof. Vinod Pillai
![Page 21: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/21.jpg)
1“Welcome to Apache Struts 2”
Our Goal :
Our goal is to create a basic Struts2 application with a Submit Button.
User will click on the button and the page will be redirected to a Welcome page which will display message “Welcome to Apache Struts 2”.
21Prof. Vinod Pillai
![Page 22: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/22.jpg)
Getting Started
Start Eclipse and enter the workspace name:
22Prof. Vinod Pillai
![Page 23: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/23.jpg)
Open Eclipse and go to File -> New -> Project and selectDynamic Web Project in the New Project wizard screen.
23Prof. Vinod Pillai
![Page 24: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/24.jpg)
Project Name: Welcome Struts. Target runtime: <Select New Runtime> & show the path where you have unzipped the Tomcat Server. Dynamic web module version: 2.5.
24Prof. Vinod Pillai
![Page 25: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/25.jpg)
Copy JAR files in WebContent -> WEB-INF -> lib folder.
25Prof. Vinod Pillai
![Page 26: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/26.jpg)
The entry point of Struts2 application will be the Filterdefine in deployment descriptor (web.xml). Hence we willdefine an entry oforg.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter class in web.xml.
Open web.xml file which is under WEB-INF folder and copypaste following code.
26Prof. Vinod Pillai
![Page 27: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/27.jpg)
web.xml
27Prof. Vinod Pillai
![Page 28: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/28.jpg)
The JSP
We will create two JSP files to render the output to user.
And we need index.jsp will be the starting point of our application which will contain a simple form with Button.
On clicking it will be redirected to Welcome.jsp which will display a simple welcome message.
Create three JSP files [WebContent folder ]:
index.jsp
/WEB-INF/Welcome.jsp
/WEB-INF/Error.jsp
28Prof. Vinod Pillai
![Page 29: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/29.jpg)
index.jsp
29Prof. Vinod Pillai
![Page 30: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/30.jpg)
Welcome.jsp
Error.jsp
30Prof. Vinod Pillai
![Page 31: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/31.jpg)
struts.xml
Struts2 reads the configuration and class definition from an xml file called struts.xml. This file is loaded from the classpath of the project. We will define struts.xml file in the source/src folder.
31Prof. Vinod Pillai
![Page 32: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/32.jpg)
The Action Class
We will need an Action class that will accept the requestand return success. For this we will create a packagecom.vinod.struts in the source folder/src. This package willcontain the action file.
32Prof. Vinod Pillai
![Page 33: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/33.jpg)
Run the Application:
To run the project, right click on Project name from Project Explorer and select Run as -> Run on Server.
Note:
In Eclipse if you run the Web Application it will run inside the Eclipse inside Web Browser if you would like to change it to system installed browser then:
Select Window -> Web Browser -> Firefox.
33Prof. Vinod Pillai
![Page 34: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/34.jpg)
Part – III
Application Development
34Prof. Vinod Pillai
![Page 35: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/35.jpg)
2“Action & Form – Name & Last name –
Display.”Our Goal :
To create a Struts2 application with a index page. User will enter his First Name & Last Name and it will be redirected to a Welcome page which will display <First Name> & <Last Name>.
35Prof. Vinod Pillai
![Page 36: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/36.jpg)
Final Structure:
36Prof. Vinod Pillai
![Page 37: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/37.jpg)
index.jsp
37Prof. Vinod Pillai
![Page 38: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/38.jpg)
struts.xml
38Prof. Vinod Pillai
![Page 39: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/39.jpg)
Action Class
39Prof. Vinod Pillai
![Page 40: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/40.jpg)
Welcome.jsp
40Prof. Vinod Pillai
![Page 41: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/41.jpg)
Note: [Most Important Flow]
Request is generated by user and sent to Servlet container.
Servlet container invokes FilterDispatcher filter which in turn determines appropriate action.
One by one Intercetors are applied before calling the Action.
Action is executed and the Result is generated by Action.
The output of Action is rendered in the view (JSP, Velocity, etc) and the result is returned to the user.
41Prof. Vinod Pillai
![Page 42: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/42.jpg)
3“Action Class (POJO/Plain Old Java Object)
& Form”Our Goal :
To create a Struts2 application with an index page. User willenter his First Name, Last Name and Address and it will beredirected to a Welcome page which will display <Name><Last Name> & <Address>.
Same as the above application only change is here thatAction Class is a POJO Class.
Other all same only change in Action Class.
42Prof. Vinod Pillai
![Page 43: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/43.jpg)
Final Structure:
43Prof. Vinod Pillai
![Page 44: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/44.jpg)
Action Class:
44Prof. Vinod Pillai
![Page 45: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/45.jpg)
Note:
Here the action class doesn't extend any other class orinterface. The method invoked in the processing of an actionis the "execute" method.
How this happened?
All actions may implement this interface, which exposes theexecute() method.
You are free to create POJOs that maintains the samecontract defined by this interface without actuallyimplementing the interface.
45Prof. Vinod Pillai
![Page 46: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/46.jpg)
Note:
46Prof. Vinod Pillai
![Page 47: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/47.jpg)
Note:
47Prof. Vinod Pillai
![Page 48: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/48.jpg)
Interceptors Interceptors are one of the most powerful features
of Struts 2.
As Interceptor, as the name suggests, intercepts therequest, and provides some additional processingbefore and after the execution of action and result.
Common functionalities required by each action areimplemented as Interceptors.
These functionalities may include validation ofinput data, pre-processing of file upload, andsometimes pre-processing of controls with somedata before the web page appears, etc.
48Prof. Vinod Pillai
![Page 49: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/49.jpg)
Interceptors The interceptor approach helps in modularizing
common code into reusable classes.
The framework provides a set of Interceptors, whichcan be used to provide the required functionalitiesto an action.
User can create his custom interceptors, to get thefunctionality required for each action.
49Prof. Vinod Pillai
![Page 50: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/50.jpg)
Interceptors Observe that in the figure the Action class is
executed, then a request passes through the set ofInterceptors which provide request pre-processingwhich is required before the action is executed.
Similarly after the execution of Action class allInterceptors are executed once more to providepost-processing if any.
But this time the execution order of Interceptors isreversed.
50Prof. Vinod Pillai
![Page 51: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/51.jpg)
Interceptors Creating Custom Interceptor : [Two Ways]
Implementing Interceptor Interface.
Extending AbstractInterceptor Class.
Configuring Interceptors:
51Prof. Vinod Pillai
![Page 52: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/52.jpg)
4“Interceptors”
Our Goal :
To create a Struts2 application with an index page. Userclicks the submit button before passing the request toAction it will be send to Interceptor then it will go to Actionand finally before showing the result it will send toInterceptor and then to Welcome.jsp/result.
52Prof. Vinod Pillai
![Page 53: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/53.jpg)
Final Structure:
53Prof. Vinod Pillai
![Page 54: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/54.jpg)
Interceptor Class:
54Prof. Vinod Pillai
![Page 55: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/55.jpg)
Struts.xml:
55Prof. Vinod Pillai
![Page 56: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/56.jpg)
Output:
56Prof. Vinod Pillai
![Page 57: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/57.jpg)
Note:
With most web applications, we find ourselves wanting toapply the same set of Interceptors over and over again.Rather than reiterate the same list of Interceptors, we canbundle these Interceptors together using an InterceptorStack.
57Prof. Vinod Pillai
![Page 58: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/58.jpg)
5“Common Action Class – Multiple Execute
Method ”Our Goal :
To create a Struts2 application with an index page. When theuser clicks the Update or Insert Button both goes to sameAction Class but different execute for each button.
58Prof. Vinod Pillai
![Page 59: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/59.jpg)
Final Structure:
59Prof. Vinod Pillai
![Page 60: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/60.jpg)
Index.jsp:
60Prof. Vinod Pillai
![Page 61: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/61.jpg)
Struts.xml:
61Prof. Vinod Pillai
![Page 62: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/62.jpg)
Action Class :
62Prof. Vinod Pillai
![Page 63: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/63.jpg)
Insert.jsp:
63Prof. Vinod Pillai
![Page 64: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/64.jpg)
Update.jsp:
64Prof. Vinod Pillai
![Page 65: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/65.jpg)
Output:
65Prof. Vinod Pillai
![Page 66: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/66.jpg)
Output:
66Prof. Vinod Pillai
![Page 67: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/67.jpg)
6“Validation – Using validate () Method & XML”
Our Goal :
To create a Struts2 application with an index page. If userclicks the Login Button without entering the Username orPassword then it should display message appropriately errormessage.
67Prof. Vinod Pillai
![Page 68: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/68.jpg)
Final Structure:
68Prof. Vinod Pillai
![Page 69: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/69.jpg)
Index.jsp:
69Prof. Vinod Pillai
![Page 70: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/70.jpg)
Struts.xml:
70Prof. Vinod Pillai
![Page 71: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/71.jpg)
Action Class:
71Prof. Vinod Pillai
![Page 72: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/72.jpg)
Welcome.jsp:
72Prof. Vinod Pillai
![Page 73: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/73.jpg)
Second Option : XML File Validation
73Prof. Vinod Pillai
![Page 74: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/74.jpg)
Final Structure:
74Prof. Vinod Pillai
![Page 75: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/75.jpg)
LoginAction-validation.xml :
75Prof. Vinod Pillai
![Page 76: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/76.jpg)
Action Class :
76Prof. Vinod Pillai
![Page 77: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/77.jpg)
7“User Form”
Our Goal :
To create a Struts2 application with an index page. If userclicks the Login Button it will redirect him to Welcome pagewhere some field values are coming from Action Classvariable & some major Form Fields.
77Prof. Vinod Pillai
![Page 78: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/78.jpg)
Action Class :
78Prof. Vinod Pillai
![Page 79: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/79.jpg)
Welcome.jsp:
79Prof. Vinod Pillai
![Page 80: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/80.jpg)
8“Integrating Tiles Plug-in”
Our Goal :
To create a Struts2 application with an index page. As userclicks the Login Button it will redirect him to Welcome pagewhich having a common design layout which will becommon for all the pages.
80Prof. Vinod Pillai
![Page 81: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/81.jpg)
Final Structure:
81Prof. Vinod Pillai
![Page 82: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/82.jpg)
Index.jsp:
82Prof. Vinod Pillai
![Page 83: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/83.jpg)
Struts.xml:
83Prof. Vinod Pillai
![Page 84: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/84.jpg)
tiles.xml:
84Prof. Vinod Pillai
![Page 85: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/85.jpg)
MainLayout.jsp:
85Prof. Vinod Pillai
![Page 86: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/86.jpg)
Header.jsp:
Menu.jsp:
86Prof. Vinod Pillai
![Page 87: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/87.jpg)
FirstPage.jsp:
SecondPage.jsp:
87Prof. Vinod Pillai
![Page 88: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/88.jpg)
8 & 9“HttpServletRequest, HttpServletResponse, ServletContext
& HttpSession”Our Goal :
Getting ServletContext Object.
Getting HttpServletRequest Object.
Getting HttpServletResponse Object.
Getting HttpSession Object.
88Prof. Vinod Pillai
![Page 89: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/89.jpg)
ApplicationAware/ServletContext:
89Prof. Vinod Pillai
![Page 90: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/90.jpg)
SessionAware/HttpSession:
90Prof. Vinod Pillai
![Page 91: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/91.jpg)
ServletRequestAware/HttpServletRequest:
91Prof. Vinod Pillai
![Page 92: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/92.jpg)
ServletResponseAware :
92Prof. Vinod Pillai
![Page 93: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/93.jpg)
10“Database – Insert + Validation + View + Update”
Our Goal :
To create a Struts2 Final application in we will provide usertwo options:
First : Allow to create a New Account and the data willentered to Database.
Second : Allow user to login into the system and view hisdetails + Update his details.
Major features:
Database connectivity.
HttpServletRequest.
Session.93Prof. Vinod Pillai
![Page 94: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/94.jpg)
Database Output:
94Prof. Vinod Pillai
![Page 95: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/95.jpg)
Final Structure :
95Prof. Vinod Pillai
![Page 96: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/96.jpg)
Index.jsp :
96Prof. Vinod Pillai
![Page 97: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/97.jpg)
Struts.xml :
97Prof. Vinod Pillai
![Page 98: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/98.jpg)
Login Action :
98Prof. Vinod Pillai
![Page 99: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/99.jpg)
Login Action :
99Prof. Vinod Pillai
![Page 100: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/100.jpg)
Login Action :
100Prof. Vinod Pillai
![Page 101: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/101.jpg)
UserClass.java / POJO /Bean:
101Prof. Vinod Pillai
![Page 102: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/102.jpg)
EditUser.jsp :
102Prof. Vinod Pillai
![Page 103: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/103.jpg)
UpdateUserAction.java :
103Prof. Vinod Pillai
![Page 104: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/104.jpg)
UpdateUserAction.java :
104Prof. Vinod Pillai
![Page 105: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/105.jpg)
Conclusion:
105Prof. Vinod Pillai
What is Framework? & MVC.
Struts Architecture.
Setting Up Struts.
Welcome Struts 2 – Application.
Action – POJO.
Multiple Execute method in Action Class.
Major Form Fields.
Validation using validate() & .xml File.
Tiles Plug-in.
Request & Session Object.
Database.
![Page 106: Struts 2 tutorial](https://reader034.vdocuments.mx/reader034/viewer/2022052301/555815acd8b42a25588b4635/html5/thumbnails/106.jpg)
Real Struts 2 Architecture
106Prof. Vinod Pillai