Announcement Announcement Module
Collapse
No announcement yet.
How to get request parameter Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • How to get request parameter

    Hi all,
    I'm currently doing some migration for a Spring 2.5.6 application to Spring 3.0.4 and I was wondering how I am supposed to get a parameter selected by a user on a page.

    With Spring 2.5.6, the code looked like that :
    Code:
    @Controller
    public class LoginController extends CustomController {
    	
    	private TechnoService technoService = null;
    	
    	// Other functions
    
    	@RequestMapping("/page1.wss")
    	public ModelAndView login(HttpSession session, HttpServletRequest request) {	
    		String technoID = request.getParameter("foobar");
                          // doing some weird things with the parameter ;)
    		String nextUrl = "/showWelcome.wss";
    		return new ModelAndView("redirect:" + nextUrl); 
    	} 
    
    }
    But running this code with the new framework doesnt work quite well.
    I've tried with the @RequestParam("foobar") in the function signature, but I get a runtime error saying that the parameter doesn't exist.

    Any thoughts about what's going on and how I could solve it?

    Thanks
    Last edited by mireaulf; Oct 15th, 2010, 02:49 PM.

  • #2
    By default parameters are required, set it to optional if it isn't always there...

    Comment


    • #3
      Well, I know that, I've read some of the documentation.

      What seems to happen is that the parameter IS NOT there but IT SHOULD be, any thoughts on what could be the cause of that?

      Comment


      • #4
        If you can get it with request.getParameter you can also get it with @RequestParam, try including the name in the @RequestParam else it takes the method attribute name for lookup and if you compile without debug info that might not be available.

        Comment


        • #5
          I think we misunderstood each others. The code I posted doesn't work because after this line

          Code:
          String technoID = request.getParameter("foobar");
          the variable is null, which means that it wasn't retrieved by the function.
          What could possibly cause this to happen, if it was working with the earlier version of Spring and doesn't work now with Spring 3.0.4.

          Also, using the @RequestParam doesn't work either. If I put it in the method signature as required (it is, I need this parameter to continue), I get the runtime error describe above.

          Thanks

          Edit: If it can help, the from submitting these data is using a POST method.
          Last edited by mireaulf; Oct 15th, 2010, 02:51 PM.

          Comment


          • #6
            Edit: If it can help, the from submitting these data is using a POST method.
            If you are using the POST method, then the @RequestMapping annotation should include that. GET is the default HTTP method for @RequestMapping.

            Code:
            @RequestMapping(value="/page1.wss", method="POST")
            This was also the case with Spring 2.5, so I'm not sure how this was working before.

            Comment


            • #7
              I doubt it has something to do with spring, the request is basically the request from the app server. If you parameter is tehre (be it a GET or POST parameter) it should be retrievable, if not I suspect something else is wrong.

              Comment

              Working...
              X