Introduction to Struts 2.0 - PowerPoint PPT Presentation

1 / 57
About This Presentation
Title:

Introduction to Struts 2.0

Description:

Topic for AdWeb Course ... Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv * Software School ,Fudan University – PowerPoint PPT presentation

Number of Views:185
Avg rating:3.0/5.0
Slides: 58
Provided by: Jenn105
Category:

less

Transcript and Presenter's Notes

Title: Introduction to Struts 2.0


1
Introduction to Struts 2.0
  • Jenny Ni
  • Joey Feng
  • Winddays Wang
  • Hewmmi Zhu
  • Heather Lv

2
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

3
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

4
Why use framework?
  • Do we need framework?
  • No and Yes.
  • No.
  • In small applications where you dont 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.

5
Struts 2.0
  • Complete new framework based on webwork
    framework.
  • Struts 2.0 implements MVC 2 design pattern.

6
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.

7
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

8
Request Lifecycle in Struts 2.0
  • User Sends Request
  • Filter Dispatcher determines the appropriate
    action
  • Interceptors are applied
  • Execution of action
  • Output Rendering
  • Return of Request
  • Display of result to user.

9
Struts 2.0 Architecture
10
Struts 2.0 Architecture
11
Why we should use Struts 2.0?
  • Simplified Design
  • Simplified Action
  • Simplified Testability
  • Better tag features
  • Annotation introduced
  • Easy plug-in
  • AJAX Support

12
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

13
  • Struts 1
  • Action ?
  • ActionForm ?
  • ActionForward ?
  • struts-config.xml ?
  • ActionServlet ?
  • RequestProcessor ?
  • Struts 2
  • Action
  • Action or POJOs
  • Result
  • struts.xml
  • FilterDispatcher
  • Interceptors

14
What you need to start using Struts 2.0?
  • Java 5.0
  • Tomcat 5.x(Servlet api 2.4 and jsp api 2.0)

15
Lets see something real
16
Web, Mail 2000
17
Web, Mail 2009
18
(No Transcript)
19
(No Transcript)
20
(No Transcript)
21
(No Transcript)
22
(No Transcript)
23
(No Transcript)
24
(No Transcript)
25
(No Transcript)
26
(No Transcript)
27
(No Transcript)
28
(No Transcript)
29
(No Transcript)
30
(No Transcript)
31
Struts Plugins
32
Simple Example
33
Struts 1
lthtmlerrors/gt lthtmlform action"/SaveMeeting"gt lt
table border"0" width"100"gt lttrgt ltth
align"right"gt Name lt/thgt lttd
align"left"gt lthtmltext property"name"
size50 /gt lt/tdgt lt/trgt lttrgt ltth
align"right"gt Date
34
lt/thgt lttd align"left"gt lthtmltext
property"date" size"50"/gt lt/tdgt lt/trgt lttrgt
ltth align"right"gt Invitees lt/thgt lttd
align"left"gt lthtmlselect property"invitees"
multiple"true"gt
lthtmloptions collection"employees"
property"value"
labelProperty"label"/gt lt/htmlselectgt
35
lt/trgt lttrgt ltth align"right"gt Description
lt/thgt lttd align"left"gt lthtmltextarea
property"description"
rows"4" cols"50" /gt lt/tdgt lt/trgt lttrgt lttd
align"right"gt nbsp lt/tdgt
36
lttd align"left"gt lthtmlsubmit
property"DO_SUBMIT"gt Save
lt/htmlsubmitgt lt/tdgt lt/trgt lt/tablegt lt/htmlformgt
  • ...
  • Only four pages!

37
Struts 2
ltsform action"Meeting" validate"true"gt
ltstoken /gt ltstextfield labelName
namename /gt ltstextfield labelDate"
name"date"/gt ltsselect labelInvitees
name"invitees" list"employees"/gt ltstextarea
labelDescription name"description"
rows"4" cols"50" /gt ltssubmit
valueSave" method"save"/gt lt/sformgt
38
Example Revisited
39
ltstextfield label"Name" name"name"
tooltip"Meeting name" /gt
40
ltsdatepicker label"Date" name"date"/gt
41
ltsoptiontransferselect ... /gt
42
ltjspinclude page"/ajax/commonInclude.jsp"/
gt ... ltstextarea theme"ajax" label"Description"
name"description" rows"4" cols"50" /gt
43
But there's more . . .
44
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.

45
Prevention and Cure
46
struts.devMode true
47
(No Transcript)
48
(No Transcript)
49
Built-in Testing Support
public class MyActionTest extends
StrutsTestCase public void testExecute()
throws Exception assertTrue(true)
50
any.action?debugconsole
51
any.action?profilingyes
52
Time to Upgrade?
53
Tutorials, Guides, and FAQs
54
Struts 2 Training Course
55
Run Struts 1 Actions as Is
ltaction name"editGangster"
class"org.apache.struts2.s1.Struts1Action"gt
ltparam name"className"gt com.mycompany.gangst
as.EditGangsterAction lt/paramgt ltresultgt
gangsterForm.jsp lt/resultgt lt/actiongt
56
How do I get started?
57
Where We are Going
Write a Comment
User Comments (0)
About PowerShow.com