我在练一一个简单的login,设定账号密码给他,可是他无法判断SUCCESS跟ERROR不管怎么样都会回传SUCCESS怎么办...
web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>stucts_project</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
index.jsp(这是我login的界面)
<%@ page language="java" import="java.util.*"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>I/O</title>
</head>
<body>
<form name="form1" action="Login.action" method="post">
账号 :<input type="text" name="name"><br> 密码:<input
type="password" name="pass"><br> <input type="submit"
value="送出">
</form>
</body>
</html>
login.java(就是这里不管怎么打错密码一样会回传success)
package com.action;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class Login extends ActionSupport{
private static final long serialVersionUID = 1;
private String name;
private String pass;
public String getName(){
return name;
}
public void setName(String name){
this.name = name;
}
public String getPass(){
return pass;
}
public void setPass(String pass){
this.pass = pass;
}
public String excute() throws Exception{
ActionContext ac = ActionContext.getContext();
if(name.equals("asd") && pass.equals("123")){
ac.put("success", "login success");
return Action.ERROR;
}else{
ac.put("error", "login error");
return Action.ERROR;
}
}
}
struts.xml(不管怎样都只会跑result.jsp不会跑error.jsp...)
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN"
"http://struts.apache.org/dtds/struts-2.1.7.dtd">
<struts>
<package name="default" extends="struts-default" namespace="/">
<action name="Login" class="com.action.Login">
<result name="success">/result.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>