本帖最后由 nrc1982 于 2010-04-19 23:52:14 编辑

解决方案 »

  1.   

    你的jsp页面呢?还有这里应该是这样的<result name="success">/WEB-INF/hello.jsp</result>
      

  2.   

    404 是说你找不到该页面,一般都是在加载配置文件的时候出错了,当你把配置文件删掉后,就没有再运行配置文件,再点击跳转肯定就不会有404了。 是不是你放了两个web.xml 在上面呀。你是先安装struts2就会有一个,你不会是自己又加了一个吧。 
    下面是struts2的配置文件,与上一篇struts1进行对照,可以发现很多不同与改进:1.web.xml<?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_9" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
     <!-- 描述性文本 -->
        <display-name>Struts2 web配置文件</display-name>
     
     <!-- 加载Struts2.0核心控制器FilterDispatcher -->
        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
        </filter> <!-- 指定用户的URL请求 -->
        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>
       
     <!-- 1.欢迎列表,既默认主页 -->
        <welcome-file-list>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>
    </web-app>   2.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>
     <!-- 包含其他文件配置 -->
       <include file="struts-default"/>
      
       <!-- 常量配置 -->
       <constant name="struts.il8n.reload" value="false"/>
       
       <!-- Bean配置
       class:bean对象的实现类;
       name:指定bean实例名;
       type:组件实现的接口,指定bean实现Struts2.0规范
       scope:指定作用范围;
       static:是否使用静态方法注入;
       optional:指定该bean是否是一个可选的Bean;
        -->
       <bean name="myLogin" class="com.struts2.Login" scope="default"
           type="org.apache.struts2.viw=ews.TagLibrary"/>
       
       <!-- 包配置
         name:包名;
         extends:指定要继承的包;
         namespace:指定命名空间;
         abstract:指定是否为抽象包;
        -->
       <package name="Struts 2.0_Tags" extends="struts-default">
      
        <!-- 拦截器配置 -->
        <interceptors>
         <interceptor name="replace" class="com.struts2.ReplaceInterceptor"/>
         <interceptor-stack name="crudStack">
          <interceptor-ref name="replace"/>
          <interceptor-ref name="defaultStack"/>
         </interceptor-stack>
        </interceptors>
        
        
        <!-- Action配置 -->
        <action name="tag1" class="com.struts2.TagAction">
         <result name="ok">ok.jsp</result>
         <interceptor-ref name="crudStack"></interceptor-ref>
        </action>
       </package>
    </struts>
      

  3.   

    return "success"改为return SUCCESS;试试
      

  4.   

    <action name="student" class="com.nrc.p1.StudentAction">
       <result>/hello.jsp</result>
    </action>
    这样修改一下,再看一下你的hello.jsp放在那个位置
      

  5.   

    工程是你新建的还是导入的呀,看下你的context root和http://localhost:8080/webapp/student中的webapp一样不
      

  6.   

    1.你的hello.jsp是否放在WebRoot下。
    2.STRUTS.XML中
    <package name="webapp" namespace="/" extends="struts-default">
    如果错误时404应该就是上面两个错误了。也建议你在action里打印一下,通过url请求后,是否真的执行了aciton。
      

  7.   

    +1,这个我也很在意。
    你的struts.xml中<package name="index" namespace="/" extends="struts-default">package是不是写错了?
    还有打开tomcat看看工程有没有在里面,配置文件的路径有没有错。编程时最悲剧的就是404的错误,很纠结
      

  8.   

    访问 http://localhost:8080/webapp/student.action呢?
      

  9.   

    LZ
    web.xml中的这个?
    <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
    你肯定有这个过滤器?struts2都用这个吧:<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
      

  10.   

    http://localhost:8080/webapp/student
    路径后面要么加上/hello.jsp
    要么修改<welcome-file>index.jsp</welcome-file>
    里面index.jsp为hello.jsp