struts2登录验证返回页面跳转

1.工程如下:

struts2登录验证返回页面跳转

2.UserAction.java

package com.ask.action;
import com.opensymphony.xwork2.ActionSupport;
public class UserAction extends ActionSupport{
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;
}
public String test(){
if(username.trim().equals("tom")&&password.equals("123456")){
return "success";
}else{
return "error";
}
}
}

3.struts.xml

<?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>
<package name="user" namespace="/user" extends="struts-default">
<action name="test" class="com.ask.action.UserAction" method="test">
<result name="success">
/success.jsp
</result>
<result name="error">
/error.jsp
</result>
</action>
</package>
</struts>

4.index.jsp

struts2登录验证返回页面跳转

5.程序运行效果如下:

5.1登录成功

struts2登录验证返回页面跳转struts2登录验证返回页面跳转

5.2登录失败

struts2登录验证返回页面跳转

struts2登录验证返回页面跳转