I, too, have a servlet that runs quickly using GET, but takes many seconds
using POST. I have not tried to analyze the problem any farther than noticing
that it takes a long time to run, and it takes a long time to send back
the result. I am using jserv-1.0b2.

Jeff Finger
[EMAIL PROTECTED]

> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED]]On Behalf Of Ross J.P.
> Ethier
> Sent: Tuesday, April 06, 1999 6:24 AM
> To: Java-Servlets
> Subject: Re: Re: Repy time of the HTML POST command
>
>
> I see why you want to write to a buffer to ultimately determine and provide
> the
> content length of the served page.
> Why don't you try this  instead
>
> public class MessageServlet extends HttpServlet   //implements
> SingleThreadModel - don;t need to be single threaded for this
> {
>
>         // private ServletConfig config;  = no need to store this, your parent
> does.
>
>         // you don;t seem to need this method since you do nothing with the
> config
>         //public void init (ServletConfig config) throws ServletException
>         //{
>         //      super.init(config);
>                 // this.config = config;
>         //}
>
>         // no need to overide this method.
>         //public void destroy() {} // do nothing
>
>         // no need to overide this method.
>         //public ServletConfig getServletConfig()
>

>         //      return config;
>         //}
>
>
>         public String getServletInfo()
>

>                 return "User Interface Servlet"
>         }
>
>         public void doPost (HttpServletRequest req, HttpServletResponse res)
>                 throws ServletException, IOException
>         {
>             res.setContentType( "text/html" );
>             StringBuffer html = new StringBuffer();
>             html.append( "<html>" );
>             html.append( "<head>" );
>             html.append( "<title> Message </title>" );
>             html.append( "</head>" );
>             html.append( "<body>" );
>             html.append( "Hello World!" );
>             html.append( "</body>" );
>             html.append( "</html>" );
>             res.setContentLength(html.length());
>             PrintWriter out = res.getWriter();
>             out.println(html.toString());
>
>             // no need to flush nor close
>       }
> }
>
>
>
>
>
> At 11:39 AM 4/6/99 +0200, you wrote:
> >Thanks for your reply.  But that was not the reason of my problem. I
> >tried to write a servlet beeing as simple as possible:
> >
> >package de.medigration.telechiv.UI_Servlets;
> >
> >/*
> > * Imports
> > */
> >import java.io.*;
> >import java.util.Date;
> >import javax.servlet.*;
> >import javax.servlet.http.*;
> >
> >public class MessageServlet extends HttpServlet
> >                        implements SingleThreadModel {
> >    private
> >        ServletConfig config;
> >
> >    public void init (ServletConfig config)
> >        throws ServletException {
> >            this.config = config;
> >    }
> >
> >    public void destroy() {} // do nothing
> >
> >    public ServletConfig getServletConfig() {
> >        return config;
> >    }
> >
> >    public String getServletInfo() {
> >        return "User Interface Servlet"
> >    }
> >
> >
> >    public void doPost (HttpServletRequest req,    HttpServletResponse
> >res)
> >        throws ServletException, IOException {
> >
> >            /* Create Output Writer */
> >            res.setContentType( "text/html" );
> >            ByteArrayOutputStream outBuffer = new ByteArrayOutputStream
> >(255);
> >            PrintWriter out = new PrintWriter(outBuffer, true);
> >
> >            /* Write Head of HTML-Page */
> >            out.println( "<html>" );
> >            out.println( "<head>" );
> >            out.println( "<title> Message </title>" );
> >            out.println( "</head>" );
> >
> >            out.println( "<body>" );
> >
> >            out.println( "Hello World!" );
> >
> >            out.println( "</body>" );
> >            out.println( "</html>" );
> >
> >            res.setContentLength(outBuffer.size());
> >            outBuffer.writeTo(res.getOutputStream());
> >            out.close();
> >    }
> >}
> >
> >
> >> -----Ursprüngliche Nachricht-----
> >> Von: Ross J.P. Ethier [SMTP:[EMAIL PROTECTED]]
> >> Gesendet am: Dienstag, 6. April 1999 08:35
> >> An:  Java-Servlets
> >> Betreff:     Re: Repy time of the HTML POST command
> >>
> >> Its hard to determine why your page takes so long.  Perhaps providing
> >the
> >> source may help.
> >>
> >> A performance tip is to use a StringBuffer to append the html instead
> >of
> >> using the '+' operand.
> >>
> >> instead of
> >>      out.println( "<html>" + "<body>" + "hello" + "</body>" +
> >"</html>");
> >> use
> >>      out.println( new StringBuffer("<html>").append("<body>"
> >> ).append("hello").append("</body>" ).append("</html>").toString());
> >>
> >> Internally the JVM turns every '+' call into a two part StringBuffer
> >which
> >> can be expensive.
> >>
> >> Good Luck
> >> Ross
> >>
> >> At 05:00 PM 3/31/99 +0200, you wrote:
> >> >Hello,
> >> >
> >> >I wrote a servlet which is started as a 'startup servlet' (I proved,
> >> >that it is initialized only once!). This servlet is invoked by a HTML
> >> >POST command from a browser (HTML form). It generates a new HTML page
> >> >using the 'PrintWriter'-class. My problem:
> >> >
> >> >IT LASTS 5 SECONDS FROM SUBMITTING THE FORM TO GETTING THE RESPONSE.
> >> >(Although browser and server are running on the same PC)
> >> >
> >> >Is this an usual delay? How can I get a better performance?
> >> >
> >> >(I used the APACHE1.3.4 server , ApacheJServ1.0b1 and JSDK 2.0 with
> >> >WindowsNT 4.0)
> >> >
> >> >Best regards
> >> >
> >> >Burkhard Schaefer
> >> >
> >> >
> >> >____________________________________________________________
> >> >
> >> >Medigration GmbH                    Tel.: (++49) 09131-690-87-47
> >> >Am Weichselgarten 7                 Fax: (++49) 09131-690-8750
> >> >D-91058 Erlangen                    www.medigration.de
> >> >GERMANY
> >> >
> >> >
> >> >------------------------------------------------------------
> >> >To subscribe:    [EMAIL PROTECTED]
> >> >To unsubscribe:  [EMAIL PROTECTED]
> >> >Problems?:       [EMAIL PROTECTED]
> >> >
> >>
> >>
> >>
> >> ------------------------------------------------------------
> >> To subscribe:    [EMAIL PROTECTED]
> >> To unsubscribe:  [EMAIL PROTECTED]
> >> Problems?:       [EMAIL PROTECTED]
> >
> >
> >------------------------------------------------------------
> >To subscribe:    [EMAIL PROTECTED]
> >To unsubscribe:  [EMAIL PROTECTED]
> >Problems?:       [EMAIL PROTECTED]
> >
>
>
>
> ------------------------------------------------------------
> To subscribe:    [EMAIL PROTECTED]
> To unsubscribe:  [EMAIL PROTECTED]
> Problems?:       [EMAIL PROTECTED]
>



------------------------------------------------------------
To subscribe:    [EMAIL PROTECTED]
To unsubscribe:  [EMAIL PROTECTED]
Problems?:       [EMAIL PROTECTED]

Reply via email to