File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

RequestDispatcher's forward method changes response's content type

 
ht kim
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi,
i'm using jakarta-tomcat-4.0.1.
i made servlet code that looks like below,
response.setContentType("text/vnd.wap.wml");
RequestDispatcher rd = getServletContext().getRequestDispatcher("/wml1.jsp");
rd.forward(request, response);
and i requested to that servlet,
browser gets content type "text/html" instead of "text/vnd.wap.wml".
how did i get this unexpected result?
does forward method changed response object's content type?
if then, how can i set the content type correctly
without specifying the content type to jsp file(/wml1.jsp).
 
Napa Sreedhar
Ranch Hand
Posts: 62
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
RequestDispatcher is used to chain servlets.
JSP pages use content type as text/html by default.
Using response.setContentType("text/vnd.wap.wml") in the JSP page may produce the desired result.
Napa
 
ht kim
Greenhorn
Posts: 7
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
yes you are right.
i just checked the java file interpreted from the jsp out. and there was setContentType method calling like this.
response.setContentType("text/html;charset=ISO-8859-1");
so setContentType before jsp executing was overwritten.
thanks napa.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic