Im developing a web application(J2EE,Struts2,JSP,Tomcat)
I want to hide the .jsp extension from webpages.
here is some piece of my web.xml:
<filter>
<filter-name>STSDispatcher</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>STSDispatcher</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>Login.jsp</welcome-file>
</welcome-file-list>
I Googled around and found this solution:
<servlet>
<servlet-name>myFoo</servlet-name>
<jsp-file>myJSPfile.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>myFoo</servlet-name>
<url-pattern>/main</url-pattern>
</servlet-mapping>
I tried this like below, but didn’t work:
for example I have “alert.jsp” and this is my web.xml:
<servlet>
<servlet-name>alert</servlet-name>
<jsp-file>/alert.jsp</jsp-file>
</servlet>
<servlet-mapping>
<servlet-name>alert</servlet-name>
<url-pattern>/alert</url-pattern>
</servlet-mapping>
but I got this error:
“There is no Action mapped for namespace / and action name alert. – [unknown location]”
What should I do?
Thanks in advance.
I think you get the error because your struts2 filter intercept all the request coming to the server and tries to find a mapping in your actions but since
/alertactually points to a servlet you see the error.A solution would be to have the mapping in your struts config file like:
This way when you request
/alertyou get the page with no extension (name of your action).