1

有没有办法使用 Spring MVC 设置页面的显示 url?让我举个例子更清楚:我有以下控制器:

@Controller
public class Display{
    @RequestMapping(value = "myPage")
    public ModelAndView display() {
        ModelAndView result = new ModelAndView(Uris.MY_PAGE);
        return result;
    }

    @RequestMapping(value = "myPage/revisited")
    public ModelAndView accountManagement() {
        ModelAndView result = new ModelAndView(Uris.ACCOUNT);
        return display();
    }
}

如果我继续myPage/Revisited,我将获得关联到的 JSP myPage。但是,在我的浏览器中,url 将保持不变 ( myPage/revisited)。我怎么能防止呢?

4

1 回答 1

1

为了更准确地了解 sam 所说的,您可以使用UrlRewriteFilter,安装过程在链接中进行了说明,然后在文件中设置规则urlrewrite.xml

 <rule  match-type="wildcard">
        <from>/myPage/revisited/redirect</from>         
        <to type="redirect">%{context-path}/myPage</to> 
</rule>

在您的控制器中,只需使用 Emanuele 所说的,即 response.sendRedirect("redirect");

于 2013-08-22T10:29:55.757 回答