Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

@RequestParam annotation usage for a get request

 
Deepaks Deshpande
Ranch Hand
Posts: 114
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear all,

I am trying to append the username as a query string onto my URL. I am using the following code


and i am calling the link in my menu page as follows:
<a href="examlogin.htm?user=">Login to take the exam</a>

Now, whenever i click the link, i get a 404 error and my logger shows the following on the console:

Please let me know what i am missing.
Thank you.
 
sutha kavi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

The following code is enough while using @RequestParam,

@RequestMapping(value="/examlogin.htm", method=RequestMethod.GET)
public String displayExamLogin(HttpServletRequest request, Model model, @RequestParam(value = "user", required = true) String user) throws Exception{
String today = new Date().toString();

model.addAttribute("user", user);
logger.info("Loading the login page... "+today+" POST method");
return "/examlogin.htm?user=";
}

Thanks,
Sutha
 
Deepaks Deshpande
Ranch Hand
Posts: 114
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear sutha,
I tried using your code. Now the browser displays a message saying
 
Deepaks Deshpande
Ranch Hand
Posts: 114
Eclipse IDE Hibernate Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Also when i added the attribute to the @RequestMapping annotation, my browser displays the following error message


Please help me.
 
sutha kavi
Greenhorn
Posts: 15
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

while using the below code,

@RequestMapping(value="/examlogin.htm", method=RequestMethod.GET)
public String displayExamLogin(HttpServletRequest request, Model model, @RequestParam(value = "user", required = true) String user) throws Exception{
String today = new Date().toString();

model.addAttribute("user", user);
logger.info("Loading the login page... "+today+" POST method");
return "";
}

Can you tell the url that has been used for accessing the above?

Regards,
Sutha
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic