1. Trang chủ
  2. » Công Nghệ Thông Tin

Struts 2 0 tutorial

107 177 0

Đang tải... (xem toàn văn)

Tài liệu hạn chế xem trước, để xem đầy đủ mời bạn chọn Tải xuống

THÔNG TIN TÀI LIỆU

Apache Struts 2 is an elegant, extensible framework for creating enterpriseready Java web applications. The framework is designed to streamline the full development cycle, from building, to deploying, to maintaining applications over time. Apache Struts 2 was originally known as WebWork 2. This tutorial will teach you how to use Apache Struts for creating enterpriseready Java web applications in simple and easy steps.

Presented By: Prof Vinod Pillai (M) 9909023599 vinodvpillai@hotmail.com http://vinodthebest.wordpress.com Agenda  Part – I : Understanding Struts  Introduction  Jakarta Struts  Struts Architecture  Part – II : Setting Up Struts  Getting required Packages  “Welcome to Struts 2” – Application  Part – III : Application Development  10 Applications using Struts Prof Vinod Pillai Part – I Understanding Struts Prof Vinod Pillai Introduction  Java Application = Desktop || Web || Mobile  Struts = Apache Struts Web Framework  Framework:  Peace of Software that Automates all tedious task  Use Design patterns commonly agreed by Industry  In built features that commonly needed by most of project Prof Vinod Pillai Jakarta Struts  The Apache Struts web framework is a free open- source solution for creating Java web applications  Apache Struts was launched in May 2000, with version 1.0 officially released in July 2001  Why we need it?  Web applications based on JSP sometimes combines database code, page design code, and control flow code  In practice, we find that unless these concerns are separated, larger applications become difficult to maintain Prof Vinod Pillai Jakarta Struts  One way to separate concerns in a software application => architecture  MVC Model-View-Controller (MVC)  Model = Business or database code  View = Page design code  Controller = Navigational code  Struts framework is designed to help developers create web applications that utilize a MVC architecture Prof Vinod Pillai Model View Controller (MVC) Prof Vinod Pillai Struts  Apache Struts Project offers two major versions:  Struts is recognized as the most popular web application framework for Java  Struts was originally known as WebWork 2.WebWork and Struts communities joined forces to create Struts  Struts is a pull-MVC framework i.e the data that is to be displayed to user has to be pulled from the Action  Action class in Struts act as the model in the web application  Unlike Struts, Struts Action class are plain POJO objects thus simplifying the testing of the code Prof Vinod Pillai Struts  Struts2 also comes with power APIs to configure Interceptors that reduce greatly the coupling in application  The view part of Struts is highly configurable and it supports different result-types such as Velocity, FreeMarker, JSP, etc Prof Vinod Pillai Struts Architecture Prof Vinod Pillai 10 10 “Database – Insert + Validation + View + Update” Our Goal :  To create a Struts2 Final application in we will provide user two options:  First : Allow to create a New Account and the data will entered to Database  Second : Allow user to login into the system and view his details + Update his details  Major features:  Database connectivity  HttpServletRequest  Session Prof Vinod Pillai 93 Database Output: Prof Vinod Pillai 94 Final Structure : Prof Vinod Pillai 95 Index.jsp : Prof Vinod Pillai 96 Struts.xml : Prof Vinod Pillai 97 Login Action : Prof Vinod Pillai 98 Login Action : Prof Vinod Pillai 99 Login Action : Prof Vinod Pillai 100 UserClass.java / POJO /Bean: Prof Vinod Pillai 101 EditUser.jsp : Prof Vinod Pillai 102 UpdateUserAction.java : Prof Vinod Pillai 103 UpdateUserAction.java : Prof Vinod Pillai 104 Conclusion:  What is Framework? & MVC  Struts Architecture  Setting Up Struts  Welcome Struts – Application  Action – POJO  Multiple Execute method in Action Class  Major Form Fields  Validation using validate() & xml File  Tiles Plug-in  Request & Session Object  Database Prof Vinod Pillai 105 Real Struts Architecture Prof Vinod Pillai 106 Thank You vinodvpillai@hotmail.com Prof Vinod Pillai 107 [...]... Struts Prof Vinod Pillai 20 1 “Welcome to Apache Struts 2 Our Goal :  Our goal is to create a basic Struts2 application with a Submit Button  User will click on the button and the page will be redirected to a Welcome page which will display message “Welcome to Apache Struts 2 Prof Vinod Pillai 21 Getting Started  Start Eclipse and enter the workspace name: Prof Vinod Pillai 22  Open Eclipse and go... http://tomcat.apache.org/download- 70. cgi Prof Vinod Pillai 16 Apache Struts 2 http:/ /struts. apache.org/download.cgi Prof Vinod Pillai 17 MySQL http://dev.mysql.com/downloads/ Prof Vinod Pillai 18 Setting Up Struts  JDK 1.7 = exe  Eclipse Java EE IDE = zip  Tomcat 7 = zip  Apache Struts- 2. 0. 6 JAR = zip  MySQL Database = exe Simply Install the software & make sure you remember the path Prof Vinod Pillai 19 Setting Up Struts. .. ]:  index.jsp  /WEB-INF/Welcome.jsp  /WEB-INF/Error.jsp Prof Vinod Pillai 28 index.jsp Prof Vinod Pillai 29 Welcome.jsp Error.jsp Prof Vinod Pillai 30 struts. xml  Struts2 reads the configuration and class definition from an xml file called struts. xml This file is loaded from the classpath of the project We will define struts. xml file in the source/src folder Prof Vinod Pillai 31 The Action Class... Project in the New Project wizard screen Prof Vinod Pillai 23  Project Name: Welcome Struts Target runtime: & show the path where you have unzipped the Tomcat Server Dynamic web module version: 2. 5 Prof Vinod Pillai 24  Copy JAR files in WebContent -> WEB-INF -> lib folder Prof Vinod Pillai 25  The entry point of Struts2 application will be the Filter define in deployment descriptor... is returned to the user Prof Vinod Pillai 11 Part – II Setting Up Struts Prof Vinod Pillai 12 Setting Up Struts *Before we start we need the following tools:  JDK 1.7 (Download)  Eclipse Java EE IDE for Web Developers (Indigo)  Tomcat 7 or any other container (Glassfish, JBoss, Websphere, Weblogic etc) (Download)  Apache Struts- 2. 0. 6 JAR (Download)  MySQL Database  MySQL Query Browser  MySQL... be the Filter define in deployment descriptor (web.xml) Hence we will define an entry of org.apache .struts2 .dispatcher.ng.filter.StrutsPrepareAndExe cuteFilter class in web.xml  Open web.xml file which is under WEB-INF folder and copy paste following code Prof Vinod Pillai 26 web.xml Prof Vinod Pillai 27 The JSP  We will create two JSP files to render the output to user  And we need index.jsp will.. .Struts 2 Architecture 1 2 3 4 5 Request is generated by user and sent to Servlet container Servlet container invokes FilterDispatcher filter which in turn determines appropriate action One by one Intercetors are applied... change it to system installed browser then:  Select Window -> Web Browser -> Firefox Prof Vinod Pillai 33 Part – III Application Development Prof Vinod Pillai 34 2 “Action & Form – Name & Last name – Display.” Our Goal :  To create a Struts2 application with a index page User will enter his First Name & Last Name and it will be redirected to a Welcome page which will display & ... Vinod Pillai 31 The Action Class  We will need an Action class that will accept the request and return success For this we will create a package com.vinod .struts in the source folder/src This package will contain the action file Prof Vinod Pillai 32 Run the Application:  To run the project, right click on Project name from Project Explorer and select Run as -> Run on Server Note:  In Eclipse if you

Ngày đăng: 25/05/2016, 16:58

Xem thêm: Struts 2 0 tutorial

TỪ KHÓA LIÊN QUAN

TÀI LIỆU CÙNG NGƯỜI DÙNG

  • Đang cập nhật ...

TÀI LIỆU LIÊN QUAN