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?
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.