Prince Radhakrishnan
Prince Radhakrishnan

Reputation: 324

404 error when Struts2 action extension is set to empty

I want to remove the action suffix extension in Struts2 application.

Added <constant name="struts.action.extension" value=""/> to the struts.xml but Apache server throws 404 error.

HTTP Status 404 - There is no Action mapped for namespace [/] and action name [login.jsp] associated with context path [/Ideck_V3].

I'm using welcome-file-list in web.xml for the first page. Here is web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
    <filter>
        <filter-name>struts2</filter-name>
        <filter-class>com.hbs.ideck.common.Struts2Dispatcher</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>struts2</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
    <welcome-file-list>
        <welcome-file>login.jsp</welcome-file>
    </welcome-file-list>
</web-app>

Here is the struts.xml

<!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.action.extension" value=""/> 
    <include file="user.xml"/>
    <include file="vendor.xml"/>
    <include file="settings.xml"/>
</struts>

How can I resolve this?

Upvotes: 2

Views: 1017

Answers (2)

Roman C
Roman C

Reputation: 1

The default extension mapping is ",,action". It means that you can use mapping to action name with .action suffix and without it, so if you want to remove the action suffix extension you need to specify it in struts.xml as

<constant name="struts.action.extension" value=","/>

Note, the mapping to action without action suffix still remains. It allows to resolve extensions in the url like .jsp and don't mess it up with action name.

Upvotes: 1

Erwan C.
Erwan C.

Reputation: 719

As you dont set any extension for your actions, everything in "/*" (see your web.xml) is intercepted. If you want to filter everything and dont set any extension, everything will be an action for struts.

You can try do filter only a path

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

Or you have to set an extension

<constant name="struts.action.extension" value="action" />

Or exclude some patterns

<constant name="struts.action.excludePattern" value="A REGEX"/>

Upvotes: 1

Related Questions