关于spring 管理 struts action的问题
在Struts中存在两个路径"/demo"和"/demo1".这两个路径请求的都是同一个action(com.struts.action.DemoAction).stru...
在Struts中存在两个路径 "/demo" 和 "/demo1" . 这两个路径请求的都是同一个action(com.struts.action.DemoAction).
struts-config.xml
<action path="/demo" parameter="demo"/>
<action path="/demo1" parameter="demo1"/>
如果spring是通过xml配置的方式管理的话 , 可以通过以下配置来实现 将同一个action在spring容器中注册两个值
<bean name = "/demo" class = "com.struts.action.DemoAction"/>
<bean name = "/demo1" class = "com.struts.action.DemoAction"/>
请教: 如果我是通过注解的方式去加载action的话,怎么样实现以上功能
@Controller("/demo")
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");
}
} 展开
struts-config.xml
<action path="/demo" parameter="demo"/>
<action path="/demo1" parameter="demo1"/>
如果spring是通过xml配置的方式管理的话 , 可以通过以下配置来实现 将同一个action在spring容器中注册两个值
<bean name = "/demo" class = "com.struts.action.DemoAction"/>
<bean name = "/demo1" class = "com.struts.action.DemoAction"/>
请教: 如果我是通过注解的方式去加载action的话,怎么样实现以上功能
@Controller("/demo")
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");
}
} 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询