简体   繁体   中英

How parse object in HttpServletResponse?

I have a problem when I try to encode object in http response. I do not know how to do it. I will have use the header?

public class Download extends HttpServlet{


    public void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException{


        PersistenceManager pm = PMF.get().getPersistenceManager();

        String method = req.getParameter("method");

        if(method.equals("view")){
            Query query = pm.newQuery(Article.class);
            List<Article> articles=null;

            try {
                articles=(List<Article>) query.execute();
                }
                finally {
                query.closeAll();
                }
                Article article= art.get(0);
                res.setContentType("application/octet-stream");//??
                //problem here



        }
    }

}

There is a setHeader() method on the HttpServletResponse class. For example, you can set the content type using the following statement:

response.setHeader("Content-Type", "text/html"); 

Here is a link with a good tutorial on the topic: http://tutorials.jenkov.com/java-servlets/httpresponse.html

Here is the JavaDoc on the class if you need more parameters:

http://docs.oracle.com/javaee/6/api/javax/servlet/http/HttpServletResponse.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM