Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
367 views
in Technique[技术] by (71.8m points)

java - 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":

 /*
 * 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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...