Servlet Development Guide : PART II Administration : Chapter 5 Troubleshooting : Browser Displays HTML Code from Servlet
Browser Displays HTML Code from Servlet
Some browsers determine the type of document contained in the response based solely on the Content-Type header of the HTTP response. The Agent does not provide a Content-Type header for a new response. To correct this problem:
• Set the Content-Type to HTML, using the setContentType() function of rwsf::HttpServletResponse in the request handler. The sample below demonstrates setting the response Content-Type to HTML:
 
void MyServlet::doGet(rwsf::HttpServletRequest& request,
rwsf::HttpServletResponse& response)
{
response.setContentType("text/html"); // Add this line
 
// ... existing code here
}
Once the servlet sets the Content-Type to text/html, the browser should correctly display the rendered page.