开发者

How to return an object to the user in the java server programming

I have a java servelet segment, which can generate a XML file and print it out on the screen.

The related code are giving as follows

public void handle(String target,
                   Request baseRequest,
                   HttpServletRequest request,
                   HttpServletResponse response) 
    throws IOException, ServletException
{
    response.setContentType("text/html;charset=utf开发者_如何转开发-8");
    response.setStatus(HttpServletResponse.SC_OK);
    baseRequest.setHandled(true);

          // some code to generate process

             PrintWriter out = response.getWriter();
     // the object of “process” is serialized to generate XML file
     process.serialize(out);
     out.println(process);
     out.close();            

}

Right now, I need to return this process object to the user, how should I do that? Thanks.


Depending on the type of the "process" object you could use a library like XStream to create a simple XML document. Of course, if it is of type Process then your results might be very surprising; in this case there is probably very little information you could serialize and return.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