2

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?

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • possible duplicate of [Struts2 .action extension causing CSS, JavaScript and Struts Dojo to break](http://stackoverflow.com/questions/12607075/struts2-action-extension-causing-css-javascript-and-struts-dojo-to-break) – Aleksandr M Aug 17 '15 at 08:23

2 Answers2

1

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"/>
Erwan C.
  • 709
  • 5
  • 18
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.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • How careless am I to check only the content not the comments.Thanks for the explanation.http://www.mkyong.com/struts2/how-to-remove-the-action-suffix-extension-in-struts-2/ – Prince Radhakrishnan Aug 11 '15 at 12:40