Solved

spring framework ModelAndView question..

Posted on 2006-10-25
3
1,499 Views
Last Modified: 2008-01-16
Hi,

    In my controller object, it creates a ModelAndView object and invoke the following methods:

ModelAndView mv = new ModelAndView("hello");
mv.addObject(req);
mv.addObject(resp);
mv.addObject(ctx);


I would like to know how to access these objects (i.e. req, resp, ctx) in my JSP??
Thanks.
0
Comment
Question by:zollen
  • 2
3 Comments
 
LVL 9

Expert Comment

by:shinobun
ID: 17806502
You should use the ModelAndView#addObject(String, Object) [1] method instead.

mv.addObject("req", req);
mv.addObject("resp", resp);
mv.addObject("ctx", ctx);

[1] http://www.springframework.org/docs/api/org/springframework/web/servlet/ModelAndView.html#addObject(java.lang.String,%20java.lang.Object)
0
 

Author Comment

by:zollen
ID: 17808369
But how do I access req, resp and ctx objects in my JSP????
0
 
LVL 9

Accepted Solution

by:
shinobun earned 50 total points
ID: 17808470
They are put in the ServletRequest as attributes.  Use the ServletRequest#getAttribute(String) method [1] to access them:

request.getAttribute("req")
request.getAttribute("resp")
request.getAttribute("ctx")

[1] http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletRequest.html#getAttribute(java.lang.String)
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

809 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question