• Post Reply Bookmark Topic Watch Topic
  • New Topic

Servlet is downloaded instead of displaying.

 
owen spalding
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using jdk1.3.1 with tomcat 3.2.1. I am running a basic servlet that when the submit button is pressed it calls the servlet to display the request method. When I press the button to call the servlet a download dialog box opens and asks if I want to save the file or open it. The name of the file is displayed as "BasicServlet000000000". When I select to open it it opens the "open with" box. I select IE and a window opens with the correct information. Does anyone know why it downloads and is there a way to change it?
This is the html code that calls the servlet.
<BODY>
<FORM METHOD=POST ACTION="http://localhost:8080/examples/servlet/BasicServlet">
<BR><BR>
press Submit Query to launch servlet BasicServlet
<BR><BR>
<INPUT TYPE="submit">
<INPUT TYPE="reset">
</FORM>
</BODY>
</HTML>
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try this:
<FORM METHOD=POST ACTION="/examples/servlet/BasicServlet">
I think it´┐Żll work.
 
owen spalding
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That didn't seem to work.
Thanks
 
Venugopal nandikolla
Greenhorn
Posts: 22
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I am sure that in your servlet code is not proper.
response.setContent("text/plain");
correct this ,compile and run your servlet it works fine.
-venu
 
owen spalding
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Venugopal nandikolla:
Hi,
I am sure that in your servlet code is not proper.
response.setContent("text/plain");
correct this ,compile and run your servlet it works fine.
-venu

I made that change and it still opens a download box. Here is my java code.
//BasicServlet
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
public class BasicServlet extends HttpServlet {
public void init (ServletConfig config)
throws ServletException {

// Always pass the ServletConfig object to the super class
super.init(config);
}

//Process the HTTP Get request
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text.plain");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>BasicServlet</title></head>");
out.println("<body>");
//Prints the REQUEST_METHOD sent by the client
out.println("Your request method was " + request.getMethod() + "\n");
out.println("</body></html>");
out.close();
}

//Process the HTTP Post request
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {

response.setContentType("text.plain");
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>BasicServlet</title></head>");
out.println("<body>");
//Prints the REQUEST_METHOD sent by the client
out.println("Your request method was " + request.getMethod() + "\n");
out.println("</body></html>");
out.close();
}
// Get Servlet information
public String getServletInfo() {
return "BasicServlet Information";
}
}
 
owen spalding
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I just saw my problem. I have ("text.plain") instead of ("text/plain"). I will make that change and see if that works.
Thanks
That fixed the problem. I added the "/" and changed the plain back to html and that worked.
Thank you for your help.
[This message has been edited by owen spalding (edited July 12, 2001).]
 
Marcos Maia
Ranch Hand
Posts: 977
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A tip:
Instead of duplicating your code in the doGet and doPost methods you may call the methos from each other
like:

doGet(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
//your code goes here
}
doPost(HttpServletRequest req, HttpServletResponse res)throws ServletException, IOException
{
doGet(req, res);
}
Or vice-versa
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!