Win a copy of OCP Oracle Certified Professional Java SE 11 Programmer I Study Guide: Exam 1Z0-815 this week in the Programmer Certification forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Liutauras Vilda
  • Junilu Lacar
  • Jeanne Boyarsky
  • Bear Bibeault
  • Knute Snortum
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Ron McLeod
  • Carey Brown
  • Paweł Baczyński
  • Piet Souris
  • Vijitha Kumara

Pls help with HttpSession in SpringMVC Model

Ranch Hand
Posts: 180
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have a class extends Controller and return the ModelAndView
I want to somehow session the object that I invoke from the method that call the web-service. How or what i have to do. Here is the snipet code that I wrote

HttpSession session = request.getSession(true);
session.setAttribute("someString", this.getWebService()) // invoke a method to return a Collection from webservice
if (action == "none")
// in here i want to get the session and get the data again from the session?

ArrayList arrList = (ArrayList) session.get(someString)? // is this right?

Greatly appreciated with your help
Ranch Hand
Posts: 73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
//put something in the session
HttpSession session = request.getSession();
session.setAttribute("myIdentifier", myObject);

// get something out of the session

MyObject myObj = (MyObject) session.getAttribute("myIdentifier");

The only thing I saw in your code that looks odd is
if(action == "none")

If you're comparing 2 strings use the .equals()

... do somethign here.
And then we all jump out and yell "surprise! we got you this tiny ad!"
Java file APIs (DOC, XLS, PDF, and many more)
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!