我使用switchAction来处理多模块请求,
想使用spring的注解来管理action,
在spring的配置文件中管理action是可以的,但是使用注解的则不行,不能创建action,
不知道是不是我的配置有问题,或者是有些什么其他的问题,希望哪位能帮我看看,解答一下
我的相关文件内容如下:
web.xml
[code="xml"]
action
org.apache.struts.action.ActionServlet
config
/WEB-INF/struts/struts-config.xml
config/demo
/WEB-INF/struts/struts-config-demo.xml
debug
3
detail
3
0
action
*.do
[/code]
struts-config.xml默认模块配置文件
[code="xml"]
[/code]
struts-config-demo.xml
[code="xml"]
[/code]
Demo1Action
[code="java"]
@Controller("/demo1/demo")
@Scope("prototype")
public class Demo1Action extends DispatchAction {
public ActionForward demo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("message", "这是Demo1模块");
return mapping.findForward("list");
}
[/code]
DemoAction
[code="java"]
@Controller("/demo")
@Scope("pototype")
public class DemoAction extends DispatchAction {
public ActionForward demo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("message", "这是Demo模块");
return mapping.findForward("list");
}
}
[/code]
applicationContext.xml
[code="xml"]
<!-- 这是我注释后的配置,如果不使用注解,使用这样的配置则是可以的
-->
[/code]
[b]问题补充:[/b]
忘了补充一点,我使用的是插件是
[code="xml"]
[/code]
[quote]
http://reack.itpub.net/post/1065/22126
蔡华江 (高级程序员) 2009-10-20 采纳为答案 举报作弊
[/quote]
谢谢蔡华江的回答,这个网址我刚才看过了,里面说的是不使用注解的方式来进行配置的,如果我不使用注解,而使用配置文件的话,是没有问题的,但是使用注解,再使用switchAction就不行了,我不知道是为什么,
报的错误是
HTTP Status 500 - No action instance for path /demo could be created
下面是我在jsp页面上写的访问路径
[code="html"]
Demo
Demo1
[/code]
[b]问题补充:[/b]
[quote]sunlightcs (高级程序员) 2009-10-22
[/quote]
谢谢你,你让我成功了一半,默认模块是没有问题了,但是我的那个demo子模块却不行,不知道为什么,希望能帮我解答,谢谢
[b]问题补充:[/b]
[quote]
引用
@Controller("/demo1/demo")
@Scope("prototype")
public class Demo1Action extends DispatchAction {
public ActionForward demo(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
request.setAttribute("message", "这是Demo1模块");
return mapping.findForward("list");
}
说明一点,不要@Controller("/demo1/demo") 这样写,"/demo1/demo"这是这个ACTION交给Spring管理时BEAN的名字,不是路径,最好这样写:@Controller("demo1Action")
sunlightcs (高级程序员) 2009-10-23 采纳为答案 举报作弊
[/quote]
谢谢你的回答,我想再问一下:
如果说这里不写成/demo1/demo,难道这里不是需要和struts配置文件中的相匹配吗?在配置文件中配置的话,访问路径就是bean的name属性值,按说,这里应该也是没有错啊,还有,如果我这里不写成/demo1/demo,而直接写成/demo的话就会与默认模块的访问路径相冲突,刚试了一下,改为/demo1也不行,还是没有action实例被创建,
[b]问题补充:[/b]
[quote]
sunlightcs (高级程序员)
[/quote]
你说的是struts2.struts1不是这样的