Struts-Logon 1

Source: Internet
Author: User

1. Create a project
Project name: struts2
Add jar package/struts2/webroot/WEB-INF/lib
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
Add a filter to Web. xml
<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>

Under SRC
Create package name: CN. jbit. struts2.web. Action
Creation class: useraction. Java
Public class useraction extends actionsupport implements sessionaware {
Private Map <string, Object> session;
Private string username;
Private string password;

@ Override
Public String execute () throws exception {
If ("jbit". Equals (username) & "123". Equals (password )){
Session. Put ("username", username );
Return success;
}
Return Error;
}
Public void setsession (Map <string, Object> session ){
This. Session = session;
}
// Omit get and set
}
In index. jsp
<S: If test = "% {# session. Username! = NULL} ">
Welcome <s: property value = "% {# session. Username}"/>
</S: If>
<S: else>
<S: Form Action = "useraction. Action" method = "Post">
Username: <s: textfield name = "username"/> <br/>
Password: <s: password name = "password"/> <br/>
<S: Submit value = "Logon"/>
</S: Form>
</S: else>
Create a folder pages under Web-INF
Create error. SJP
Create success. jsp
Create a configuration file under Conf
Struts. xml
<Struts>
<Constant name = "struts. UI. Theme" value = "simple"> </constant>
<Package name = "default" namespace = "/" extends = "struts-Default">
<Action name = "useraction" class = "cn. jbit. struts2.web. Action. useraction">
<Result name = "success">/WEB-INF/pages/success. jsp </result>
<Result name = "error">/WEB-INF/pages/error. jsp </result>
</Action>
</Package>
</Struts>



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

Struts-Logon 1

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.