Embed
Email

Struts 2

Document Sample

Shared by: yaoyufang
Categories
Tags
Stats
views:
3
posted:
1/31/2012
language:
pages:
57
Introduction to Struts 2.0

Jenny Ni

Joey Feng

Winddays Wang

Hewmmi Zhu

Heather Lv









1

Software School ,Fudan University

Contents

1. What is Struts?

2. Why to use framework?

3. Struts 2.0 Overview

4. Struts 2.0 MVC components

5. Request Lifecycle in Struts 2

6. Struts 2.0 Architecture

7. Sample Application

8. Why we should use Struts 2.0?

9. Struts 1.x vs Struts 2.0

10. What you need to start using Struts2.0



Software School ,Fudan University 2

What is Struts?

 Open Source java framework for

creating web applications.

 Action Based Framework

 Create web application using MVC 2

architecture

 Apache Struts offer two major version

Struts 1.x

Struts 2.0

 Struts 2 = WebWork + Struts



Software School ,Fudan University 3

Why use framework?

 Do we need framework?

 No and Yes.

 No.

 In small applications where you don’t want

the overhead of learning new things.

 But

 Yes

 We have to use framework in real world

application because:-

 Automation of common tasks

 Concentrate on higher level concerns.



Software School ,Fudan University 4

Struts 2.0

 Complete new framework based on webwork framework.

 Struts 2.0 implements MVC 2 design pattern.









Software School ,Fudan University 5

Struts 2.0 MVC Components

 Controller:-

 Filter Dispatcher:-

 First component that start processing that is why this type

of MVC is called front controller MVC

 Looks at the request and apply the appropriate action.

 Struts framework handles all of the controller work.

 Its configured in web.xml



 Interceptors:-

 Can execute code before and after an Action is

executed.

 They can be configured per action basis.

 Can be used for data validation, file upload, double

submit guards.





Software School ,Fudan University 6

Struts 2.0 MVC Components contd.



 Model:-

 Implemented by action class

 For model you can use any data access

technologies like JDBC,EJB,Hibernate





 View

 Its your result part. It can be JSP,JSTL,JSF etc.

 Presentation part of the MVC









Software School ,Fudan University 7

Request Lifecycle in Struts 2.0

1. User Sends Request

2. Filter Dispatcher determines the appropriate action

3. Interceptors are applied

4. Execution of action

5. Output Rendering

6. Return of Request

7. Display of result to user.









Software School ,Fudan University 8

Struts 2.0 Architecture

Struts 2.0 Architecture









Software School ,Fudan University 10

Why we should use Struts 2.0?

1. Simplified Design

2. Simplified Action

3. Simplified Testability

4. Better tag features

5. Annotation introduced

6. Easy plug-in

7. AJAX Support







Software School ,Fudan University 11

Struts 1.x vs Struts 2.0

 How Struts 1.x and Struts 2.0 differ from each

other?

› Configuration

› Action Class

› Dependency injection.

› Servlet Dependency

› Validation

› Threading model

› Testability

› Expression Language



Software School ,Fudan University 12

Struts 1 Struts 2

Action  Action

ActionForm  Action or POJO’s

ActionForward  Result

struts-config.xml  struts.xml

ActionServlet  FilterDispatcher

RequestProcessor  Interceptors

What you need to start using

Struts 2.0?

1. Java 5.0

2. Tomcat 5.x(Servlet api 2.4 and jsp api

2.0)









Software School ,Fudan University 14

Let’s see something real…









Software School ,Fudan University 15

Web, Mail 2000

Web, Mail 2009

Struts Plugins

Simple Example

Struts 1











Name:















Date:















Invitees:

















Description:















 







Save















 ...







 Only four pages!

Struts 2

















Example Revisited









...



But there's more . . .

Brian Kernighan Law of

Debugging Difficulty



Debugging is twice as hard as writing the

code in the first place. Therefore, if you

write the code as cleverly as possible, you

are, by definition, not smart enough to

debug it.

Prevention and Cure

struts.devMode = true

Built-in Testing Support



public class MyActionTest

extends StrutsTestCase {



public void testExecute()

throws Exception {



assertTrue(true);

}

}

any.action?debug=console

any.action?profiling=yes

Time to Upgrade?

Tutorials, Guides, and

FAQs

Struts 2 Training Course

Run Struts 1 Actions as Is





com.mycompany.gangstas.EditGangsterAction





gangsterForm.jsp





How do I get

started?

Where We are Going



Related docs
Other docs by yaoyufang
MS SBE Brochure
Views: 0  |  Downloads: 0
MERCIES OF DAVID
Views: 0  |  Downloads: 0
EPP_Orientation
Views: 0  |  Downloads: 0
ul rates reduced 6-4-10
Views: 0  |  Downloads: 0
TITLE OF THE TERM PAPER
Views: 1  |  Downloads: 0
Saint-Sa雗s_-_L_ancetre__vocal_score_
Views: 0  |  Downloads: 0
DECISION
Views: 0  |  Downloads: 0
LARP 702 Gungywamp
Views: 0  |  Downloads: 0
By registering with docstoc.com you agree to our
privacy policy

You are almost ready to download!

You are almost ready to download!