19

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.

tkanzakic
  • 5,499
  • 16
  • 34
  • 41
Simcha
  • 3,300
  • 7
  • 29
  • 42
  • 2
    I solved it, there excess parameter in the method of the second class – Simcha Sep 01 '12 at 15:18
  • 3
    You may post your solution as an answer and accept it afterwards, this will help community – Serkan Arıkuşu Mar 05 '13 at 16:04
  • 1
    @user1640210, posting a solution and accepting it will help the community as serkan says, and keep people from wasting time reading a question that is already solved. – Gus Mar 11 '13 at 15:46

4 Answers4

36

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.

SkyWalker
  • 28,384
  • 14
  • 74
  • 132
ike3
  • 1,760
  • 1
  • 17
  • 26
2

In my case the reason of this error was that browser (Chrome, in my particular case) was sending the date from the <input type="date" ... /> to the server in the wrong format so server didn't know how to parse it.

ivan.mylyanyk
  • 2,051
  • 4
  • 30
  • 37
0

As said ike3, using the detailed log aided a lot to find the solution for me. In my case it was a mismatch between @PathVariable without name specified, and the variable itself.

Something like this:

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

Note the difference between "uname" and "username" ! There was an exception internally that wasn't raised and I couldn't see it until I set the log to INFO level.

Community
  • 1
  • 1
Aníbal
  • 785
  • 8
  • 24
0

In my case, it was also a problem of conversion, Spring was expecting an Integer however I was entering a String. Try to check what you have passed as parameters to the controller

Youness Marhrani
  • 1,084
  • 16
  • 8