This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Servlets and the fly likes RequestDispatcher's forward method changes response's content type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "RequestDispatcher Watch "RequestDispatcher New topic
Author

RequestDispatcher's forward method changes response's content type

ht kim
Greenhorn

Joined: Aug 02, 2001
Posts: 7
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

Joined: Jan 29, 2002
Posts: 62
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

Joined: Aug 02, 2001
Posts: 7
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
 
subject: RequestDispatcher's forward method changes response's content type
 
Similar Threads
Default content-type
WAP Gateway for websphere?
forwarding xml cotent from servlet to a jsp
multiple mime types
JSP+XSL -> WML ??