Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/322.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java SpringMVC。重定向页面_Java_Ajax_Spring Mvc - Fatal编程技术网

Java SpringMVC。重定向页面

Java SpringMVC。重定向页面,java,ajax,spring-mvc,Java,Ajax,Spring Mvc,我有一个处理URL studentEdit.html的控制器。当我使用AJAX传递控制器值“get”时,我需要重定向到另一个页面viewstustudents.html,但什么也没有发生。我保持一致。该方法返回ModelAndView,但我不知道为什么它不重定向到另一个页面 我还尝试将url设置为: 重定向:viewStudents.html和重定向:viewStudents 但这没有帮助 @RequestMapping(value = "/studentEdit.html", method =

我有一个处理URL studentEdit.html的控制器。当我使用AJAX传递控制器值“get”时,我需要重定向到另一个页面viewstustudents.html,但什么也没有发生。我保持一致。该方法返回ModelAndView,但我不知道为什么它不重定向到另一个页面

我还尝试将url设置为:

重定向:viewStudents.html和重定向:viewStudents

但这没有帮助

@RequestMapping(value = "/studentEdit.html", method = RequestMethod.GET)
public ModelAndView getStudentProfile(@RequestParam(value = "get", required = false) String get) {

    if(get != null && get.equals("get")) {
        return new ModelAndView("redirect:/viewStudents.html");
    } else {
        ModelAndView mav = new ModelAndView("studentEdit"); 
        return mav;
    }
}


function getStudent() {
            $.ajax({
                type: "GET",
                url: "/IRSystem/studentProfileEdit.html",
                data: "get=" + 'get',
                success: function(response) {

                },
                error: function(e) {
                    alert('Error' + e);
                }

            });
        }

非常感谢您提供任何信息。

如果您希望在请求后重定向到另一个页面,则无需使用AJAX

一个简单的链接就足够了:

<a href="/IRSystem/studentProfileEdit.html?get=get">click me</a>

单击链接时会发生什么情况:

  • 执行对
    /IRSystem/studentProfileEdit.html
    的GET请求
  • get=get
    作为请求数据传递
  • 默认情况下,用户被重定向到链接的
    href
    (即
    /IRSystem/studentProfileEdit.html
    ),但您可以将其重定向到其他地方

假设其余代码正确,请使用
about
redirect:
prefix确保正确解释重定向。

在服务器端这样做有什么原因吗?如果您实际上没有从服务器检索任何数据,则应该使用Javascript重定向。您正在重定向AJAX请求本身。无法使用此方法重新定位页面。您可以通过在响应中添加标题(例如,
X-Redirect-Url:/my/Redirect
)来解决此问题,并在成功回调中根据该值执行操作。当然,如果您的环境允许,我需要从数据库中检索信息,然后将这些信息重定向到另一个页面。