Results 1 to 4 of 4

Thread: ModelAndView

  1. #1
    Join Date
    Mar 2005
    Posts
    6

    Default ModelAndView

    hi,

    Is it possible to assign the value returned from the ModelAndView to a variable in a jsp page?

    In the controller I implemented the return statement is as given below:

    return new ModelAndView("sample.jsp", "var_name", "var_value");


    In the jsp page, I want this value to be assigned to a variable.

    Can somebody tell me how to achieve this?

    regards,
    nisha

  2. #2
    Join Date
    Aug 2004
    Location
    Carlisle, UK
    Posts
    184

    Default

    Anything you add to the model is made available to your view - that's the purpose of the model.

    If your view is jsp, then I believe the model attributes are added as attributes to the request, and are available via request.getAttribute("var_name").

    However, it is much simpler to use the JSTL standard tag library, in which case you can get the value by
    <c:out value="${var_name}"/>
    or just by
    ${var_name}
    depending on which version of servlet/JSP you are using.

    Hope this helps. The examples that come with Spring should help further.
    Chris Harris
    Carlisle, UK

  3. #3
    Join Date
    Mar 2005
    Posts
    6

    Default

    hai Chris,

    Thanks a lot. That was of great help.

    regards,
    nisha

  4. #4
    Join Date
    Apr 2005
    Posts
    6

    Default Re: ModelAndView

    Quote Originally Posted by nisha
    hi,

    Is it possible to assign the value returned from the ModelAndView to a variable in a jsp page?

    In the controller I implemented the return statement is as given below:

    return new ModelAndView("sample.jsp", "var_name", "var_value");
    ...
    My comment does not have to do with your question, but you might want choose view's name not tied to any implementation specific, i.e.: remove ".jsp" and use only "sample".

    It is possible (and recommended) to use prefix/suffix values in the configuration to avoid tight coupling with implementation.

    So in the future, you may easily change to Velocity, Freemarker or any other view without having to change your Controller's code.

    Cheers~

Similar Threads

  1. Replies: 37
    Last Post: Dec 6th, 2007, 10:02 AM
  2. Replies: 2
    Last Post: Oct 21st, 2005, 11:42 AM
  3. RFE? Create fixed ModelAndView in XML
    By wangjammer5 in forum Container
    Replies: 4
    Last Post: Oct 5th, 2005, 09:07 AM
  4. simpleformcontroller & modelandview
    By yuer2084 in forum Web
    Replies: 2
    Last Post: Jul 27th, 2005, 04:07 AM
  5. Replies: 2
    Last Post: Dec 22nd, 2004, 01:13 PM

Posting Permissions

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