日期:2014-05-18  浏览次数:20609 次

Struts2,访问loginA.action报404
一个登录的小例子,如果登录成功就跳转到欢迎页,不然就返回当前页..

我的目录结构是:

struts.xml文件

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<!-- 2013.8.16  -->
<package name="first" extends="struts-default" namespace="/"><!-- 定义一个package -->
<!-- 对action返回结果的配置 -->
<action name="loginA" class="action_struts.LoginAction">
<result name="success" type="dispather">/12.2.2.welcome.jsp</result>
<result name="login">/12.2.2.index.jsp</result>
</action>
</package>
<!-- END 2013.8.16 -->
</struts>

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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"  
    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>SSH</display-name>  
    <welcome-file-list>  
        <welcome-file>index.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>

action类:

package action_struts;


import com.opensymphony.xwork2.ActionSupport;


public class LoginAction extends ActionSupport {