"[Mina Gohari]" wrote:

>      Hello
>
>      I tried with "application/x-www-form-urlencoded" and
>      "application/x-binary" , but I didn't get html from Servlet.
>
>      I sent to Servlet a serialized object then I want Servlet send a html
>      file to client. but It didn't do correct.
>
>      String htmlPage = new String();
>      htmlPage += "<HTML><HEAD><TITLE>MyServlet</TITLE></TITLE>";
>      htmlPage += "</HEAD><BODY>Test</BODY></HTML>";
>
>      PrintWriter outputToBrowser =  new PrintWriter(res.getOutputStream());
>      res.setContentType("application/x-www-form-urlencoded");
>      //res.setContentType("text/html");
>

For this scenario, you really do want to have the content type set to "text/html",
since that is what your servlet is producing.  Therefore, you would want to
uncomment the line immediately above, and remove the line before that.

>      outputToBrowser.println(htmlPage);
>      outputToBrowser.flush();
>      outputToBrowser.close();
>
>      but this html page doesn't show on client side, any suggestion.
>

You might also want to consider a couple of other things:

* Using a StringBuffer to accumulate the text of your output page
  is much more efficient than String concatenation.

* If you set the content length as well as the content type,
  your servlet engine has the option to take advantage of
  persistent connections defined in HTTP/1.1, which will
  improve performance.

* You are working to hard to create your print writer.

Recasting your code to do these things differently would make it look like this:

    StringBuffer htmlPage = new StringBuffer();
    htmlPage.append("<html><head><title>MyServlet</title></head>");
    htmlPage.append("<body>Test</body></html>");
    htmlPage.append("\r\n");    // Carriage return and line feed

    res.setContentType("text/html");
    res.setContentLength(htmlPage.length());
    PrintWriter writer = res.getWriter();
    writer.print(htmlPage.toString());
    writer.flush();
    writer.close();


>
>      Thanks
>
>      Mina
>

Craig McClanahan

___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".

Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html

Reply via email to