日期:2014-05-19  浏览次数:20715 次

s:form 出现找不到action的问题
这边只将重要的代码贴出来, jsp页面只是截取body部分的内容
--index.jsp 首页面
<s:form action="login" method="post">
<s:textfield name="username" label="User Name"></s:textfield>
<s:password name="password" label="PassWord"></s:password>
<s:submit value="Submit"></s:submit>
</s:form>

--error.jsp 错误页面

<body>
<s:property value="tip"/>
</body>

--welcome 成功页面

<body>
欢迎,${username }
</body>

--LoginAction 登录处理的Action

package com.test.action;

import com.opensymphony.xwork2.ActionSupport;

public class LoginAction extends ActionSupport{
/**
* 登录处理的Action
*/
private static final long serialVersionUID = 1L;

private String username;//用户名
private String password;//密码
private String tip;//提示信息

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 getTip() {
return tip;
}
public void setTip(String tip) {
this.tip = tip;
}

@Override
public String execute() throws Exception {
if("fanbo".equals(getUsername())&&"hejuan".equals(this.getPassword())){
return SUCCESS;
}else{
tip="用户名和密码不符";
return ERROR;
}

}

/**
* 注册页面
* @return
*/
public String regist(){
return SUCCESS;
}

}

--Struts Action的配置

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN" "struts-2.1.7.dtd" >
<struts>
<package name="test" extends="struts-default" namespace="/">
<action name="login" class="com.test.action.LoginAction">
<result name="success">/welcome.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
</struts>

--web.xml中的filter的配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
xmlns="http://java.sun.com/xml/ns/javaee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
  <!-- Struts filter的配置 -->
  <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>
  
  <welcome-file-list>
  <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
</web-app>

--运行的时候,点击index.jsp页面中的提交按钮总是抱找不到Action的错误。下面为错误信息,就不写出全部了,写出一部份

HTTP Status 404 - There is no Action mapped for namespace / and action name login.

--------------------------------------------

type Status report

message There is no Action mappe