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