Results 1 to 7 of 7

Thread: Simple question - access object in jsp passed from modelAndView

  1. #1
    Join Date
    Sep 2011
    Posts
    18

    Default Simple question - access object in jsp passed from modelAndView

    Hi all!
    I just need to access object, doplnokList which is LinkedList, passed from controller method

    [...]
    return new ModelAndView("hello","doplnokList",doplnokList);

    to jsp page and access it in <% %> tag. Perhaps write its content to out.

    Thanks for help!

  2. #2
    Join Date
    Aug 2010
    Location
    Broomfield, CO
    Posts
    20

    Default

    <% %> are scriptlet tags and should at this point (read: 2011) be avoided unless absolutely necessary. Scriptlets were the thing back in the day. You should now use either EL or JSTL (or some other variant) to render the items.

    Using your example code, in your JSP, you would simply use "${hello}" to de-reference the value you set in your controller - in this case, the String "hello".

  3. #3
    Join Date
    Sep 2011
    Posts
    18

    Default

    They should not be used? Too bad, I was happy to have casual java syntax there.
    Anyway according t omy example it should be ${doplnokList} cause 'hello' is view name but its not working...

  4. #4

    Default

    can you post the jsp code ?
    mmmm, I think I will order a cup of coffee in this beautiful spring day

  5. #5

    Default

    Out of curiosity, can you try the following in your Controller and see if that works.

    ModelAndView mav = new ModelAndView("hello")
    mav.addObject("doplnokList",doplnokList);
    return mav;

  6. #6
    Join Date
    Sep 2011
    Posts
    18

    Default

    Quote Originally Posted by litterat View Post
    can you post the jsp code ?
    no, I can't cause jsp code is what Im looking for

  7. #7
    Join Date
    Sep 2011
    Posts
    18

    Default

    Quote Originally Posted by knoxor View Post
    Out of curiosity, can you try the following in your Controller and see if that works.
    its working like this:
    code:
    Code:
    ModelAndView mav = new ModelAndView("hello");
    		
    		
    	mav.addObject("variable", "some");
    		
    		
    	return mav;
    jsp:
    Code:
    ${variable}
    output:
    [...]
    some
    [...]

Posting Permissions

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