论坛首页 Java版 Struts

struts2.1.2的REST问题[已解决]

浏览 656 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
最后更新时间:2008-06-05 关键字: struts2.1.2, rest
在使用Struts2.1.2时,发现一个问题

当我使用rest插件时,在struts.xml中配置
  
<package name="default" extends="struts-default">        
        <action name="test" class="cn.com.struts.action.IndexController" method="test">
            <result name="test">test.jsp</result>
            <result name="success">index.jsp</result>
        </action>
    </package>


Action代码:
package cn.com.struts.action;
import com.opensymphony.xwork2.ActionSupport;

public class IndexController extends ActionSupport{
	public String index(){
		System.out.println("=====================index=======================");
		return SUCCESS;
	}
	public String test(){
		System.out.println("=====================test=======================");
		return "test";
	}
}

结果浏览http://localhost:8080/struts/test.do时发现不是访问的IndexAction的test方法。
访问的是index方法。返回jsp页面index.jsp
只能通过http://localhost:8080/struts/index!test.do来访问,返回jsp页面index-test.jsp

当然,去掉其rest插件就不会有问题。
这样好像有些不太爽。
   
最后更新时间:2008-06-04
不就应该这样吗?
   
0 请登录后投票
最后更新时间:2008-06-04
我是说它应该两种实现都支持啊。
支持了rest,
结果导致配置action指定action的method方式就不支持了。

看了一下rest插件的源码。
mapping的method为null,然后设为默认的index
看来用rest时设置method是无效的
   
0 请登录后投票
最后更新时间:2008-06-05
你看下rest插件的plugin.xml里面怎么配的吧,他重写了一个自己的actionmapper,整套的pageflow等都重写过,印象中在文档中看到过可以配置一个CompositeActionMapper的,可以试试
   
0 请登录后投票
最后更新时间:2008-06-05

通过更改RestActionInvocation.java的源码,实现了我的需求。

如下:

protected String invokeAction(Object action, ActionConfig actionConfig) throws Exception {
        String methodName = proxy.getMethod();
        
        if(actionConfig.getMethodName()!=null&&actionConfig.getMethodName().trim().length()>0){
             methodName =actionConfig.getMethodName();
        }

..........................
}

 

   
0 请登录后投票
论坛首页 Java版 Struts

跳转论坛:
JavaEye推荐