0

I have the following servlet code to store a data for a specific reason and later I retrieve the same data in another scenario in a project. It works fine as expected.

// setting 
   ServletContext context = request.getSession().getServletContext();
    context.setAttribute("imageData", data);

    // retrieving ...
    ServletContext context = request.getSession().getServletContext();
byte[] data = (byte[])context.getAttribute("imageData");

Now, In an another project, where I use plain java program, where I want to store data similar to this servlet logic. I tried using the same code in plan java project, but it throws error, not accepting this servletcontext in plan java file.

Could someone please help, 1.) what is the equivalent in plan java to store like this temporarily or 2.) How to make that servletconext code working in plain java ?

Thank you in advance!

  • Getsy
Getsy
  • 4,887
  • 16
  • 78
  • 139

2 Answers2

1

How about simple HashMap<String, Object>

jmj
  • 237,923
  • 42
  • 401
  • 438
  • http://stackoverflow.com/questions/3995463/how-can-i-iterate-over-a-map-of-string-pojo – jmj Feb 07 '14 at 07:59
  • Please help on this as well-> http://stackoverflow.com/questions/21624479/java-applet-java-applet-to-receive-data-from-socket – Getsy Feb 07 '14 at 09:55
0

You can consider using simply a HashMap in the applet context. If you need to use the same code in applet and web contexts, add a layer of abstraction and two implementations to manage the attributes depending on the context.

Guy Bouallet
  • 2,099
  • 11
  • 16