### URGENT: duplicated servlet output ###

Hi,
I'm usin cos.jar of servlets.com for file uploading. But, sometimes, the output of my servlets are duplicated. This problem doesn't occur everytime even if for the same uploaded files. Also, When I encounter this problem on my desktop, It runs on the other desktops without any problem.
I'm sure that lines of uploaded files are not re-read/re-processed twice immediately. Because, may applications would return errors in that case. But, if entire file is re-read/re-processed, there would not be errors returned.
Here are my configuration:
Browser:Internet Explorer 5.0
OS: Windows 2000 Professional
Servlet Engine: Resin 2.1.9
Please help...This is very important problem. Because, the output of our sevlets are duplicated.
thanks in advance...

Thanks for the reply.
I'm sure this is not a thread synchronization problem.
Here is the doPost():
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
itrprofThread iThread;
iThread = new itrprofThread(request,response);
iThread.start();
try {
iThread.join();
} catch (InterruptedException e) {}
I'm sure that uploaded file is processed twice after the first entire process of the file is finished. Here is the proof:
CORRUPTED LINEs AND THEIR DEPENDENTs (2 of 2)
Errror code Line number Line
itp-05 [2] 99 WAIT #0: nam='SQL*Net message from client' ela= 98956 p1=1413697536 p2=1
itp-05 [2] 353 WAIT #0: nam='SQL*Net message from client' ela= 98956 p1=1413697536 p2=1
As you see above, the lines are the same lines. In fact, it's single line in the uploaded file. But, If you notice the line numbers of the lines, they are different. The first line number is correct. But, the second is wrong. Because, second line is duplicated.
Also, There are 252 lines in the file. But, line number of the second line is reported 353. This is not possible.
I'm now sure that uploaded file in the second phase is processed after the first phase is completed. Because:
Line number in the first phase: 99
Total line number in the file: 252
Line number in the second phase: 353
If I sum 99 and 252, it gives 351. It's proof the entire file is processed twice after the first phase is completed.
is is possible to see the contents of HTML form data before sending to servlet ?
PLEASE HELP, THIS IS VERY IMPORTANT PROBLEM.

