本文介绍了Spring:客户端发送的请求在语法上是不正确的()的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我在重定向期间收到了下一个错误:

Hi I received next error during the redirect:

浏览器显示的URL是: localhost:8080 / Project / menu / main / home / 0 and here我的课程首先重定向 - 从,第二个到:

URL which browser shows is: localhost:8080/Project/menu/main/home/0 and here my classes with redirects first - "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();
    }
}

第二课:

@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.

推荐答案

在这种情况下,拥有<$非常有用在c code> log4j配置

In cases like this it is very useful to have org.springframework.web loggin level set to DEBUG in log4j configuration

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

例如。当参数丢失或无法转换为所需类型时,日志中会出现异常详细信息。

E.g. when parameter is missing or cannot be converted to the required type there will be an exception details in the log.

这篇关于Spring:客户端发送的请求在语法上是不正确的()的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:48