Solved

spring framework ModelAndView question..

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

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 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 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:
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

911 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

26 Experts available now in Live!

Get 1:1 Help Now