I have a Servlet thats run and takes in data from a web page. Later on in a different set of tasks I want to access this data from a standard Java class and use the data, how would i go about this? Can I save the data anywhere for access?
I have code like this :
String name = request.getParameter("username");
And then I tried to set it as an attribute and pass it :
getServletContext().setAttribute("com.mycompany.app-param", "name");
Then in the next class I tried to access the context to get the varible, but no matter what I tried I got server error 500’s, or null or Server = null. i don’t think it’s able to pick up the context properly :
value = getServletContext().getAttribute("com.mycompany.app-param");
Does anyone know how I can access the context created previously and get its variable?
See Is getServletContext() officially supported in GAE? – on gae it’s not guaranteed to work the way you want it to work (eg to pass on info).
You should use Session or Request scoped attributes instead, see here here and here to get you started. Which one you use depends on the required life time and visibility of the saved attributes (Request < Session < Application)