Similar Messages

  • Servlet output not displayed properly in Internet Explorer

    Hi All,
    I'm developing a servlet which uploads a file. After the servlet parses the request body, it stores the file contents as a binary string in the database. While displaying the contents of the attached file, the IE(Internet Explorer) is ignoring all the newlines and spaces. IThe same uploaded file when viewed through Firefox browser is being displayed properly. I've added some debug statements to print the filecontent before sending it to servlet output stream. They look exactly as they were in the uploaded file. The MIME type is application/octet-stream.
    I've also made the response to accept "ISO-8859-1" and "UTF-8" charsets, yet the IE is not rendering the file contents properly. The code looks like this,
    response.setContentType("text/html; charset= ISO-8859-1, UTF-8");
    byte[] buff = attachment.getAttachObject();
    OutputStream out = response.getOutputStream();
    out.write(buff);
    out.close();
    I've tried using PrintWriter also. I've tried changing the content types, character encodings of request and response objects, still couldn't resolve the issue. What really baffles me is that when it's displaying properly in Firefox, why can't it render properly in IE? I'm using Win XP SP2, and IE version is 6.0.29. The content which is being sent to the output stream contains newline and space characters, but they are not displayed in the browser. Did any one face this sort of issue? Your help is highly appreciated.
    Thanks,
    Tarun.

    Hi,
    Thanks for looking into the issue. Let me tell you that I've tried keeping various content-types like text/plain, text/xml etc, but in none of those cases the IE rendered the output properly. But with the same content-type i.e text/html or text/plain, Firefox is able to render the file content properly. I've tried a brutal force approach like below,
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    String str = new String(attachment.getAttachObject());
    char[] buff = str.toCharArray();
    for(i=0;i< buff.length; i++)
    int n = (int)buff;
    if(n == 10)
    out.println();
    else
    out.print(buff[i]);
    out.close();
    I was trying to print a newline whenever I find a newline character in the file content. Even this didn't work. Please suggest me some way to get rid of this problem.

  • Converting servlets output to PDF fle

    How to convert Java Servlets output html file to PDF file or a Word document.

    not sure what u mean by 'convert' the output to PDF or word document
    Do you mean you want to force the browser to open file using MSWord / PDF viewer? If yes :
    For showing output as a word document, you can set the servlet response MIME type to 'application/ms-word' and set its extension to .rtf . You can then use a RTF template to build servlet output (since RTF is flat file format). By replacing placeholder tags in RTF template, you can generate content.
    For showing output as PDF, you'll need some library for PDF writing.
    hth,
    Subodh

  • Read Servlet output stream

    how can i read servlet output stream

    i m using SAX to create an XML.
    I set result to "Servlet Output Stream" as shown below :->
    SAXTransformerFactory saxTF = SAXTransformerFactory.newInstance();
    TransformerHandler th = saxTF.newTransformerHandler();
    Transformer t = th.getTransformer();
    StreamResult stRes = new StreamResult(res.getOutputStream());
    th.setResult(stRes);
    th.startDocument();
    what i want to wright the same xml result in file at the same time(parallel y).

  • Servlet Output Streams and clearing

    I am using servlets, and I want to be able to print something repeatedly. Well, that's not exactly true: I can print something repeatedly. Using a ServletOutputStream, it doesn't seem possible to clear what has already been written. Here's the code:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.util.*;
    import java.io.*;
    public class AlwaysTime extends HttpServlet {
         public void doPost(HttpServletRequest req, HttpServletResponse res)                throws ServletException, IOException {
              HttpServletResponse oldRes = res;
              Date now = new Date();
              res.setContentType("text/html");
              ServletOutputStream out = res.getOutputStream();
              out.println("<html>");
              out.println("<head>");
              out.println("<title>Clock</title>");
              out.println("</head>");
              out.println("<body>");
              out.println("<h1 align=\"Center\">");
              out.println(now.toString());
              out.println("</h1>");
              out.println("</body>");
              out.println("</html>");
              try {
                 Thread.sleep(1000);
              } catch (InterruptedException ie) {}
              // Do nothing: wait for 1 second.
              doPost(req, oldRes);
         public void doGet(HttpServletRequest req, HttpServletResponse res)
              throws ServletException, IOException {
              doPost(req, res);
    }This code prints the time every second, but I want to clear the previous output stream. I thought the code shown above would work, but of course, oldRes points to the same object as res. But I don't know how to clear an output stream, so that it is completely empty. Instead, each of the new lines are appended to the same output stream.
    This doesn't only apply to servlet output streams: is there some way to clear the System output stream, for instance?
    But mainly the servlet output stream ...

    You would not want to use HTTP for this type of functionality. HTTP is known as a 'stateless' protocol that simply returns one exact response for each request. So, there is not way to 'clear' the stream (technically, you would not do so for 'normal' streams either, but when you add HTTP into the mix, the task is definitely not possible).
    You could implement the above using a RSS feed, or by using HTTP meta-refresh tags on the page itself ot resubmit the requests every second (though this would be inefficient). An applet would also do the task.
    - Saish

  • Very urgent: call servlet from JSP

    Hello,
    I'm facing a problem in invoking a servlet from a JSP having the JSF components.
    The application has a text field to implement ajax for search functionality in the database .I have written a servlet to make the database connection and fire the querry.
    Ajax implementation in a js file is called on every keyup event in the jsp file,and
    a call is given to the servlet from the ajax methode.
    The function in the js file is as follows:-
    function getPersonByFirstNameXML( firstName ) {
        if (!firstName) {
            clearPersonByFirstNameXML();
        } else {   
            var url = BASE_URL + "/servlet/get_PersonsXML";
            alert(url);
            return new AJAXRequest("post", url, "firstName=" + encode(firstName), processGetPersonByFirstNameXML);
    }Im getting the myAJAX.status value as 500.
    I think I'm not able to access the servlet properly.
    what changes do i need to make in the we.xml file ?
    and what should be the url to be passed.
    Please provide me a sloution to the above problem as it is very urgent else if anybody is aware of a readymade JSF componet with search functionality freely available please let me know.
    PS:
    The sample application named RedirectionExample which makes use of a servlet and would be of help to you. You can find the tutorial on the following page:
    http://developers.sun.com/prodtech/javatools/jscreator/reference/codesamples/sampleapps.html
    is not available as stated in some of the suggestions by Author: mayagiri
    Thanks for any help.
    Abhi

    the status 500 generally means either HTTP server internal error or that execution of CGI script or servlet aborted with error.
    It can be reasonably supposed that the request reaches the servlet, ie. that "url" value points to some existing servlet, otherwise most probably the status value would be 404.
    To test that the servlet is working i'd try to access it using some simple html page with form like this (with {BASE_URL} replaced by real value):
    <form method=post action={BASE_URL}/servlet/get_PersonsXML>
    <input type=text name=firstName>
    <input type=Submit>
    </form>

  • Servlet  output correct in ie and netscape, but not in portal

    I have a servlet that retrieves and xml document, applies a
    stylesheet, and uses PrintWriter to output the html.
    When I run the servlet, the output is correct in ie and netscape.
    So, I set the servlet up as a web portlet and have put it on a
    portal page.
    My problem: When I run the portal page, the mdashes and
    rsquotes, etc. show up in portal as question marks.
    I went into the provider.xml and added some information
    (contentType,charset), but that had no effect.
    Ideas appreciated.
    Thanks.

    I have been doing some research, and this appears to be some
    sort of character encoding/unicode problem.
    I have specified UTF-8 in my servlet. Does portal not work with
    UTF-8?
    Is there a setting somewhere that I can check in portal to
    verify what character encoding it is using? (ISO-8859-1, US-
    ASCII, etc?)
    This is a sample of my servlet code:
    public void DoGet(HttpServletRequest request, HttpServlet
    Response,response)
    throws ServletException, IOException
    DOMParser parser;
    XMLDocument xml,xsldoc;
    URL xslURL,xmlURL;
    String xmld = "";
    String xsld = "";
    response.setContentType("text/html;charset=UTF-8");
    PrintWriter out = response.getWriter();
    try
    parser = new DOMParser();
    parser.setPreserveWhitespace(true);
    xslURL = createURL(xsld);
    parser.parse(xslURL);
    xsldoc = parser.getDocument();
    xmlURL = createURL(xmld);
    parser.parse(xmlURL);
    xml = parser.getDocument();
    XSLStylesheet xsl = new XSLStylesheet(xsldoc,xslURL);
    XSLProcessor processor = new XSLProcessor();
    processor.processXSL(xsl,xml,out);
    Any advice appreciated.

  • REG:SERVLET OUTPUT STREAM

    I am trying to implement upload/view functionality..To view an uploaded txt file or html file,I am just flushing out the file contents into servlet's output stream..The content type has been set appropriately.
    The problem is for some html files ia m able to see the file contents in the browser,and for some html files,the browser displays a open/save dialog box..
    Can any1 explain me why this discrepency?Its the sam e code and same content type..why is it so?

    Thanks for ur reply...
    All i mentioned was in the same browser..PFB the code snippet
         ServletOutputStream pic = null;
         pic = response.getOutputStream();
         ByteArrayOutputStream baos = new ByteArrayOutputStream();
         byte b[] = new byte[5*1024];
         while(true)
              int bytes = in.read(b);
              if(bytes == -1)
                   break;
              baos.write(b, 0, bytes);
         response.setContentLength(b.length);
         b = baos.toByteArray();
         pic.write(b, 0, b.length);
         pic.flush();
         pic.close()

  • How to set NLS character set for report 9i servlet output?

    Hi,
    I am running a Reports 9i report. My problem is that the output HTML file is UTF8 encoded while ALL my 9iASR2 registry setting are set to EEISO8859P2. When I issued the http://&lt;host:port&gt;/reports/rwservlet/showenv?server=servername command it returned that the NLS setting is UTF8.
    Can somebody please help me, how to set this environment variable for the report servlet to EE..P1? Thank you in advance.
    Regards,
    Tamas Szecsy

    Dmitry,
    recently I got this from Oracle support. :-(. Currently when I set the Windows 2000 local and default local to Hungarian and the charset to EE..P2 then I get Central-European encoded charset. I think you will have to experience around to get correct result (if it is possible at all).
    +++++++++++++++++++++++++++++++++++++++++++++++++++++
    This is bug Number 2472932 NLS:RWSERVLET SETS INVALID CHARSET AT THE HTTP HEADER
    marked as fixed in 9.0.2.2 . unfortunately this bug is not published so I will not be able to sent you the bug as a whole but here is problem description in bug:
    iAS9.0.2.0.1 (Reports9.0.2.0.1) on Solaris2.8
    Running rdf with rwservlet sends the invalid charset at the http header.
    Say ias is up with LANG=C, http header for the rwservlet
    is always sent as "iso-8859-1" regardless of rwserver's NLS_CHARACTERSET.
    This is the TCP/IP packet for the GET /reports/rwservlet?report=xxx&....
    HTTP/1.1 200 OK Date: Sat, 20 Jul 2002 01:15:37 GMT Cache-Cont
    rol: private Content-Language: en Server: Oracle9iAS/9.0.2 Ora
    cle HTTP Server Oracle9iAS-Web-Cache/9.0.2.0.0 (N) Content-Leng
    th: 6908 Content-Type: text/html; charset=ISO-8859-1 Set-Cooki
    In this example, to produce a html with other charset than
    iso-8859-1,usually the outputted html has the charset information at
    meta tag by setting "Before Report Value" property in rdf.
    However charset in meta tag is less priority than http header, browser
    such as IE6 or Netscape7 firstly displays the page in iso-8859-1.
    Hence the characters other than iso8859p1 gets garbage.
    To workaround it with IE6/NS7, set proper encoding manually.
    ('View'-'Encoding' for IE 'View'-'Character coding' for NS7 )
    However, NS4.7 does not have workaround for it.
    Besides, starting opmn in LANG=ja, the rwservlet's http header becomes
    Shift_JIS!!. Thus rwserver seems to set the http header based on the
    LANG on Solaris.
    To fix these issues,
    - The http header for rwservlet shold be based on the nls_characterset
    for the rwserver.
    This is no problem for reprots jsp run.

  • IE fails handing servlet output to plugin (netscape does)

    My servlet returns a file to the browser that a browser plugin is required to display. If I request the file using a GET from IE (5.0 or 5.5), the file is sent 2X from the servlet but does get displayed. This is fine for my test servlet, but my application can't handle being asked 2x for the same thing.If I use a POST, it only sends the file one time but fails to hand it off to the plugin and generates the Plugin Error dialog "The data that the plugin requested, did not download successfully". Everything works fine with netscape. I had someone test my servlet using IIS and JRun and they said it worked fine, so that pointed me to Weblogic.Thanks
              

    Hi
    A very interesting problem. Browsers handle html is different ways. IE may be rearranging the HTML removing the white space in between whereas Netscape might not.
    The best way to attack this problem is append the Html output into a String object as your processing moves through different stages. Now you can try printing it to the console or to a Log file once you are done. Alternately you can check to see the length of content if it matches the length of content which is printed out from a "view source" on IE.
    This is only to eliminate the probability of accidental appending of invisible characters during processing which the browsers might be auto correcting.
    I would think this process would help you to resolve the issue even though the problem may be somthing else.
    Keep us posted.
    Good Luck!
    Eshwar Rao
    Developer Technical Support
    Sun microsystems
    http://www.sun.com/developers/support

  • Writing to servlet output stream

    Hi All,
    I am writing to a servlet(imageservlet) output stream in a jsp page two times as follows:
    <img src="\imageservlet?key=x1">
    <img src="\imageservlet?key=x2">
    It is causing memory errors. Do I have to take special precautions?
    Thanks inadvance.

    Hi,
    THis is my servlet code.
    import java.io.*;
    import java.io.StringWriter;
    import javax.servlet.http.*;
    import javax.servlet.*;
    import java.awt.Color;
    import com.trizetto.healthweb.service.GenerateImage;
    * Simple servlet to use with Image I/O generator
    public class GenerateImageServlet extends HttpServlet
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws IOException, ServletException
         String className="PieChartGenerator";
         if(request.getParameter("keyName").equals("Pie"))
              className=PieChartGenerator";
         else if( request.getParameter("keyName").equals("Gantt") )
              className="GanttChartGenerator";
    try
    GenerateImage ge=
    (GenerateImage) Class.forName(className).newInstance();
    String type = ge.createImage(response.getOutputStream());
    response.setContentType(type);
    catch (Exception e)
    throw new ServletException(e);
    But this one does not generate image. The image is generated from the Graphics object of the Frame.
    Something like the following code:
    http://www.javaworld.com/javaworld/jw-05-2000/servlets/Servlets.zip
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets-p2.html
    http://www.javaworld.com/javaworld/jw-05-2000/jw-0505-servlets-p1.html
    I am using Java 1.1.
    I am running my app. in websphere. The error happens randomly while I am stopping the websphere application server.
    Thanks in advance.

  • Help... Super Urgent. Servlet Problem

    Anyone can help me this? My servlet wants to connect to another servlet. My supervisor tells me to use socket. This is my code.
    Socket socket = new Socket(location, 8210);
              OutputStream os = socket.getOutputStream();
              boolean autoflush = true;
              PrintWriter out = new PrintWriter(socket.getOutputStream(), autoflush);
              ObjectInputStream objIn = null;
              Object obj = null;
    BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
              out.println("GET "+dir+"?class="+className+"&method="+method+"&machine="+request.getServerName()+"&port="+random+" HTTP/1.1");
              out.println("Host: localhost:8080");
              out.println("Connection: Close");
              out.println();
    boolean loop = true;
              StringBuffer sb = new StringBuffer(8096);
              while (objIn==null)
                   objIn = new ObjectInputStream(new BufferedInputStream(socket.getInputStream()));
                   try
                        obj = objIn.readObject();
                        //Thread.currentThread().sleep(50);
                   catch (Exception e)
                        e.printStackTrace();
    My supervisor say that as my servlet opens socket connection to the other servlet, the other servlet just have to do outputstream then my servlet can received. I try but can't. Anyone can help me?? Very Urgent. tomorrow is the dateline.

    Hi MelonSeed,
    I believe that the other servlet needs to open a ServerSocket in order for the two servlets to communicate via a Socket.
    Although I haven't tried it, you can open a URLConnection to the other servlet and then open an InputStream for reading the response from the other servlet.
    Depending on the URL you use to connect to the other servlet, you will (as I'm sure you know) invoke its "doGet()" or "doPost()" methods.
    Also, you may find some relevant examples in Jason Hunter's book, Java Servlet Programming, which are available online.
    Good Luck,
    Avi.

  • How to compress JSP/Servlet output with WebCache?

    Hello,
    I have an application using servlet/JSP. A request coming from the browser is handle by a servlet, and then forward the processing to a JSP page that produces the response. The requests are like http://host:port/athena/execute/action and we use POST method. It seems WebCache does not compress the output if I specify this compression rule
    URL expression: ^/athena/.*$
    Method POST
    POST Body Expression .*
    What's wrong ??
    Thanks in advance.

    This is already answered in another identical thread.

  • Include to jsf  servlet output data

    hello
    my servlet transforms xml document by xstl and i want to include into my jsf page what servlet writes in outputStream
    i had tried facelet's ui:include, but it said that the path invalid
    what way can i go to resolve this problem?
    thank you
    Edited by: user10279326 on Dec 24, 2010 1:16 PM
    Edited by: user10279326 on Dec 24, 2010 1:16 PM

    You could use an URLConnection in a JSF backing bean to invoke the servlet, then output the result through a property of the backing bean.
    If we're talking about lots of data you might want to rethink your strategy a little. For example you could use Ajax to fetch the data from the servlet through the client side and display a 'processing' icon while it is busy loading the data. That way your page displays almost immediately and the servlet result will then display as soon as it is done processing.

  • Manipulate Servlet Output

    Hello:
    I use RequestDispatcher to call servlet2 from servlet 1. It works, but I need to manipulate the output of servlet2 in servlet1.
    While Servlet API 2.3 have some filter functionality, I am using WebSphere Application Server 4.0 and it does not support 2.3 API. Any suggestion will be greatly appreciated.
    Best regards
    Kent

    If there is no need to sent the servlet2 out put to client (browser) you transform it to a compiled class (lets say c.class), create a instance of this class into servlet1 and call a method in c.class that gives the same servlet2 output.
    A second solution is to get the output of the servlet2 content like this :
    URL servlet2Url = new URL("servlet2 url");
    URLConnection servlet2Conn= servlet2Url.openConnection();
    servlet2Conn.connect();
    DataInputStream is = new DataInputStream(servlet2Conn.getInputStream());
    ... then read the input stream "is" like any other inputStream
    Hope this will help

Maybe you are looking for