Solved

spring framework ModelAndView question..

Posted on 2006-10-25
3
1,505 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: Postgres Monitoring System

A PHP and Perl based system to collect and display usage statistics from PostgreSQL databases.

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

Title # Comments Views Activity
web application structure 18 115
by zero exception 10 70
Better way to make a string with template variables in java 3 34
difference between sorce folder and folder in eclipise 3 44
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
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:
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

733 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