Announcement Announcement Module
Collapse
No announcement yet.
ModelAndView Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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
    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.

    Comment


    • #3
      hai Chris,

      Thanks a lot. That was of great help.

      regards,
      nisha

      Comment


      • #4
        Re: ModelAndView

        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~

        Comment

        Working...
        X