我现在把login.jsp放在根目录下,一访问,就出现404错误。
我把 filter 和下面的 监听器去掉,正常
web.xml<?xml version="1.0" encoding="UTF-8"?>
<web-app 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"
   version="2.5">

<!-- 加载struts2核心 -->
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>
            org.apache.struts2.dispatcher.FilterDispatcher
        </filter-class>
        <init-param>
<param-name>exclude</param-name>
<param-value>
login.jsp
</param-value>
</init-param>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>    <!-- 指明spring配置文件在何处 -->
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:applicationContext.xml</param-value>
    </context-param>    <!-- 加载spring配置文件applicationContext.xml -->
    <listener>
        <listener-class>
            org.springframework.web.context.ContextLoaderListener
        </listener-class>
    </listener>
       
 
<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>

</web-app>****************************************************************************struts.xml
<!DOCTYPE struts PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
          "http://struts.apache.org/dtds/struts-2.0.dtd"><struts>
    <constant name="struts.objectFactory" value="spring" />
    <package name="struts2" extends="struts-default">
        <action name="login" class="LoginAction" method="testStruts">
            <exception-mapping result="usernameInvalid" exception="com.exception.UsernameException" />
            <exception-mapping result="passwordInvalid" exception="com.exception.PasswordException" />
            <result name="success" type="dispatcher">index.jsp</result>
            <result name="input" type="dispatcher">login.jsp</result>
            <result name="usernameInvalid" type="dispatcher">usernameInvalid.jsp</result>
            <result name="passwordInvalid" type="dispatcher">passwordInvalid.jsp</result>
        </action>
    </package></struts>

解决方案 »

  1.   

    补充下,login.jsp ,直接放在网站的根目录下
      

  2.   

    </filter>
      <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
      </filter-mapping>改为</filter>
      <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.action</url-pattern>
      </filter-mapping>
      

  3.   

    已经试过了,不行无论是所有的都走 filter  还是 *.action 都不行
    我都奇了怪了,网上也都是讲这个配的呀
      

  4.   

    终于可以了,现在把我的一些心得,记录一下出现上面的原因是因为,相应的包没有没有导入因为,我用的是srping 2.5 ,现在最新是3.2吧,没用最新的,我同事他们2.5用的多,struts用的是2.1,注意以下两点:
    第一.
    spring+struts一定要导入的包:
    commons-logging-1.0.4.jar (没这个包,不会打印出错信息)
    ognl-2.7.3.jar
    spring.jar
    struts2-core-2.1.8.1.jar
    struts2-spring-plugin-2.1.8.1.jar
    xwork-core-2.1.6.jar
    freeer-2.3.15.jar
    commons-fileupload-1.2.1.jar前面因为少了commons-logging-1.0.4.jar。连错误信息都不会打印
    第二
    在前面的过滤中 filter 中     
    <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
    我试着把/* 改为 /*.action 或 *.action 会出现,
    希望大家再遇到此类的问题不要再走弯路
      

  5.   

    org.apache.struts2.dispatcher.FilterDispatcher这个在新版本的struts2中已经不使用了呀。
      

  6.   

    commons-logging-1.0.4.jar 没这个包你的spring跑得起来?