Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Servlets download instead of displaying

Options
  • 18-04-2007 4:03pm
    #1
    Registered Users Posts: 7,541 ✭✭✭


    Hey all,

    Running some java 1.3 servlets on Oracle Application Server. Having a problem where a servlet that is displayed correctly in IE doesn't work in Firefox 2.0. What happen is that instead of displaying in the FF browser, it asks the user to either open or save it. Most servlets work fine. Can anyone see why? code below:

    [PHP]package ie.boards.servlet;

    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.ServletOutputStream;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    /**
    * Servlet implementation class for Servlet: Test
    *
    */
    public class RedirectServlet extends javax.servlet.http.HttpServlet implements javax.servlet.Servlet {

    public RedirectServlet() {
    super();
    }

    public void destroy() {
    super.destroy();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doAll(request, response);
    }

    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doAll(request, response);
    }

    protected void doPut(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doAll(request, response);
    }

    protected void doAll(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    ServletOutputStream out=response.getOutputStream();
    try{
    out.println("<html>");
    out.println("<head>");
    out.println("<script language=\"javascript\">");
    out.println("function bustOut(){");
    out.println("var newWin = window.open(\"http://x.x.x.x/ie.boards.servlet.MainServlet\", \"appwin\", \"menubar=0,scrollbars=1,status=0,height=715,width=1024\")");
    out.println("self.close()");
    out.println("}");
    out.println("window.onLoad = bustOut;");
    out.println("</script>");
    out.println("</head>");
    out.println("<body onLoad=\"bustOut()\">");
    out.println("MainServlet has opened in another window.");
    out.println("This window can be closed.");
    out.println("</body>");
    out.println("</html>");
    }catch(IOException e){
    System.out.println("IOException: "+e.toString());
    }
    }

    public void init() throws ServletException {
    super.init();
    }
    }[/PHP]


Comments

  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    Um, is it a MIME type thing?


  • Registered Users Posts: 7,541 ✭✭✭irlrobins


    Meaning?


  • Registered Users Posts: 5,379 ✭✭✭DublinDilbert


    Hi,

    I think you need to set the content type to HTML to get it to display in the browser:-

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");

    out.println("</html>");


  • Registered Users Posts: 7,468 ✭✭✭Evil Phil


    We had a problem with stuff being downloaded as cleartext because the MIME type wasn't set on the server.

    <edit>
    Or what Dublin Dilbert said.


  • Registered Users Posts: 5,379 ✭✭✭DublinDilbert


    I'm guessing that once IE see's the first <html> tag it assumes HTML, where as FF doesn't...


  • Advertisement
  • Registered Users Posts: 7,541 ✭✭✭irlrobins


    Hi,

    I think you need to set the content type to HTML to get it to display in the browser:-

    response.setContentType("text/html");
    PrintWriter out = response.getWriter();
    out.println("<html>");

    out.println("</html>");
    Yep that did it. Cheers all. Simple case of leaving out setContentType.


Advertisement