Struts2 download, installation and development process

Source: Internet
Author: User
Tags i18n

First, Struts2 Download

Login Download Struts2 Latest Version

Recommended Download Full distribution full version, this option includes Struts2 the sample application ( Apps folder), empty sample apps, core libraries ( Lib folder), source code, and documentation ( Docs folder), etc., src folder contains Struts2 the entire source code of the framework.

Second, Struts2 installation

copy these several required class libraries to Web of the application Web-inf/lib the path. If you need more features of Struts2 in your Web app , you'll need to copy the appropriate JAR file to Web of the application Web-inf/lib the path.

Third, the development process

1. In Web. XML The file defines the core Filter to intercept user requests.

<?xml version= "1.0" encoding= "GBK"? ><web-app xmlns:xsi= "Http://" xmlns= "Http://" xmlns:web= "" xsi: schemalocation= "Http://" id= "Webapp_ ID "version=" 3.0 "><!--defines the core of the STRUTS2 filter--><filter><filter-name>struts2</filter-name ><filter-class></filter-class ></filter><!--let Struts2 's core filter intercept all requests--><filter-mapping><filter-name>struts2</ Filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>

2. If you need to POST method to submit a request, you define the data that contains the form JSP page. It is not necessary to go through this step if you simply send the request in a GET mode.

3. Define the Action class that handles user requests . For example, we do a login demo needs a loginaction

Import Com.opensymphony.xwork2.actioncontext;import Com.opensymphony.xwork2.actionsupport;public class LoginAction Extends actionsupport{//defines username and password properties that encapsulate request parameters private string Username;private string Password;public string GetUserName () {return username;} public void Setusername (String username) {this.username = username;} Public String GetPassword () {return password;} public void SetPassword (String password) {this.password = password;} Defines the Execute method that handles user requests public String execute () throws exception{//when username is,password for Leegang, the login succeeds if ( GetUserName (). Equals ("struts") && GetPassword (). Equals ("struts")) {Actioncontext.getcontext (). GetSession ( ). Put ("User", GetUserName ()); return SUCCESS;} Else{return ERROR;}}}
4. ConfigurationActionand the correspondence between the processing result and the physical view resource.

<struts><!--Specify global internationalized resource file--><constant name= "struts.custom.i18n.resources" value= "mess"/><!-- Specifies the character set used by the internationalized encoding--><constant name= "struts.i18n.encoding" value= "GBK"/><!--all action definitions should be placed under the package-- ><package name= "Lee" extends= "Struts-default" ><action name= "Login" class= " "><!--define mappings between three logical views and physical resources--><result name=" input ">/login.jsp< /result><result name= "error" >/error.jsp</result><result name= "Success" >/welcome.jsp</ Result></action></package></struts>

5. Writing View Resources


<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%><% @taglib prefix=" s "uri="/struts-tags "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://" >


<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%><% @taglib prefix=" s "uri="/struts-tags "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://" >


<%@ page language= "java" contenttype= "text/html; CHARSET=GBK "pageencoding=" GBK "%><% @taglib prefix=" s "uri="/struts-tags "%><! DOCTYPE HTML PUBLIC "-//w3c//dtd HTML 4.01 transitional//en" "Http://" >

6. Writing internationalized Resource files

Use Native2ascii Conversion Encoding







Pass=\u5bc6 \u7801



loginpage= Login Page

errorpage= error Page

succpage= Success Page

failtip= Sorry, you can't login!

succtip= Welcome, {0}, you are already logged in!

user= User name

pass= Dense Code

login= Login

Iv. Results of operation

Struts2 download, installation and development process

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.