Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Result from a servlet is generated to a file but not displayed in browser

 
kai wen ham
Greenhorn
Posts: 5
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear fellow java programmer,

I am studying the Java Servlet Programming Bible (by Suresh Rajagopalan) book and I am working on some examples in the book.

Sometimes, on my pc, the result is not displayed in browser but generated in a file to be downloaded.

I have included the screenshot of the output:
http://www.kaiwenham.com/misc/servlet.html

Below is one of the examples:

package servletbible.ch03.examples;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class GetParameterExample extends HttpServlet
{
public void service(HttpServletRequest httpRequest , HttpServletResponse httpResponse) throws
ServletException , IOException
{
// Set the content type of response
httpResponse.setContentType("text/plain");
// Attach the response to PrintWriter object
PrintWriter outputStream =
httpResponse.getWriter();
// Get the value of the parameter named MyParameter
String parameterValue =
httpRequest.getParameter("MyParameter");

if (parameterValue == null)
{
outputStream.println(" The request does not contain any parameter" ) ;
}
else
{
outputStream.println(" The value of the parameter MyParameter is " + parameterValue ) ;
}
outputStream.close();
}

}

I was wondering if anyone of you have this experience? Please let me know what should I do to let the result behave normally like what is shown on the example.

I am using Tomcat.

Thank you!

Sincerely,
Kai Wen Ham
 
siva raju
Ranch Hand
Posts: 37
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A long shot, but try changing the contextType to text/html and check.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic