开发者

Hide the .jsp url extension in struts2 project

开发者 https://www.devze.com 2023-04-07 19:40 出处:网络
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.

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/

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号