Solved

Spring MVC - access model attributes inside a scriplet

Posted on 2011-03-10
5
1,867 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

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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:

708 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

20 Experts available now in Live!

Get 1:1 Help Now