简体   繁体   English

Spring:客户端发送的请求在语法上是不正确的()

[英]Spring: The request sent by the client was syntactically incorrect ()

Hi I received next error during the redirect: 嗨我在重定向期间收到了下一个错误:

The request sent by the client was syntactically incorrect 客户端发送的请求在语法上是不正确的

URL which browser shows is: localhost:8080/Project/menu/main/home/0 and here my classes with redirects first - "from", second "to": 浏览器显示的URL是: localhost:8080/Project/menu/main/home/0 ,这里我的类首先重定向 - “from”,second“to”:

 /*
 * Get all possible values of menu and generate correct url to pages controllers
 * 
 */

@Controller
@SessionAttributes("menu")
public class MainMenuController {


    @ModelAttribute
    public Menu createMenu() {
        return new Menu();
    }

    @RequestMapping(value = "/menu", method = RequestMethod.GET)
    public String mainMenuResolver(@ModelAttribute Menu menu) {
        menu.setMainMenu("first");
        return "forward:/menu/first";
    }

    @RequestMapping(value = "/menu/{mainMenu}", method = RequestMethod.GET)
    public String subMenuResolver(@PathVariable String mainMenu, @ModelAttribute Menu menu) {
        menu.setMainMenu(mainMenu);
        menu.setSubMenu("home");
        return "forward:/menu/first/home";
    }

    @RequestMapping(value = "/menu/{mainMenu}/{subMenu}", method = RequestMethod.GET)
    public String secMenuResolver(@PathVariable String mainMenu, @PathVariable String subMenu, @ModelAttribute Menu menu) {
        menu.setMainMenu(mainMenu);
        menu.setSubMenu(subMenu);
        menu.setSecMenu("0");

        if (menu.getMainMenu().equals("first")){
            return "redirect:/menu/main/"+menu.getSubMenu()+"/"+menu.getSecMenu();
        }

        if (menu.getMainMenu().equals("second")){
            return "redirect:/menu/religion/"+menu.getSubMenu()+"/"+menu.getSecMenu();
        }

        return "redirect:/menu/main/"+menu.getSubMenu()+"/"+menu.getSecMenu();
    }
}

Second class: 二等:

@Controller
@SessionAttributes("menu")
public class FirstPageController {

    @ModelAttribute
    public Menu createMenu() {
        return new Menu();
    }

    @RequestMapping(value = "/menu/main/{subMenu}/{secMenu}", method = RequestMethod.GET)
    public ModelAndView menuResolver(@PathVariable String mainMenu, @PathVariable String subMenu,@PathVariable String secMenu, @ModelAttribute("menu") Menu menu) {
        menu.setMainMenu(mainMenu);
        menu.setSubMenu(subMenu);
        menu.setSecMenu(secMenu);       

        if (menu.getSubMenu().equals("home")){
            String title = "Project - Home Page";
            return new ModelAndView("MainPage", "title", title);
        }

        String title = "Project - Home Page";
        return new ModelAndView("MainPage", "title", title);
    }
}

Solved : I solved it, there excess parameter in the method of the second class. 解决 :我解决了它,在第二类的方法中有多余的参数。

In cases like this it is very useful to have org.springframework.web loggin level set to DEBUG in log4j configuration 在这种情况下,在log4j configuration中将org.springframework.web登录级别设置为DEBUG非常有用

<logger name="org.springframework.web">
    <level value="DEBUG" />
    ...
</logger>

Eg when parameter is missing or cannot be converted to the required type there will be an exception details in the log. 例如,当参数丢失或无法转换为所需类型时,日志中将存在异常详细信息。

在我的情况下,这个错误的原因是浏览器(Chrome,在我的特定情况下)是以错误的格式将date<input type="date" ... />发送到服务器,因此服务器不知道如何解析它。

As said ike3 , using the detailed log aided a lot to find the solution for me. 正如ike3所说,使用详细日志帮助我找到解决方案。 In my case it was a mismatch between @PathVariable without name specified, and the variable itself. 在我的例子中,没有指定名称的@PathVariable与变量本身不匹配。

Something like this: 像这样的东西:

@RequestMapping("/user/{uname}")
public String doSomething(@PathVariable String username) { ...

Note the difference between "uname" and "username" ! 注意“uname”和“username”之间的区别! There was an exception internally that wasn't raised and I couldn't see it until I set the log to INFO level. 内部有一个未引发的异常,直到我将日志设置为INFO级别才能看到它。

In my case, it was also a problem of conversion, Spring was expecting an Integer however I was entering a String. 在我的情况下,它也是一个转换问题,Spring期待一个Integer但是我输入了一个字符串。 Try to check what you have passed as parameters to the controller 尝试检查您作为参数传递给控制器​​的内容

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Spring形式:客户端发送的请求在语法上不正确() - Spring form : The request sent by the client was syntactically incorrect () spring mvc - 客户端发送的请求在语法上是不正确的 - spring mvc - The request sent by the client was syntactically incorrect SPRING框架:客户端发送的请求在语法上不正确 - SPRING framework: The request sent by the client was syntactically incorrect 客户端发送的请求在语法上不正确 - The request sent by the client was syntactically incorrect Spring MVC文件上传-客户端发送的请求在语法上不正确 - Spring MVC File Upload - The request sent by the client was syntactically incorrect Spring MVC-上传文件显示客户端发送的请求在语法上不正确 - Spring MVC - upload file shows The request sent by the client was syntactically incorrect 客户端发送的请求在语法上是不正确的。 在春天使用@RequestParam - The request sent by the client was syntactically incorrect. using @RequestParam in spring 客户端发送的请求在语法上不正确。 在@ManyToOne关系中休眠,春季 - The request sent by the client was syntactically incorrect. in @ManyToOne relation Hibernate, Spring 使用Spring MVC进行CRUD时出现错误“客户端发送的请求在语法上不正确” - Error “The request sent by the client was syntactically incorrect” when CRUD with Spring MVC 客户端发送的请求在spring mvc,ajax中在语法上不正确 - The request sent by the client was syntactically incorrect in spring mvc, ajax
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM