Course Code: GCS-P125

STRUTS FRAMEWORK

CONTENTS Configuring a Struts application  The Controller  The Views  Managing Errors  Struts Validator  Internationalization  Struts JDBC Connection Pool  Struts Tools  References 

Confidential

2

Configuring a Struts application 

The Web Application Directory Structure The WEB-INF directory is where the deployment descriptor for the web application should be placed.

Confidential

3

Configuring a Struts application (cont.) 

Configuring the web.xml file for Struts Struts Blank Application action org.apache.struts.action.ActionServlet config /WEB-INF/struts-config.xml action *.do

Confidential

4

Configuring a Struts application (cont.) 

Configuring the Tag Libraries The taglib-uri element specifies a URI identifying a tab library that is used by the web application. The taglib-location element specifies the location (as a resource) of the tag library descriptor file. /tags/struts-bean /WEB-INF/struts-bean.tld /tags/struts-html /WEB-INF/struts-html.tld /tags/struts-logic /WEB-INF/struts-logic.tld /tags/struts-tiles /WEB-INF/struts-tiles.tld

Confidential

5

Configuring a Struts application (cont.) Setting up the Welcome File List index.jsp  Configuring Error Handling in web.xml 404 /common/404.jsp 500 /common/500.jsp

Confidential

6

Configuring a Struts application (cont.) 

Using the exception-type element instead of the error-code

javax.servlet.ServletException /common/system_error.jsp

Confidential

7

Configuring a Struts application (cont.) The Struts Configuration File The data-sources Element 



Confidential

8

Configuring a Struts application (cont.) The form-beans Element

The global-forwards Element

The action-mappings Element The element configures the mappings from submitted request paths to the corresponding Action classes for a particular sub-application.

Confidential

9

Configuring a Struts application (cont.) The message-resources Element The element specifies characteristics of the message resource bundles that contain the localized messages for an application. The plug-in Element

Confidential

10

Configuring a Struts application (cont.) 









Download: - Start at http://jakarta.apache.org/site/binindex.cgi or follow link from http://jakarta.apache.org/struts/ Unzip into a directory of your choice - E.g., C:\jakarta-struts-1.1 - Here after referred to as struts_install_dir Update your CLASSPATH - Add struts_install_dir/lib/struts.jar Copy the .tld files into WEB-INF, copy struts.jar (and all of the common*.jar files) into WEB-INF/lib Tomcat / JDK 1.4

Confidential

11

The Controller

Confidential

12

The Controller(cont.) 



The ActionServlet Class The org.apache.struts.action.ActionServlet acts as the primary controller for the Struts framework. All requests from the client tier must pass through this component before proceeding anywhere else in the application. The RequestProcessor Class process()method of the org.apache.struts.action.RequestProcessor is called by the ActionServlet instance and passed the current request and response objects.

Confidential

13

The Controller (cont.)

request

doGet()

call process() ActionServlet RequestProcessor.process() doPost() find FormBean and Action from strutsconfig.xml

determined target

return an ActionForward to RequestProcessor Action.execute() forward to

Confidential

ActionForm.validate()

14

The Views 

Using Views within the Struts Framework HTML Documents JSP Custom Tag Libraries JavaScript and Style Sheets Multimedia Files Message Bundles ActionForm Classes

Confidential

15

The Views (cont.) 

ActionForm

Username:
Password:


Confidential

16

The Views (cont.) import org.apache.struts.action.*; public class MyForm extends ActionForm { protected String name; protected String address; public String getName(){ return this.name; }; public String getAddress(){ return this.address; }; public void setName(String name) { this.name = name; }; public void setAddress(String address){ this.address = address; }; };

Confidential

17

The Views (cont.) public ActionErrors validate(ActionMapping actionMapping, HttpServletRequest resquest) { /** @todo: Override this org.apache.struts.action.ActionForm method*/ return super.validate(actionMapping, resquest); } 

Using in Edit Form Set the form’s data members back to their default values

