使用struts2-convention-plugin-2.1.6的问题
struts2已经升级到了2.16了,并使用Convention Plugin作为替换替换Codebehind Plugin来实现Struts2的零配
置,详细见其官方文档
,Alfa.Shi翻译了中文版
。
我在使用Convention Plugin时却遇到了一个N烦人的问题,小弟在此恳请各位赐教,不知道是我配置的问题还是插件
的本身的bug,我在访问相应action时,竟然不执行action中的execute()默认方法(访问action中其他方法时,居然报没
有相应的action名或result异常),而是直接跳转到相应的结果页面,比如访问HelloAction类,将跳转到hello.jsp,当我
把action类给删除了,还是同样跳转到的hello.jsp页面,所以可以肯定的是没有真正根据action来执行相应的跳转,因为
struts2-convention-plugin是即使在没有action存在情况下,也会根据URL规则来找到结果页面。
struts.xml配置文件:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN"
"http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<constant name="struts.convention.default.parent.package" value="crud-default" />
<constant name="struts.convention.result.path" value="/mycontent"/>
<package name="crud-default" extends="convention-default">
<!-- 基于paramsPrepareParamsStack,增加store interceptor -->
<interceptors>
<interceptor-stack name="crudStack">
<interceptor-ref name="store">
<param name="operationMode">AUTOMATIC</param>
</interceptor-ref>
<interceptor-ref name="paramsPrepareParamsStack" />
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="crudStack" />
</package>
</struts>
我具体的action包是这样的:"org.example.products.web.struts2" ( Convention会从根package中寻找包名含
有struts, struts2, action or actions的任意packages和查找符合条件package下面及其子package中对
com.opensymphony.xwork2.Action 的实现以及以Action结尾的类,所以"org.example.products.web.struts2"该
包下所有Action类应该都将被Convention找到),但是我的action不知怎么没用,就是没有被找到,哎!真是百思不得棋
解!!郁闷了好几天,现在还没找到原因!
我的页面文件目录结构是这样:"webapp/mycontent/hello.jsp"(在struts.xml中配置了“ <constant
name="struts.convention.result.path" value="/mycontent"/>,更改了其默认存在WEB-INF/content下,如果
我想放在根目录下,不知是否是把value="/"就行?请教一下各位,恳请各位赐教!)。
当我访问http://localhost:8080/hello.action时直接跳到hello.jsp页面,HelloAction中的execute方法没反应,直接把HelloAction删除了,访问还是同样。
当访问http://localhost:8080/hello!save.action时,直接抱没有相应的action,但HelloAction中有save方法。
小弟被此问题已困扰好几天了,这几天觉都睡不着,恳请各位赐教!小弟感激不尽!
应该不是index方法,我代码没有做任何更改,换一个工作空间(eclipse)就OK啦。现在也没搞懂是什么原因.
没看到他错误吗,默认不再是execute了而已index方法