struts-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Ashish Kulkarni <ashish.kulkarn...@gmail.com>
Subject [OT] Return Hashmap java object from servlet
Date Tue, 07 Jul 2009 16:06:10 GMT
HiIs it possible to return Hashmap object from java Servlet,  What kind of
ContentType can i set to the response?

The other option is to set data from HashMap into XML and return it as XML
file.

for example.

I have servlet like below

public class ReturnObjectServlet extends HttpServlet
{
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{

processResponse(request, response);
}

public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{

processResponse(request, response);
}

private void processResponse(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException
{

           Map map1 = new HashMap();
   map1.put("ABC", "XYZ");
   map1.put("ABC2", "XYZ");
   map1.put("ABC3", "XYZ");

        // What kind of response type can i set??
         response.setContentType("text/xml; charset=UTF-8");
         PrintWriter out = response.getWriter();
         out.print(map1);
         out.close();

        }


}

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message