Struts-global configuration

Source: Internet
Author: User

1. Create a struts WEB Project
Project name: struts2101407
2. Add struts2 support to the Project
Commons-fileupload-1.3.jar
Commons-io-2.0.1.jar
Commons-lang3-3.1.jar
Freemarker-2.3.19.jar
Javassist-3.11.0.GA.jar
Ognl-3.0.6.jar
Struts2-core-2.3.15.1.jar
Xwork-core-2.3.15.1.jar
3. Add the struts2 core configuration file
1. Create the conf directory in the project
2. Create a core configuration file in the conf directory
Core configuration file name: struts. xml
Core configuration file content:
<? XML version = "1.0" encoding = "UTF-8"?>
<! Doctype struts public
"-// Apache Software Foundation // DTD struts configuration 2.3 // en"
Http://struts.apache.org/dtds/struts-2.3.dtd>
<Struts>
</Struts>
4. Configure the struts core filter in the web. xml file
<Filter>
<Filter-Name> struts </filter-Name>
<Filter-class> org. Apache. struts2.dispatcher. Ng. Filter. strutsprepareandexecutefilter </filter-class>
</Filter>
<Filter-mapping>
<Filter-Name> struts </filter-Name>
<URL-pattern>/* </url-pattern>
</Filter-mapping>
5. Create a controller
1. Create a package under the src directory
Package name: CN. jbit. struts2101401.web. Action
2. Create a controller under the package
Controller name: useraction. Java
Controller content:
Public class useraction extends actionsupport {
Private user;
Public String login (){
If ("123". Equals (user. GetUserName () & "123". Equals (user. GetPassword ())){
Return "success ";
}
Return Error;
}
// Omit getter and setter
}
6. Configure the controller (action) in the core configuration file struts. xml)
<Constant name = "struts. UI. Theme" value = "simple"> </constant>
<Package name = "default" namespace = "/" extends = "struts-Default">
<! -- Global -->
<Global-Results>
<Result name = "error">/WEB-INF/pages/error. jsp </result>
</Global-Results>

<! -- User action -->
<Action name = "useraction" class = "cn. jbit. struts2101401.web. Action. useraction">
<Result name = "success">/WEB-INF/pages/success. jsp </result>
<! -- Local -->
<Result name = "error">/WEB-INF/pages/error. jsp </result>
</Action>
</Package>
7. Create a view)
1. View-Logon
View name: index. jsp
View content:
<S: Form Action = "useraction! Success. Action "method =" Post ">
Username: <s: textfield name = "user. username"/> <br/>
Password: <s: password name = "user. Password"/> <br/>
<S: Submit value = "Logon"/>
</S: Form>
2. View-Logon successful
View name: success. jsp
View content:
Success. jsp
3. View-Logon Failed
View name: Error. jsp
View content:
Error. jsp

This article from the "Su Yan" blog, please be sure to keep this source http://suyanzhu.blog.51cto.com/8050189/1564330

Struts-global configuration

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: info-contact@alibabacloud.com 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.