I am developing an application using Spring. I am navigating to different pages through out the application. My problem here is, if i am navigating to the ABC.jsp page. In the browser it should shown to be as IP:port/ABC, not like IP:port/ABC.jsp.

Is there any mechanism in spring to hide the file extension in the browser?

有帮助吗?

解决方案

If i am not wrong and you are using sping. So simple do one thing in the controller request mapping drop the extension and in controller setting view page to the model, drop extension in that also. Like

@RequestMapping(value="/login")
    public ModelAndView login() {
        return new ModelAndView("login");
    }

in the above method i am mapping the controller as login by dropping the extension and in the time of forwarding the model i am dropping the extension. In this case you can forward to the controller without showing the extension in the url.

其他提示

With a servlet mapping you need to specify each JSP individually like follows:

<servlet>
    <servlet-name>search</servlet-name>
    <jsp-file>/search.jsp</jsp-file>
</servlet>
<servlet-mapping>
    <servlet-name>search</servlet-name>
    <url-pattern>/search</url-pattern>
</servlet-mapping>

It's easier if all those JSPs are in a common path. E.g. /app/*.

<servlet>
    <servlet-name>app</servlet-name>
    <servlet-class>com.example.FriendlyURLServlet</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>app</servlet-name>
    <url-pattern>/app/*</url-pattern>
</servlet-mapping>

with

request.getRequestDispatcher("/WEB-INF" + request.getPathInfo() + ".jsp").forward(request, response);

This assumes the JSPs to be in /WEB-INF folder so that they cannot be requested directly. This will show /WEB-INF/search.jsp on http://example.com/app/search.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top