是否可以在Java中将HashMap存储到ServletContext中?当我去获取属性返回它是一个字符串...有没有办法将其转换回HashMap?其技术上可能存储一个HashMap在ServletContext中?
HashMap<Integer,ArrayList<byte[]>>
我设置属性是这样的:
event.getServletContext().setAttribute("Banners", getAllBanners());
的方法getAllBanners()返回一个HashMap<Integer, ArrayList<byte[]>>
对象。然后,当我想访问它,我称之为:
event.getServletContext().getInitParameter("GBPBanners");
编辑**
明白了HashMap <Integer, ArrayList<byte[]>> myMap = (HashMap<Integer,ArrayList<byte[]>>) event.getServletContext().getAttribute("Banners");
你能后你使用的代码?你有可能把错误的东西拉回来。什么是字符串值? – roberttdev 2011-03-26 21:12:43
我不确定,但也许你可以序列化HashMap对象,并在需要时检索它! – 2011-03-26 21:15:31