本人刚刚接触Struts2,今天在做网上教的一个小项目时,总是报404错,不知道是为什么
项目情况如下:
工具:MyEclipse6.5 Tomcat5.0
JDK1.6
Struts2版本2.2web.xml配置如下:
<?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.ng.filter.StrutsPrepareFilter</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>struts.xml配置如下:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" 
    "http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
<package name="bixy" namespace="/" extends="struts-default">
<action name="hello" class="org.bixy.struts2.demo.HelloStruts">
<result name="suc">/hello.jsp</result>
<result name="err">/err.jsp</result>
</action>
</package>
</struts>在web.xml中配置Struts2 的Filter之前,可以访问到index.jsp页面,配完Filter之后,就报404错了,望前辈指教

解决方案 »

  1.   

    在struts中 如果楼主要访问action 就配置action类
    <action name="sellorderAction" class="com.popuEmenu.action.sellorderAction">
    然后访问的路径
    <%
    if(session.getAttribute("list")==null){
    response.sendRedirect("LoginMenuAction!login");
    }
    %>
    这是个列子.页面得到的list为空时访问
      

  2.   

    这是我的struts2的拦截 不知道你的能用不.也许是拦截问题.也许是你访问路径问题 <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>
      

  3.   

    struts2.0以后的过滤器一般都是用
    org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    楼主试试看~~
      

  4.   

    这个问题我遇到过 哈哈  是你的配置文件的路径不对  应该放在src下面
      

  5.   

    看看你配置文件的路径吧,前几天还有个人问我这个问题的,给他调了半天,发现struts文件不在src下
      

  6.   

    我的struts.xml配置文件是放在src目录下的
    我的web.xml配置文件中,
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareFilter</filter-class>
    org.apache,还有ng下面划黄线,说我拼写不正确,我看jar包里面,这个路径是正确的啊
      

  7.   

    启动时有没报错?看下显示404是访问哪个URL导致的?
      

  8.   

    tomcat中server.xml文件做如下配置
    <Context path="/struts2" docBase="D:\Workspaces\Struts2\WebRoot" reloadable="true"/>
    访问的时候输入的是:http://localhost:8080/struts2然后页面报404错,说The requested resource (/struts2/) is not available如果不加web.xml 中filter的配置,可以正常访问
      

  9.   

    看看你的struts版本,如果是2.13前的用org.apache.struts2.dispatcher.FilterDispatcher
      

  10.   

    或者用StrutsExecuteFilter试试
    是你的过滤器问题,和别的没有关系。因为你没有配之前是可以访问的,所以在/*之前调用过滤的问题,。
      

  11.   

    问题解决了,我把过滤器改成org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
    Tomcat换成6.0 ,就好了,谢谢大家