struts.convention.result.path is not working in Struts2

馋奶兔 提交于 2020-01-03 03:10:12

问题


My current project structure is as follows

WebContent
   WEB-INF
   View
     TestPage.jsp
     other JSP pages...

My assignment is to put all JSP pages inside folder WEB-INF and do all relative changes in the project.

WebContent
   WEB-INF
      View
        TestPage.jsp
        other JSP pages...

So I have to update all result tag in struts.xml

<result name="success">/View/TestPage.jsp</result>

to

<result name="success">/WEB_INF/View/TestPage.jsp</result>

After search on web I found a plugin - struts convention plugin to achieve this, But it follows its Naming convention.

Can I override Struts convention plugin configuration (that will not follow its naming convention)?I have tried too, but it is not reflecting. My struts.xml is

<struts>
    <constant name="struts.devMoade" value="true" />
    <constant name="struts.convention.result.path" value="/WEB-INF/View/" />

    <package name="test" extends="struts-default" namespace="/">
        <action name="hello1" class="testAction.Hello1Action">
            <result name="success">/TestPage.jsp</result>
        </action>
    </package>
</struts>

When I run

localhost:8080/project-name/hello1

It displays error 404.But if I change result in struts.xml as

<result name="success">/WEB-INF/View/TestPage.jsp</result>

It works fine.

I don't wanna do changes in all result tags.How can I achieve this by doing changes at one place?


回答1:


The convention plugin uses a different configuration provider and this constant only works with configuration created by convention.

<constant name="struts.convention.result.path" value="/WEB-INF/View/" />

If you want to override the convention configuration you should use annotations.

package testAction;

@ParentPackage("json-default")
@Namespace("/")
@Action(value="hello1", results=@Result(name = "success", location="TestPage.jsp"))
public class Hello1Action extends ActionSupport {
}


来源:https://stackoverflow.com/questions/28363971/struts-convention-result-path-is-not-working-in-struts2

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!