public void reset(ActionMapping actionMapping, HttpServletRequest request) { /** @todo: Override this org.apache.struts.action.ActionForm method*/ super.reset(actionMapping, request); UserBean userBean = (UserBean ) request.getSession().getAttribute( " userBean"); if (userBean != null) { this.address = userBean .getAddress(); this.name = userBean .getName(); } }

Confidential

18

The Views (cont.) public String toString() { StringBuffer buf = new StringBuffer(); buf.append("address =").append(address).append(" "); buf.append(“name=").append(name).append(" "); return buf.toString(); } 

Using an ActionForm in an Action public ActionForward execute( ActionMapping mapping,ActionForm form, HttpServletRequest request, HttpServletResponse response ) throws Exception{ String address = ((UserForm)form).getAddress(); String name = ((UserForm)form).getName();

Confidential

19

Managing Errors 

ActionErrors In Action ActionErrors errors = new ActionErrors(); errors.add("propertyname", new ActionError("key"); saveErrors(request, errors); Output error messages in JSP :

Confidential

20

Managing Errors (cont.) 

In ApplicationResources

errors.header=

    Validation Error

    You must correct the following error(s) before proceeding:
    errors.prefix=
  • errors.suffix=
  • errors.footer=
errors.required={0} is required. errors.minlength={0} cannot be less than {1} characters. errors.maxlength={0} cannot be greater than {1} characters. errors.invalid={0} is invalid. errors.byte={0} must be a byte. errors.short={0} must be a short. errors.integer={0} must be an integer. errors.date={0} is not a date. errors.range={0} is not in the range {1} through {2}. errors.creditcard={0} is an invalid credit card number. errors.email={0} is an invalid e-mail address. error.session.expired=Session expired.

Confidential

21

Struts Validator 



Required Packages commons-validator.jar and jakarta-oro.jar Add validator-rules.xml ,validate.xml to struts-config.xml



Client-side validations

Confidential

22

Struts Validator (cont.) 

Client-side validations

Confidential

23

Struts Validator (cont.) 

Server-side validations public class LogonForm extends ValidatorForm {



Basic validators Declare in validation.xml
mask ^([a-zA-Z0-9])*$


Confidential

24

Struts Validator (cont.) 

Server-side validations

Confidential

25

Internationalization 

Add Message Resources into struts-config.xml
 

parameter="fr.paris.dasco.pvp.ApplicationResources"/>

ApplicationResources_xx.properties Ex: ApplicationResources_fr.properties for French ApplicationResources_ja.properties for Japannese

Using the Tag <bean:message key="app.title"/> With : app.title = Struts Ex Defined in ApplicationResources. properties 

Confidential

26

Struts JDBC connection pool What Is a DataSource? A JDBC DataSource is an object described by the JDBC 2.0 extensions package that is used to generically represent a database management system (DBMS). The DataSource is defined by the interface javax.sql.DataSource; it is described as a factory containing JDBC Connection objects. 

Confidential

27

Struts JDBC connection pool (cont.)

 Using a DataSource in Your Struts Application Add jdbc2_0−stdext.jar in lib In struts-config.xml



Confidential

28

Struts JDBC connection pool (cont.) Using in Action //import datasource import javax.sql.DataSource; import javax.servlet.ServletContext; import java.sql.Connection; ………………………… 

ServletContext context = servlet.getServletContext(); DataSource dataSource = (DataSource) context.getAttribute("jdbc/oracle_pvp"); Connection conn = dataSource.getConnection();

………………………………

Confidential

29

Struts Tools       

Camino Pro 3.1.1 (http://www.scioworks.com/) Create the struts skeleton. Convert JSPs to struts format. Generate Action and ActionForm Generate web.xml and struts-config.xml ...... Struts Studio

Confidential

30

References  

http://jakarta.apache.org/struts/ Ebook : Mastering Jakarta Struts, Struts in Action, Jakarta Struts...

Confidential

31

The end

Thank you for your attention!

Confidential

32

Configuring a Struts application (cont.)

Configuring the web.xml file for Struts. 1"?> app. PUBLIC "-//Sun Microsystems, Inc.//DTD Web ...

469KB Sizes 3 Downloads 165 Views

Recommend Documents

Area_B3_Fall2012 Cont
Oct 12, 2012 - Club. On behalf of Area B3 Governor Pau Rey, and Club. President Egon Hovnikar. VENUE:Lifeskills Development Centre. Rue du Grand ...

Cont publica normal.pdf
8 99121204378 TABOADA SIMANCA ANGIE PAOLA 4.09. 9 1098715488 TORRES LLANOS LIDAJINET STEFANI 4.08. 10 98113061880 RUIZ PERALTA ...

20111020lim-cont-der.pdf
Sign in. Loading… Whoops! There was a problem loading more pages. Retrying... Whoops! There was a problem previewing this document. Retrying.

Review CONT ISL 2013.pdf
... data atau informan dalam penelitian kualitatif, tidak boleh dicantumkan apabila dapat merugikan informan tersebut. Page 3 of 3. Review CONT ISL 2013.pdf.

Testing Struts Actions with StrutsTestCase
Set up a J2EE Web Application Project That Uses Struts . ... Configure the Action and Forward in the Struts Configuration File . . . . . . . . . . . . . . . . . . . . . . . . . . 7. Run and Test Your First .... Create the Management Feature to Edit/D

1-1 dg-Cont. Financiera.pdf
SINOPSIS. BREVE DESCRIPTOR. Introducción a los conceptos fundamentales de la Contabilidad Financiera. CONOCIMIENTOS PREVIOS RECOMENDADOS.

24-Cont Issues Bullying Asbestos.pdf
There was a problem previewing this document. Retrying... Download. Connect more apps... Try one of the apps below to open or edit this item. 24-Cont Issues Bullying Asbestos.pdf. 24-Cont Issues Bullying Asbestos.pdf. Open. Extract. Open with. Sign I

u lab 3 cont I 2017.pdf
Asiste Light, Plan Iva, Asite Libros, Reten ISR, Asiste Hospitales, Reten IVA, Reporte de Inventarios. (cada numeral es independiente). 6) Hoy 30 de junio de ...

DSS-cont-impl-2016-08-17.pdf
Loading… Page 1. Whoops! There was a problem loading more pages. Retrying... DSS-cont-impl-2016-08-17.pdf. DSS-cont-impl-2016-08-17.pdf. Open. Extract.

7.4 - Configuring GSA Mirroring
Google Search Appliance software version 7.2 and later .... The search appliance models you have determine which machine is the master and which .... configuration over a virtual private network. .... On the drop-down list, choose Replica. 6.

7.2 - Configuring GSA Unification
Users See 404 Errors After Clicking Results. 24. Results from Secondary Search Appliances are Not Available on. Primary Search Appliance. 24. Unexpected ...

7.2 - Configuring GSA Mirroring
property rights relating to the Google services are and shall remain the exclusive ... 5. About GSA Mirroring. 5. Deciding Which Mirroring Configuration to Use. 7 ... This document is for you if you are a search appliance administrator, network ...

7.0 - Configuring GSA Unification
When GSA unification is configured, personal content from the Cloud .... All security configurations on the Crawler Access pages on the secondary search ...

7.2 - Configuring GSA Unification
Google Search Appliance running software version 6.0 or later can be configured ... Search Appliance C searches its local index, which contains accounting information. .... management system and you are setting up GSA unification, you can ...

7.0 - Configuring GSA Mirroring
appliance, to provide high availability serving. .... see the section “Setting up monitoring” in the article Design a search solution (http://support.google.com/.

Configuring the after-sales service supply chain: A ...
Feb 25, 2007 - Keywords: After-sales service; Supply chain configuration; Durable consumer goods; Case study. 1. ... relationship building, after-sales service acquires a ..... management. Collaboration practice with retailers and supply chain perspe

7.4 - Configuring GSA Unification
Google Search Appliance: Configuring GSA Unification. 3. Contents ... Using the GSA Unification Network Stats and GSA Unification Diagnostic. Pages to Find ..... provider. User logs in to network domain. Credentials for authorization are.

7.0 - Configuring GSA Mirroring
Google and the Google logo are registered trademarks or service marks of ..... You must set up CA certificate use in the mirroring configuration in one of the two ...