Results 1 to 3 of 3

Thread: Problem in retrieving session data.

Hybrid View

  1. #1

    Default Problem in retrieving session data.

    I am trying to store some Form values in Session and I like to retrieve them later on in subsequent JSP pages. I use SimpleFormController in my code. My problem is the onSubmit method in the controller is not getting executed.

    This is how I store the Form values in the Controller inside OnSubmit method. Here selected_city and selected_city_value are Hash Maps that needs to be stored in the session.

    protected ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response, Object command) throws Exception {
    .....
    ......
    ......

    HttpSession sessionnew = request.getSession(true);
    sessionnew.setAttribute("selected_city", selected_city);
    sessionnew.setAttribute("selected_city_value", selected_city_value);

    }




    This is how I retrieve the session information from the session in the JSP Page.

    HashMap<String, String> selected_city = (HashMap<String, String>) session.getAttribute("selected_city");
    HashMap<String, Double> selected_city_value = (HashMap<String, Double>) session.getAttribute("selected_city_value");
    String origin=selected_city.get("origin_city");


    Can someone point me whether I am storing the session information in the correct way. If I remove the "HttpServletRequest request,
    HttpServletResponse response,"
    from the onSubmit method and other session information, I can see the onSubmit getting executed properly.
    I am not able to understand why onSubmit method is not executed?

    Note: I have zipped the project from Eclipse. Download this and import into Eclipse to reproduce the error.

    http://rapidshare.com/files/43943209...Annotation.zip

    Instructions to import the Project zip file.
    a. Click on the “File”, select “Import”, select “General”, select “Existing Projects into Workspace”, select “Select the archive files”, select the Project zip file.

  2. #2

    Default

    I can't download the zip file to take a look at this. It's been a while since I've used the old SimpleFormController approach. I assume you've got a pre-Spring2.5 implementation.

    To make this work, I believe you'll need to do a couple of things I didn't see mentioned. To enable your command object to be stored in the session, you'll need to set the SessionForm property for your implementation to 'true'. The way the SimpleFormController works is that your initial 'GET' request will call the formBackingObject method, which you will need to override and implement the appropriate initialization of the command object.

    In your JSP, you should be able to access the command object with JSTL and EL.

  3. #3

    Default

    Thank u msecrist

    The problem went away after I fixed it like this:

    Old code with bug


    protected ModelAndView onSubmit(HttpServletRequest request,
    HttpServletResponse response, Object command)


    New code with fix

    protected ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) {

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •