There is no Action mapped for namespace [/] and action name [] associated with context path [/struts]

java_newbie picture java_newbie · Jul 24, 2013 · Viewed 34k times · Source

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.

Answer

Aniruddha Das picture Aniruddha Das · Jun 17, 2014

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>