Struts.convention.result.path not working in Struts2

My current project structure looks like this

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

      

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

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

      

So I need to update all the result tags in struts.xml

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

      

to

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

      

After searching the web, I found a plugin plugin plugin to achieve this, but it follows its naming convention.

Can I override the configuration of the Struts convention plugin (which won't follow its naming convention)? I tried it too, but it doesn't reflect. My struts.xml

-

<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 ran

localhost:8080/project-name/hello1

      

Error 404 is displayed.But if I change the result in struts.xml as

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

      

It works great.

I don't want to make changes to all the result tags. How can I achieve this by making changes in one place?

+1


source to share


1 answer


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

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

      



If you want to override the convention configuration, you must use annotations.

package testAction;

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

      

0


source







All Articles