| Author |
Result from a servlet is generated to a file but not displayed in browser
|
kai wen ham
Greenhorn
Joined: Sep 28, 2003
Posts: 5
|
|
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
Joined: Oct 10, 2003
Posts: 37
|
|
|
A long shot, but try changing the contextType to text/html and check.
|
Siva<br />-----<br />SCWCD 1.4, SCJP 1.4, SCBCD(Preparing), CCNA
|
 |
 |
|
|
subject: Result from a servlet is generated to a file but not displayed in browser
|
|
|