wood burning stoves 2.0*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Result from a servlet is generated to a file but not displayed in browser Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Result from a servlet is generated to a file but not displayed in browser" Watch "Result from a servlet is generated to a file but not displayed in browser" New topic
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Result from a servlet is generated to a file but not displayed in browser
 
Similar Threads
Doubt in servlet program using eclipse IDE
Difficulties with setting up Apache tomcat: 'Need a little help.
Session management - cookies / URL rewriting
Stuck on HelloWorldServlet
Head First BeerSelect problems