2

I have an intercetpor that checks if the user is logged in before serving the requested action. I have tried setting this as default for all action. For all addresses except one this works like a charm. When I go to my root URL "http://localhost:8080/map/" for some reason the interceptor doesn't fire. I'm guessing there is something missing i struts.xml but I can't figure out what:

<struts>

    <constant name="struts.devMode" value="true" />
    <constant name="struts.custom.i18n.resources" value="ApplicationResources,DatabaseResources" />

    <package name="map" extends="struts-default">
        <interceptors>
            <interceptor name="loginintercept"
                class="se.contribe.intercept.LoginInterceptor" />
            <interceptor-stack name="defaultLoginStack">
                <interceptor-ref name="loginintercept" />
                <interceptor-ref name="defaultStack" />
            </interceptor-stack>
        </interceptors>

        <default-interceptor-ref name="defaultLoginStack" />

        <default-action-ref name="index"></default-action-ref>

        <global-results>
            <result name="loginneeded">/login.jsp</result>
        </global-results>

        <action name="index" class="**.map.MapAction">
            <result>/index.jsp</result>
        </action>

        <action name="login">
            <result>/login.jsp</result>
        </action>

        <action name="loginInput" class="**.session.LoginAction">
            <result type="redirectAction">
                <param name="actionName">index</param>
            </result>
            <result name="input">/login.jsp</result>
            <result name="error">/login.jsp</result>
        </action>

        <action name="*" class="**.map.MapAction">
            <result>/index.jsp</result>
        </action>
    </package>

</struts>

I have obfuscated the class names a bit just in case my employer would object.

Roman C
  • 49,761
  • 33
  • 66
  • 176
Skadlig
  • 1,569
  • 1
  • 14
  • 16
  • Is a request to http://localhost:8080/map/ invoking your index action? If so, what interceptors are being invoked for that request? – Steven Benitez Apr 20 '11 at 14:23

2 Answers2

0

Your root url may be http://localhost:8080/map/ but a package "map" refers to http://localhost:8080/map/map

You probably want a package defined for "/" which the root at http://localhost:8080/map/ and you might want a package defined for "" which allows the actions within to be executed from within any package.

Edit: In the above I confused name for namespace (been using conventions plugin too much it seems!)

I would strongly suspect that if you check your web.xml file you'd find something like:

<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
</welcome-file-list>

which if you changed that to

<welcome-file-list>
    <welcome-file>index.action</welcome-file>
</welcome-file-list>

you would get what you expected, as I can have both a index.jsp and an index.action and changing that setting choose one or the other.

Quaternion
  • 10,380
  • 6
  • 51
  • 102
  • @Qyaternion I think you are talking about the namespace of the package. When none is supplied namespace="" is used. The name attribute of a package is just that, a name, there is no connection to the url unless a namespace is supplied. At least that is what I figured from the Apache reference manual. – Skadlig Apr 21 '11 at 09:35
0

I managed to figure this one out my self eventually.
I tested writing a simple output to console in the execute stage of

<action name="index" class="**.map.MapAction">  

When I opened the web page no output was printed in the console. That got me thinking. My main page was named index.jsp and apparently that name bypasses Struts normal controls. Changing the name to index2.jsp solved the problem.
There is probably some place else where I could change this behaviour but it was easier to simply change the name.

Skadlig
  • 1,569
  • 1
  • 14
  • 16