-->

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

2019-06-07 04:40发布

问题:

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 {
}