3

I've looked through all similar Qs on stackoverflow but it didn't help, sorry. The main difference I have from all of them is that I got EMPTY action name in error message. Googling didn't help :( Hope someone just could give a hint where to look for the source of the problem. thx

message:

    Stacktraces
    There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]. - [unknown location] 
        com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:185)
        org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
        org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:39)
        com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58
    ..................

struts.xml:

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
    "http://struts.apache.org/dtds/struts-2.0.dtd">

        <struts>
        <constant name="struts.devMode" value="true" />
        <package name="default" namespace="/*" extends="struts-default">
            <action name="login"
                class="training.struts.action.LoginAction">
                <result>login.jsp</result>
            </action>
        </package>
        </struts>

web.xml:

        <?xml version="1.0" encoding="UTF-8"?>
        <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
        version="2.5">

        <display-name>Struts Lab</display-name>

        <filter>
            <filter-name>struts2</filter-name>
            <filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>struts2</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

        <!-- Spring Config -->
        <context-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                    /WEB-INF/springServlet/appServlet/mvc-servlet.xml,
                    /WEB-INF/db/db-cfg.xml,
                    /WEB-INF/springServlet/application-security.xml
            </param-value>
        </context-param>

        <listener>
            <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
        </listener>

        <servlet>
            <servlet-name>mvc</servlet-name>
            <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
            <init-param>
                <param-name>contextConfigLocation</param-name>
                <param-value>/WEB-INF/springServlet/appServlet/mvc-servlet.xml</param-value>
            </init-param>
            <load-on-startup>1</load-on-startup>
        </servlet>

        <servlet-mapping>
            <servlet-name>mvc</servlet-name>
            <url-pattern>/</url-pattern>
        </servlet-mapping>

        <!-- Spring Security -->
        <filter>
            <filter-name>springSecurityFilterChain</filter-name>
            <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
        </filter>

        <filter-mapping>
            <filter-name>springSecurityFilterChain</filter-name>
            <url-pattern>/*</url-pattern>
        </filter-mapping>

        <!-- *** -->
        <welcome-file-list>
            <welcome-file>login.jsp</welcome-file>
            <welcome-file>index.jsp</welcome-file>
        </welcome-file-list>

        </web-app>

well..image is impossible so the project structure is:

src/main/java
----+training.struts.action.LoginAction.java
src/main/webapp
----+WEB-INF
--------+classes
-----------+struts.xml
--------+db
-----------+db-cfg.xml
--------+springServlet
-----------+appServlet
---------------+mvc-servlet.xml
-----------+application-security.xml
--------+index.jsp
--------+login.jsp
--------+web.xml

UPDATE: So sad to be stupid =( I've moved my login.jsp from WEB-INF to webapp root and that solved the problem.

UPDATE2: I've made some investigation: if I remove "welcome-file-list" block from web.xml, container will look for "index.jsp" in webapp root to show as first view on application running. If I delete "index.jsp" then I'll got the identical exception message: There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]

So in my opinion if you have empty action name in error message with correct xml settings for struts, the first step should be start-up JSP availability checking.

Cheers, guys.

Roman C
  • 49,761
  • 33
  • 66
  • 176
java_newbie
  • 821
  • 1
  • 13
  • 24

6 Answers6

4

Add the below blank action to you struts.xml file in "/" package namespace and it will show the index.html when you will only try to access your url (like appid.app.com) and it will not show the error. Normally it will add a blank action and app engine will redirect the blank action to your welcome file.

    <action name="" class="com.candi.actions.Dashboard" method="noAction">
        <result name="success">index.jsp</result>
    </action>
Aniruddha Das
  • 20,520
  • 23
  • 96
  • 132
3

Add / in your namespace instead of /* :

<package name="default" namespace="/" extends="struts-default">

Or if issue not resolved than you can use Config Browser Plugin.

The Config Browser Plugin is a simple tool to help view an application's configuration at runtime. It is very useful when debugging problems that could be related to configuration issues.

Ankur Lathi
  • 7,636
  • 5
  • 37
  • 49
3

OK, so I have placed login.jsp in a wrong place in my web-app folders structure. That was the mistake

java_newbie
  • 821
  • 1
  • 13
  • 24
0

Add the following package in struts.xml

<package name="default" namespace="/" extends="struts-default">    
     <action name="login"
            class="training.struts.action.LoginAction">
            <result>login.jsp</result>
    </action>   
</package>
MayurB
  • 3,609
  • 2
  • 21
  • 36
  • Attach the JSP page where you are calling the action – MayurB Jul 24 '13 at 09:21
  • I don't call any actions manually - I just run the project on server in eclipse – java_newbie Jul 24 '13 at 09:30
  • 2
    2337 neurons suddendly died in my brain after reading ` – Andrea Ligios Jul 24 '13 at 09:38
  • @AndreaLigios: ` – Aleksandr M Jul 24 '13 at 11:17
  • @AleksandrM I know that, [I've used it too](http://stackoverflow.com/a/17405177/1654265), but for default fallback of not found action URLs; in this answer, it seemed to be used to avoid declaring any action... no matter the URL, it will always fallback on LoginAction :| – Andrea Ligios Jul 24 '13 at 11:22
  • @AndreaLigios For other project actions specify the package namespace.For more modularization.For e.g namespace = "/Action"...Other than any url will redirect you to login page Since in user code it wont redirect to welcome page on context root.This is the one way to redirect it on contextroot – MayurB Jul 24 '13 at 11:42
  • Yes, but since you probably have to check if user is authenticated in an Interceptor, this becomes useless; it is useful only if you want to redirect to login page a user that is trying to hack with the URL, instead of giving him a 404 page (from where you can reach the login page, of course). Btw I didn't downvote you, just commented; as a hint, put this kind of considerations in the answer next time, to avoid putting them later in the comments :) – Andrea Ligios Jul 24 '13 at 11:49
0

I changed the namespace in package tag to '/' and the problem resolved!!!

0

For me, I changed the opening tag of the web.xml file from

<web-app>

to

<web-app id="WebApp_ID" version="2.4"
         xmlns="http://java.sun.com/xml/ns/j2ee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
         http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">