Use struts for simple login

Source: Internet
Author: User

1. Select Java EE6.0 when building a project

2. Write Login interface

<body>  <center>    <form id= "Form1" Name= "Form1" action= "Action/login.action" method= "POST" >    user name <input name= "username" type= "text" ><br>    password <input name= "password" type= "password" ><br>    <input type= "Submit" value= "Login" >    </form>    </center>  </body >

3. Right-click the project name-->eclipse-->add Struts support-->struts 2.1-->finish

4. Building class login.jsp inheriting Actionsupport

5. Write Login.java

Ackage Com.chao.s4;import com.opensymphony.xwork2.actionsupport;public Class Login extends Actionsupport {private String Username= "";p rivate string password= "";p ublic 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;} Public String Execute () throws Exception {//TODO auto-generated method stubstring u,p;u=getusername ();p =getpassword (); if (U.equals ("1") &&p.equals ("1")) {return "Success";} Elsereturn "Error";}}

6. Write Struts.xml (can be dragged)

Code:

7. Last Write success.jsp and error.jsp

<body>    Login Successful <a href=index.jsp> return </a><br>  </body>
<body>    Login failed <a href=index.jsp> return </a><br>  </body>

Use struts for simple login

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.