public class UserAction extends ActionSupport  implements ModelDriven<Object>, Preparable{
加上
@Namespace("/fanice/user") 
@Results( { @Result(name = "success", location = "index.jsp"),  
            @Result(name = "error", location = "index.jsp") })
@Action("oss")
public class UserAction extends ActionSupport  implements ModelDriven<Object>, Preparable{

解决方案 »

  1.   

    额 ,谢谢你的回答,加上了还是不行啊,还是报哪个错。jsp报404,后台报错
      

  2.   

    @Action("oss")是不是写错地方了,是不是要写在方法上:
      

  3.   


    package com.example.actions;import com.opensymphony.xwork2.ActionSupport; 
    import org.apache.struts2.convention.annotation.Action;
    import org.apache.struts2.convention.annotation.Actions;
    import org.apache.struts2.convention.annotation.Result;
    import org.apache.struts2.convention.annotation.Results;public class HelloWorld extends ActionSupport {
      @Action(value="/different/url", 
        results={@Result(name="success", type="httpheader", params={"status", "500", "errorMessage", "Internal Error"})}
      )
      public String execute() {
        return SUCCESS;
      }  @Action("/another/url")
      public String doSomething() {
        return SUCCESS;
      }
    }
    官网山看到的一段代码
      

  4.   

     怀疑你的index.jsp配置的路径有问题
    修改为
    @Namespace("/fanice/user") 
    @Results( { @Result(name = "success", location = "/index.jsp"),  
                @Result(name = "error", location = "/index.jsp") })
    @Action("oss")
    public class UserAction extends ActionSupport  implements ModelDriven<Object>, Preparable{
      

  5.   

    在UserAction上面加入@Namespace("/fanice/user")还报404是不是你jsp的路径问题
      

  6.   

    jsp 路径有问题的话
    后台也应该有输出啊可是我的后台没有输出
      

  7.   

     debug模式,断点下,看请求到后台的action没有,再看看action里的方法有没有正常走完,你的webRoot下面有个index.jsp,应该是可以看到页面的。或者修改为
    @Namespace("/fanice/user") 
    @Results( { @Result(name = "success", location = "/WEB-INF/page/fanice/user/index.jsp"),  
                @Result(name = "error", location = "/WEB-INF/page/fanice/user/index.jsp") }) 试试
      

  8.   


    debug 进不去,没挂上。哎,悲剧啊为什么这里有个小点  ,问题会不会出在这里?
      

  9.   

    web,xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" 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>MyCommon</display-name>
    <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>

     <!-- 配置spring的监听器 --> 
     <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>classpath*:applicationContext*.xml</param-value>
     </context-param>
     
     <!-- Character Encoding Filter -->
     <filter>
            <filter-name>Set Character Encoding</filter-name>
            <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
            <init-param>
                <param-name>encoding</param-name>
                <param-value>UTF-8</param-value>
            </init-param>
            <init-param>
                <param-name>forceEncoding</param-name>
                <!-- 强制进行转码 -->
                <param-value>true</param-value>
            </init-param>
      </filter>
      
     <!-- Open Session In View Filter -->
     <filter>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
      <init-param>
       <param-name>singleSession</param-name>
       <param-value>true</param-value>
      </init-param>
     </filter>
     
     <!-- 延长action中属性的生命周期, -->
     <filter>
      <filter-name>struts-cleanup</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ActionContextCleanUp</filter-class>
     </filter>
     
     <!-- Struts2 Filter -->
     <filter>
      <filter-name>struts2</filter-name>
      <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
      <init-param>
       <param-name>config</param-name>
       <param-value>struts-default.xml,struts-plugin.xml,classpath*:struts.xml</param-value>
      </init-param>
     </filter>
     
     <filter-mapping>
         <filter-name>Set Character Encoding</filter-name>
         <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
      <filter-name>OpenSessionInViewFilter</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
      <filter-name>struts-cleanup</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping>
    <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>/*</url-pattern>
    </filter-mapping> <!-- Spring Listener -->
     <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     </listener> <!-- Spring提供的一个用来防止内存泄露的监听器 -->
     <listener>
         <listener-class>org.springframework.web.util.IntrospectorCleanupListener</listener-class>
     </listener></web-app>
      

  10.   

    楼主把@Results这个注解里面的放到
    @Action(value="oss",results={ @Result(name = "success", location = "index.jsp"),  
                @Result(name = "error", location = "index.jsp") })
    这里面试试
      

  11.   

    Action@Namespace("/fanice/user") 
    @Results( { @Result(name = "success", location = "/index.jsp"), 
    @Result(name = "error", location = "/index.jsp") })
    @Action("oss")
    public class RegistAction extends ActionSupport { /**
     * 
     */
    private static final long serialVersionUID = 1L; public String execute() {
    System.out.println("Welcome to Annotation");
    return SUCCESS;
    }
    }
    struts.xml 为空
    web.xml<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>struts2</display-name>
      <filter>
        <filter-name>struts2</filter-name>
        <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        <init-param>   
    <param-name>actionPackages</param-name>  
    <param-value>com.zhangqi.action.RegistAction</param-value>  
    </init-param> 
      </filter>
      <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
      </filter-mapping>
    </web-app>
    web.xml中需要扫描配置action的包,楼主的里面配一堆spring的东东,不太熟悉
    然后就是 webRoot下面的index.jsp了
    可以成功访问。
    建议楼主将web.xml简化下,先让程序跑起来,再添加监听等等。