日期:2014-05-20  浏览次数:20800 次

菜鸟学struts2,高手指点下,老是报错:The requested resource is not available
1、login.jsp
  <form action="login.action" method="post">
   userName:<input type="text" name="username"><br>
   passWord:<input type="text" name="password"><br>
  <input type="submit" value="submit">
  </form>
2、result.jsp
  <body>
userName:${requestScope.username }<br>
password:${requestScope.password }
  </body>
3、类LoginAction 
package com.test.action;
public class LoginAction {
private String username;
public String getUserName() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
private String password;
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String execute() throws Exception
{
return "success";
}
}
4、struts配置
<?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="struts2" extends="struts-default">
<action name="login" class="com.test.action.LoginAction">
<result name="success">/result.jsp</result>
</action>
</package>

</struts>
5、过滤
<?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">

<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>