• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Access variable value from Java file to Jsp file.

 
Maria Laxmi
Ranch Hand
Posts: 40
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I am having a trouble using a session scope variable. My requirement is to access a variable value in jsp which is defined in the java class. I am using spring ModelAndView controller. Here is the scenario.

There is a method defined in one java file.

method public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response, Object command, BindException errors) throws Exception{

Long[] var1 = form.getCommand().getSelectedIds();
}
I want to use the value of var1 in jsp file. And it should be in session scope.I tried below code but didn't work.
mv.addObject("var1Value", var1) in java file; and then tried to access it from jsp.

I am new to J2EE, and unable to figure out what is the problem? and how can I solve this?

Thanks.
 
chetan agg
Ranch Hand
Posts: 31
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this in java file

request.getSession().setAttribute("key" , value);


in jsp, (String)session.getAttribute("key");

Regards,


 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic