Hide the .jsp url extension in struts2 project
I am working in the struts2 web application.I want to do the mapping of my url such that the extensions like ".jsp" should be eliminated from the url. So below is the snippet code of my web.xml.I want to do that my url show /login instead of /login.jsp.
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>URLFilter</filter-name>
<filter-class>example.MyFilter</filter-class>
<init-param>
<param-name>onError</param-name>
<param-value>/login.jsp</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>URLFilter</开发者_运维技巧filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Just access all your JSPs through Actions (and put them somewhere below WEB-INF
to enforce this policy). It's easy to do with the "default action" of Struts2:
<action name="login">
<result>/WEB-INF/pages/login.jsp</result>
</action>
I don't know how well this integrates with ServletFilter
, maybe you'll have to turn the one mentioned in your web.xml into a Struts2 Interceptor
.
You can change url extension using property file as shown in below link :
http://www.aoiblog.com/change-url-extension-in-struts2/
精彩评论