Presentation is loading. Please wait.

Presentation is loading. Please wait.

Introduction to Struts 2.0 Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv Software School,Fudan University 1.

Similar presentations


Presentation on theme: "Introduction to Struts 2.0 Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv Software School,Fudan University 1."— Presentation transcript:

1 Introduction to Struts 2.0 Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv Software School,Fudan University 1

2 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 Contents Software School,Fudan University 2

3  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 What is Struts? Software School,Fudan University 3

4  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. Why use framework? Software School,Fudan University 4

5  Complete new framework based on webwork framework.  Struts 2.0 implements MVC 2 design pattern. Struts 2.0 Software School,Fudan University 5

6  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. Struts 2.0 MVC Components Software School,Fudan University 6

7  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 Struts 2.0 MVC Components contd. Software School,Fudan University 7

8 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. Request Lifecycle in Struts 2.0 Software School,Fudan University 8

9 Struts 2.0 Architecture

10 Software School,Fudan University 10

11 1. Simplified Design 2. Simplified Action 3. Simplified Testability 4. Better tag features 5. Annotation introduced 6. Easy plug-in 7. AJAX Support Why we should use Struts 2.0? Software School,Fudan University 11

12  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 Struts 1.x vs Struts 2.0 Software School,Fudan University 12

13 Struts 1 Action  ActionForm  ActionForward  struts-config.xml  ActionServlet  RequestProcessor  Struts 2 Action Action or POJO’s Result struts.xml FilterDispatcher Interceptors

14 1. Java 5.0 2. Tomcat 5.x(Servlet api 2.4 and jsp api 2.0) What you need to start using Struts 2.0? Software School,Fudan University 14

15 Let’s see something real… Software School,Fudan University 15

16 Web, Mail 2000

17 Web, Mail 2009

18

19

20

21

22

23

24

25

26

27

28

29

30

31 Struts Plugins

32 Simple Example

33 Name: Date: Struts 1

34 Invitees: <html:select property="invitees" multiple="true"> <html:options collection="employees" property="value" labelProperty="label"/>

35 Description: <html:textarea property="description" rows="4" cols="50" />

36 ...  Only four pages! Save

37 <s:textarea label=”Description” name="description" rows="4" cols="50" /> Struts 2

38 Example Revisited

39 <s:textfield label="Name" name="name" tooltip="Meeting name" />

40

41

42 <jsp:include page="/ajax/commonInclude.jsp"/>... <s:textarea theme="ajax" label="Description" name="description" rows="4" cols="50" />

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

48

49 Built-in Testing Support public class MyActionTest extends StrutsTestCase { public void testExecute() throws Exception { assertTrue(true); }

50 any.action?debug=console

51 any.action?profiling=yes

52 Time to Upgrade?

53 Tutorials, Guides, and FAQs

54 Struts 2 Training Course

55 <action name="editGangster" class="org.apache.struts2.s1.Struts1Action"> com.mycompany.gangstas.EditGangsterAction gangsterForm.jsp Run Struts 1 Actions as Is

56 How do I get started?

57 Where We are Going


Download ppt "Introduction to Struts 2.0 Jenny Ni Joey Feng Winddays Wang Hewmmi Zhu Heather Lv Software School,Fudan University 1."

Similar presentations


Ads by Google