huangjiuyx 2009-11-02 02:18
浏览 248
已采纳

关于spring 管理 struts action的问题

在Struts中存在两个路径 "/demo" 和 "/demo1" . 这两个路径请求的都是同一个action(com.struts.action.DemoAction).

struts-config.xml

如果spring是通过xml配置的方式管理的话 , 可以通过以下配置来实现 将同一个action在spring容器中注册两个值

请教: 如果我是通过注解的方式去加载action的话,怎么样实现以上功能

[color=orange]@Controller("/demo")[/color]
public class DemoAction extends MappingDispatchAction { 
public ActionForward demo(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    System.out.println("demo");
    return mapping.findForward("success");
}

public ActionForward demo1(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    System.out.println("demo1");
    return mapping.findForward("success");
}

}

以上配置只有在请求路径为"/demo"的时候才能访问到这个action , 如果路径为"/demo1"时这个注解要怎么写 .

  • 写回答

3条回答 默认 最新

  • weixin_42519046 2009-11-05 09:50
    关注

    struts action 直接继承DispatchAction

    一个action 就写一个路径就可以了

    前台访问改改就可以
    js:
    window.location.href="demo.do?method=a1";
    jsp:

    strust配置文件改一下:
    给你个我的例子
    attribute="logonForm"
    input="/form/logon.jsp"
    name="logonForm"
    path="/logon"
    scope="request"
    [color=red] parameter="method"
    validate="true"[/color] type="com.iphonemusic.struts.action.LogonAction" />

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥30 vmware exsi重置后的密码
  • ¥15 易盾点选的cb参数怎么解啊
  • ¥15 MATLAB运行显示错误,如何解决?
  • ¥15 c++头文件不能识别CDialog
  • ¥15 Excel发现不可读取的内容
  • ¥15 关于#stm32#的问题:CANOpen的PDO同步传输问题
  • ¥20 yolov5自定义Prune报错,如何解决?
  • ¥15 电磁场的matlab仿真
  • ¥15 mars2d在vue3中的引入问题
  • ¥50 h5唤醒支付宝并跳转至向小荷包转账界面