有 Java 编程相关的问题?

你可以在下面搜索框中键入要查询的问题!

java重定向到视图文件中的外部URL

在SpringMVC控制器操作中有以下字符串。我希望控制器操作呈现一个视图页面,该页面采用以下字符串,然后执行重定向

String redirectUrl = "http://www.yahoo.com"

我的控制器操作如下所示:

@RequestMapping(method = RequestMethod.GET)
    public String showForm(HttpServletRequest request, ModelMap model) 
    {
          String redirectUrl = "http://www.yahoo.com";
          model.addAttribute("redirectUrl", redirectUrl);
          return "loginSuccess"; //this is my view JSP file
    }

在JSP视图中有没有一种方法可以在不使用JSTL的情况下执行此重定向?我想要一个干净的重定向,不发送任何查询字符串参数

谢谢


共 (1) 个答案

  1. # 1 楼答案

    也许我误解了,但是如果你想要重定向,你必须使用RedirectView

    String redirectUrl = "http://www.yahoo.com";
    return "redirect:" + redirectUrl;
    

    或者使用RedirectView实例

    @RequestMapping(method = RequestMethod.GET)
    public View showForm(HttpServletRequest request, ModelMap model) 
    {
          String redirectUrl = "http://www.yahoo.com";
          RedirectView view = new RedirectView(redirectUrl );
          return view;
    }