-1

I want to put view.jsp file in WEB-INF folder. it lies in WEB-INF\user\view.jsp

<package name="user" extends="struts-default"  namespace="user">
     <action name="view" class="com.example.user.ViewUserAction">
             <result>/WEB-INF/user/view.jsp</result>
     </action>
</package>

but Struts changes this url to application/user/WEB-INF/user/view.jsp

so as I understand if my namespace is not "/" I will never visit the JSP in WEB-INF ?

Roman C
  • 49,761
  • 33
  • 66
  • 176
marknorkin
  • 3,904
  • 10
  • 46
  • 82

1 Answers1

1

I found where I was wrong.

As Alexander M pointed out in comments no such url will be generated.

The thing is I've tried various bad solutions, but most of them had the next synopsis.

In struts.xml I wrote:

<package name="product" namespace="/" extends="struts-default">
        <action name="view" class="com.example.action.product.ViewProduct">
            <result name="success">/WEB-INF/view/product/view.jsp</result>
        </action>
</package>

and in jsp I refer to somee action as:

<a href="product/view">View product</a>

but seems like its wrong way to do it - in my case I had urls like:

http://localhost:8080/app/product/product/view.action

which is not valid.

So I changed struts.xml namespace to:

  <package name="product" namespace="/product" extends="struts-default">
            <action name="view" class="com.example.action.product.ViewProduct">
                <result name="success">/WEB-INF/view/product/view.jsp</result>
            </action>
   </package>

And then in view.jsp used struts <s:a> tag (or you may use <s:url>):

<a href="<s:url action='view' namespace="/product"/>"> View product</a>

<s:a action="view" namespace="/product"> View product</s:a>

For further reference about packages and namespaces understanding:

  1. Struts Namespace Configuration
  2. Struts Package Configuration
marknorkin
  • 3,904
  • 10
  • 46
  • 82