Solved

spring framework ModelAndView question..

Posted on 2006-10-25
3
1,489 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

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
This theoretical tutorial explains exceptions, reasons for exceptions, different categories of exception and exception hierarchy.

746 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now