File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Access variable value from Java file to Jsp file. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Access variable value from Java file to Jsp file." Watch "Access variable value from Java file to Jsp file." New topic
Author

Access variable value from Java file to Jsp file.

Maria Laxmi
Ranch Hand

Joined: Aug 08, 2008
Posts: 40
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

Joined: Apr 11, 2009
Posts: 31
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
 
subject: Access variable value from Java file to Jsp file.