Spring MVC - access model attributes inside a scriplet

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.
lotrzzAsked:
Who is Participating?
 
objectsConnect With a Mentor Commented:
> return new ModelAndView("view1", "model", model);

change that to:


return new ModelAndView("view1", model);
0
 
lotrzzAuthor Commented:
I meant, If I do  <c:out value="${model.attr1}"/>  in jstl,  I can see the value.
0
 
lotrzzAuthor Commented:
Any help would be appreciated
0
 
Sathish David Kumar NArchitectCommented:
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
 
Sathish David Kumar NArchitectCommented:
String attr1Val = (String)request.getAttribute("model.attr1");
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.