Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Spring MVC - access model attributes inside a scriplet

Posted on 2011-03-10
5
1,987 Views
Last Modified: 2012-05-11
how do I get model attributes inside a scriplet tags in a jsp?

In my controller, I am setting the model attributes
model.setAttribute("attr1", attrVal1);
....

return new ModelAndView("view1", "model", model);

In view1.jsp,  I have

<%
String attr1Val = (String)request.getAttribute("attr1");

%>


The attr1Val is coming as null , what am I missing?  However, if i do  <c:outvalue="$model.attr1"/>  in jstl,  I can see the value.
0
Comment
Question by:lotrzz
  • 2
  • 2
5 Comments
 

Author Comment

by:lotrzz
ID: 35095326
I meant, If I do  <c:out value="${model.attr1}"/>  in jstl,  I can see the value.
0
 

Author Comment

by:lotrzz
ID: 35096157
Any help would be appreciated
0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35097535
What is value for attrVal1?  why set that in model directly set that value in request parameter then only you can get the value  

String attr1Val = (String)request.getAttribute("attr1");

but your setting in model so you cant get the value directly !

0
 
LVL 20

Expert Comment

by:Sathish David Kumar N
ID: 35097549
String attr1Val = (String)request.getAttribute("model.attr1");
0
 
LVL 92

Accepted Solution

by:
objects earned 50 total points
ID: 35099680
> return new ModelAndView("view1", "model", model);

change that to:


return new ModelAndView("view1", model);
0

Featured Post

Master Your Team's Linux and Cloud Stack

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The viewer will learn how to implement Singleton Design Pattern in Java.
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 …

839 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