Module 7: Struts 2 Basics Thanisa Kruawaisayawan Thanachart Numnonda www.imcinstitute.com
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 technologies  Strutsapplication is a genuine Web application that should be able to run on any Servlet container including all Java EE compliant App servers 2
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 3
How Struts 2 Works 4
Our Goal 5
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 6
Step 1: Write JSP pages 7
JSP Pages  Write one JSP page for each view  Use Struts tags for  Handing HTML input forms  Writing out messages 8
login.jsp 9
welcome.jsp 10
Step 2: Write Action classes 11
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 12
LoginAction.java 13
Step 3: Config struts.xml 14
struts.xml  Identify required Action's and then define them as <action> elements 15
Step 5: Build, Deploy, and Test Application 16
Results 17
Acknowledgement Most contents are borrowed from the presentation slides of Sang Shin, Java™ Technology Evangelist, Sun Microsystems, Inc. 18
Thank you thananum@gmail.com www.facebook.com/imcinstitute www.imcinstitute.com 19

Java Web Programming [7/9] : Struts2 Basics

  • 1.
    Module 7: Struts2 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 technologies  Strutsapplication is a genuine Web application that should be able to run on any Servlet container including all Java EE compliant App servers 2
  • 3.
    Why Struts?  Takesmuch 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 3
  • 4.
    How Struts 2Works 4
  • 5.
  • 6.
    Steps 1. Write JSPpages (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 6
  • 7.
    Step 1: WriteJSP pages 7
  • 8.
    JSP Pages  Writeone JSP page for each view  Use Struts tags for  Handing HTML input forms  Writing out messages 8
  • 9.
  • 10.
  • 11.
  • 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 12
  • 13.
  • 14.
    Step 3: Config struts.xml 14
  • 15.
    struts.xml  Identify required Action's and then define them as <action> elements 15
  • 16.
    Step 5: Build,Deploy, and Test Application 16
  • 17.
  • 18.
    Acknowledgement Most contentsare borrowed from the presentation slides of Sang Shin, Java™ Technology Evangelist, Sun Microsystems, Inc. 18
  • 19.
    Thank you thananum@gmail.com www.facebook.com/imcinstitute www.imcinstitute.com 19