Java Web Programming [7/9] : Struts2 Basics
-
Upload
imc-institute -
Category
Technology
-
view
584 -
download
3
description
Transcript of Java Web Programming [7/9] : Struts2 Basics
Module 7: Struts 2 Basics
Thanisa Kruawaisayawan
Thanachart Numnonda
www.imcinstitute.com
2
Apache Struts
Struts is an open source Web application framework developed as Apache Jakarta project http://jakarta.apache.org/struts/
Model-View-Controller (MVC) framework Used for constructing web applications based Servlets
and JSP technologiesStruts application is a genuine Web application that should
be able to run on any Servlet container including all Java EE compliant App servers
3
Why Struts?
Takes much of the complexity out of building your own MVC framework
Encourages good design practice and modeling Easy to learn and use Feature-rich and many supported 3rd-party tools Flexible and extensible Large user community Stable and mature Open source
4
How Struts 2 Works
5
Our Goal
6
Steps
1. Write JSP pages (View)
2. Write Action class (Model)
3. Forward at either success or error through configuration set in struts.xml
4. Build, deploy, and test the application
7
Step 1: Write JSP pages Step 1: Write JSP pages
8
JSP Pages
Write one JSP page for each view Use Struts tags for
Handing HTML input formsWriting out messages
9
login.jsp
10
welcome.jsp
11
Step 2: Write Step 2: Write Action classesAction classes
12
Action Class
Extend com.opensymphony.xwork2.ActionSupport class
Decide set of properties that reflect the input form Write getter and setter methods for each property Write execute() method
13
LoginAction.java
14
Step 3: Config Step 3: Config struts.xmlstruts.xml
15
struts.xml Identify required Action's and then define them as
<action> elements
16
Step 5: Build, Deploy,Step 5: Build, Deploy,and Test Application and Test Application
17
Results
18
Acknowledgement
Most contents are borrowed from the presentation slides of Sang Shin, Java™ Technology Evangelist, Sun Microsystems, Inc.