Redirecting a servlet response to a file

Is there a way to redirect the response objects output buffer to a file instead of to the client (browser)?
I am using the jsp to process a set of jsp templates (using the RequestDispatcher's include method) and I would like to send the resulting html to a file, NOT to the client.
Any ideas.
Thanks,
Jay
[email protected]

The problem is that I'm not generating code with out.println() statements, I'm relying on the servlet engine to generate the html from jsp templates.
For example, my code uses the RequestDispatcher.include(request, response) to access and process a jsp template, which in turn may include another jsp template, and so forth and so on, and it is my understanding that there is an output buffer that is being written and will finally be sent to the client. I want to intercept this and send that to a file.
Thoughts?

Similar Messages

  • Converting emails to servlet requests; servlet responses to emails

    Hello,
    I had asked this question in the Servlet forum. They directed me to here.
    I've some servlet applications that posted by HTML forms with file attachements and other HTML fields.
    I want to add email support to my servlets. So, users should be able post and recieve their data by emails.
    But, I don't want to add email handling tasks to the current servlet applications. I need a middleware application between end users and my servlets that converts emails to servlet requests, and servlet responses to emails.
    Here are the steps:
    1- End user sends email with attachments.
    2- Emailed data is converted to servlet request by a middleware application.
    3- Servlet request is processed by my current servlets.
    4- Servlet response is sent to middleware application.
    5- Middleware application emails servlet reponse to end user as email.
    If I can do that, I will not have to add emailing codes to my current servlets. do you know a product doing that ? Or, can you give me a direction ?
    thanks...

    Have you looked into JMS?

  • Providing redirects in Servlet filter

    Hi,
    I need to provide serverside redirects in Servlet filter.O tried the below code, But unable to do it.
    Is it possible to do such a thing.
    public void doFilter(ServletRequest req, ServletResponse res,
                   FilterChain chain) throws IOException, ServletException {
              logger.info("Start of RedirectFilter ");
              HttpServletRequest request = (HttpServletRequest) req;
              HttpServletResponse response = (HttpServletResponse) res;
              String requestURI=request.getRequestURI();
              String domainURL=request.getServerName().toLowerCase();
              logger.info("domainName--"+domainName);
              String keywordToBeAppended=domainURL.replaceAll(domainName,"");
              logger.info("url--"+request.getRequestURI());
              logger.info("servername--"+request.getServerName());
              logger.info("keywordToBeAppended-"+keywordToBeAppended);
              String finalURL= request.getScheme()+"://"+domainURL+"/"+keywordToBeAppended+requestURI;
              logger.info("finalURL--"+finalURL);
              RequestDispatcher rd = request.getRequestDispatcher(finalURL);
              rd.forward(request, response);
              logger.info("End of RedirectFilter ");
              chain.doFilter(request, response);
         }

    There is technically a huge difference between "redirect" and "forward". You're doing here forwards. And because you continue the filter chain, you run into problems. You should do either a forward OR continuing the current request unchanged (through the filter chain) OR send a redirect. You cannot do one or more simultaneously.

  • Servlet as a welcome file: is it a myth?

    Hello
    There are many articles on the web that espouse that Servets 2.4 allow for a servlet to be specified as a welcome file thusly (taken from OnJava.com):
    First, register the servlet in web.xml.
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi=
    "http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation=
    "http://java.sun.com/xml/ns/j2ee
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
    <servlet>
    <servlet-name>MyServlet</servlet-name.
    <servlet-class>com.jspservletcookbook.MyServlet</servlet-class>
    </servlet>
    <!-- optionally map the 'MyServlet' servlet to a URL pattern -->
    <servlet-mapping>
    <servlet-name>MyServlet</servlet-name>
    <url-pattern>/myservlet</url-pattern>
    </servlet-mapping>
    <!-- rest of web.xml ... -->
    Then create a welcome-file element in web.xml that specifies the registered servlet name.
    <welcome-file-list>
    <welcome-file>MyServlet</welcome-file>
    <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>
    Make sure to use the servlet name in the welcome-file element without a forward slash (/) preceding it.
    Poppycock I say. At least it's not working for me with either Tomcat 5 or Tomcat 5.5. Has anyone out there ever seen this work on Tomcat?

    It most certainly is possible now, but wasn't until rather late in TC 5.0.xx series I believe (5.0.18 or so?). You can chack the change logs to id exactly when...
    But the reason it isn't working for you is you have to match the value in your <welcome-file> to the URL in the servlet's <url-pattern> servlet mapping. So your web XML should look like this:
    <servlet>
      <servlet-name>MyServlet</servlet-name.
      <servlet-class>com.jspservletcookbook.MyServlet</servlet-class>
    </servlet>
    <servlet-mapping>
      <servlet-name>MyServlet</servlet-name>
      <url-pattern>/myservlet</url-pattern>
    </servlet-mapping>
    <welcome-file-list>
      <welcome-file>myservlet</welcome-file>
      <welcome-file>default.jsp</welcome-file>
    </welcome-file-list>Your porblem was case. Your url-pattern had lower case, but the welcome-file had upper case letters like the servlet name.
    Here is an example app that I tested and worked:
    //The servlet:
    package net.thelukes.steven;
    import java.io.IOException;
    import java.io.PrintWriter;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class WelcomeServlet extends HttpServlet {
         public void doGet(HttpServletRequest request, HttpServletResponse response)
           throws ServletException, IOException {
              PrintWriter out = response.getWriter();
              out.println("Hello World");
              out.flush();
              out.close();
    //the web.xml
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app id="WebApp_ID" version="2.4"
             xmlns="http://java.sun.com/xml/ns/j2ee"
             xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
             xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
                                 http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
         <display-name>WTPTest</display-name>
         <servlet>
              <servlet-name>Welcome</servlet-name>
              <servlet-class>net.thelukes.steven.WelcomeServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>Welcome</servlet-name>
              <url-pattern>/welcome</url-pattern>
         </servlet-mapping>
         <welcome-file-list>
              <welcome-file>welcome</welcome-file>
         </welcome-file-list>
    </web-app>
    //The address I typed (the web app is names WTPTest
    http://localhost:8080/WTPTest
    //The HTML Output
    Hello World

  • Servlet for downloading a file

    i am writing a servlet for downloading a file on a GET action in the form..the web-xml is deployed correctly as far as i can interpret..bt i am encountering an error during the run time..
    HTTP Status 500 -
    type Exception report
    message
    description The server encountered an internal error () that prevented it from fulfilling this request.
    here is the log file..
    Jul 11, 2008 12:07:14 AM org.apache.catalina.core.StandardWrapperValve invoke
    SEVERE: Servlet.service() for servlet DwnFile threw exception
    java.lang.NullPointerException
         at com.example.web.dwnfile.doGet(dwnfile.java:17)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:690)
         at javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
    it has some more content bt it is just the exceptions thrwn...
    and here is my *.java file*
    package com.example.web;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    public class dwnfile extends HttpServlet
    public void doGet(HttpServletRequest request,HttpServletResponse response) throws IOException,ServletException
    response.setContentType("/image/jpeg");
    ServletContext ctx=getServletContext();
    InputStream is=ctx.getResourceAsStream("/2004.jpeg");
    int read=0;
    byte[] bytes=new byte[1024];
    OutputStream os=response.getOutputStream();
    while ((read=is.read(bytes))!=-1)
    {os.write(bytes,0,read);
    os.flush();
    os.close();
    the bold line is whre the exception is pointing..i think..
    thanks in advance..
    Edited by: Sun_Rockz on Jul 10, 2008 7:13 PM

    response.setContentType("/image/jpeg");
    ServletContext ctx=getServletContext();
    InputStream is=ctx.getResourceAsStream("/2004.jpeg");there was an error in this part of code..the image extension of .jpeg is not allowed it seems..on changing it to jpg worked..and
    in the first line the contenttype mst not be preceded by a forward slash..
    now one more doubt relating to the same servlet..
    response.setContentType("application/x-zip");
    ServletContext ctx=getServletContext();
    InputStream is=ctx.getResourceAsStream("/servlet_spec.zip");
    if i keep this in my servlet the required action is taking place..i.e.i am gettin a download option bt the problem is tht the file is getting downloaded as a download.do file.....
    download.do is the url pattern tht i am using in my html web page..
    i tried replacing different types of allplications and files bt all are downloaded wit the same name. i.e. download.do
    so what do u think is reason behind this..
    thanks for all the replies.
    Edited by: Sun_Rockz on Jul 11, 2008 10:47 AM
    Edited by: Sun_Rockz on Jul 11, 2008 10:51 AM

  • Redirecting the servlet output to jsp

    Hi i need to redirect my servlet out put to jsp
    in result set's every row i have 9 columns
    this result set how can i redirct to jsp
    plz can any one let me know with an example
    thanks a lot in advance

    inamdar wrote:
    Hi i have never used DTO's and DAO classes
    plz colud u let me know without using that..Huh? It is never too late to start with it. Just create two simple classes. A DTO class is basically a simple javabean with private (encapsulated) properties and a public getter and setter for each property. A DAO class is basically a class which contains purely JDBC code.
    Sample DTO:public class MyData {
        private Long id;
        private String name;
        private Integer value;
        public Long getId() { return id; }
        public String getName() { return name; }
        public Integer getValue() { return value; }
        public void setId(Long id) { this.id = id; }
        public void setName(String name) { this.name = name; }
        public void setValue(Integer value) { this.value = value; }
    }Sample DAO:public class MyDataDAO {
        public List<MyData> listAll() {
            String listAllQuery = "SELECT id, name, value FROM data";
            List<MyData> myDataList = new ArrayList<MyData>();
            Connection connection = null;
            Statement statement = null;
            ResultSet resultSet = null;
            try {
                connection = getConnectionSomehow(); // DriverManager or Connection Pool, your choice.
                statement = connection.createStatement();
                resultSet = statement.executeQuery(listAllQuery);
                while(resultSet.next()) {
                    MyData myData = new MyData();
                    myData.setId(new Long(resultSet.getLong("id")));
                    myData.setName(resultSet.getString("name"));
                    myData.setValue(new Integer(resultSet.getInt("value")));
                    myDataList.add(myData);
            } catch (SQLException e) {
                // Handle it. Print it, throw it, log it, mail it, your choice.
                e.printStackTrace();
            } finally {
                // You can write an utility class/method for those lines as well.
                if (resultSet != null) { try { resultSet.close(); } catch (SQLException e) { e.printStackTrace(); } }
                if (statement != null) { try { statement.close(); } catch (SQLException e) { e.printStackTrace(); } }
                if (connection != null) { try { connection.close(); } catch (SQLException e) { e.printStackTrace(); } }
            return myDataList;
    }Sample Servlet code:List<MyData> myDataList = new MyDataDAO().listAll();
    request.setAttribute("myDataList", myDataList);
    request.getRequestDispatcher("someJspFile.jsp").forward(request, response);Sample JSTL code in someJspFile.jsp:<table>
        <c:forEach items="${myDataList}" var="myData">
            <tr>
                <td>${myData.id}</td>
                <td>${myData.name}</td>
                <td>${myData.value}</td>
            </tr>
        </c:forEach>
    </table>Simple and clean, isn't it?

  • Requesting user capability to "Save Response as PDF File w/form design intact"

    Love the new admin "Save Response as PDF File with form design intact" feature, but we really need for our indivual users (i.e. the ones filling out the form) to be able to do this. Our director still needs a hard copy of the form for manual signatures and those who pay by check. Our committee chairs use the online data (from excel file) but we also need the user to print a hard copy to physically turn in to the director. A .pdf file with form design intact that our user could print out and turn in would be helpful.

    Hi,
    We have an "Ideas" page where you can add or vote on feature ideas:
    http://forums.adobe.com/community/formscentral?view=idea
    I am pretty sure this idea has been added for you to vote on, but I didn't find it to link to.  I know it is a popular request though so if you need to add a new idea click "Create an idea" under "Actions" in the top right, I am sure it will get a lot of votes..
    Thanks,
    Josh

  • HTTP Header in Servlet-Response

    Hi,
    I have to add a header line to a Servlet-Response: 'msgid: 1234'.
    Have no idea how to do that, can anybody help?
    Thanks in advance
    Karsten

    Hi Karsten,
    http://java.sun.com/products/servlet/2.2/javadoc/javax/servlet/http/HttpServletResponse.html#setHeader(java.lang.String,%20java.lang.String)
    Hope it helps
    Detlev

  • Unable to write SOAP response to a file

    Hi,
      I am trying to capture SOAP response into a file using the method mentioned in the below given wiki but running into errors.
    File gets read but it doesn't get deleted and it gets processed infinitely without creating any monitoring messages.
    https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/using%252brequest%252bresponse%252bbean%252bmodule%252bin%252bfile%252badapter
    Following is the trace from defaulttrace:
    #1.5 #005056A33969002E00003735000014A41040C0723D32A941#1236364790565#
    com.sap.engine.services.ts##com.sap.engine.services.ts#J2EE_GUEST#168484##
    test008_ZP0_117114750##672e8d50052011deafc2005056a33969#XI File2XI[CC_NTLM/BE_FILE_LOCAL/]_400304##0#0#Error#1#/System/Server#Java#ts_0021##Thread is not associated with any transaction context.##
    #1.5 #005056A33969002E00003737000014A41040C0723D32A941#1236364790565#
    com.sap.engine.services.ts##com.sap.engine.services.ts#J2EE_GUEST#168484##test008_ZP0_11711
    4750##672e8d50052011deafc2005056a33969#XI File2XI[CC_NTLM/BE_FILE_LOCAL/]_400304##0#0#Error#1#/System/Audit#Java###Exception #1#com.sap.engine.services.ts.transaction.TxDemarcationException: Thread is not associated with any transaction context.
         at com.sap.engine.services.ts.transaction.TxManagerImpl.setRollbackOnly(TxManagerImpl.java:754)
         at com.sap.transaction.TxManager.setRollbackOnly(TxManager.java:382)
         at com.sap.aii.af.service.util.transaction.impl.SAPTxManagerImpl.rollback(SAPTxManagerImpl.java:109)
         at com.sap.aii.adapter.file.File2XI.processFileList(File2XI.java:1748)
         at com.sap.aii.adapter.file.File2XI.invoke(File2XI.java:615)
         at com.sap.aii.af.lib.scheduler.JobBroker$Worker.run(JobBroker.java:463)
         at com.sap.engine.core.thread.impl3.ActionObject.run(ActionObject.java:37)
         at java.security.AccessController.doPrivileged(Native Method)
         at com.sap.engine.core.thread.impl3.SingleThread.execute(SingleThread.java:152)
         at com.sap.engine.core.thread.impl3.SingleThread.run(SingleThread.java:247)
    Caused by: com.sap.engine.services.ts.exceptions.BaseIllegalStateException: Thread is not associated with any transaction context.
         at com.sap.engine.services.ts.jta.impl.TransactionManagerImpl.setRollbackOnly(TransactionManagerImpl.java:475)
         at com.sap.engine.services.ts.transaction.TxManagerImpl.setRollbackOnly(TxManagerImpl.java:751)
         ... 9 more
    Am not sure if this is the right approach. One other way mentioned some where else is to use the File Handler in Axis adapter but thats not working either.
    Any help is appreciated!!
    Thanks
    Kiran

    Hi!
    A part from the abov sugestions make sure even though u checked previously..
    1. Check whether your SOAP URL s correct or not which you are giving in the receiver SOAP adapter
    2. Also check you are giving the SOAP action in the receiver SOAP adatper correctly or not.
    3. Finally check the SOAP service is activei or not in SAP>BC>XI-->SOAP in ABAP stack
    4. Since FIle is only for ASYN comm and while using FILE for  sync interface you need to pass module paramters in the Sender File CC
    please go thorugh the below link and check all those parameters once again whcih contains detaled screen shots.....Ok
    [https://www.sdn.sap.com/irj/scn/wiki?path=/display/xi/file-rfc-file(Without+BPM)]
    Regarsd::
    Amar Srinivas Eli

  • Concurrent processing of POST requests and automatic flushing of the servlet response buffer in WLS6.1.

              Hi all,
              I encountered the following 2 servlet problems in WLS 6.0/ 6.1:
              1. Processing concurrent POST requests
              WLS seems to disallow concurrent executions of any servlet's doPost servlet method.
              When two clients attempt to send a request to a servlet using POST, the socond
              one
              is blocked until the first customer is served. In essence, the servlet ends up
              operating in
              1-user mode. I just learned from Jervis Liu that the problem is solved in WLS6.0
              if you disable http-keepalive.
              For WLS 6.1 a partial workaround is to make the servlet work in a single-thread
              mode (by implementing the javax.servlet.SingleThreadModel interface). In this
              case,
              WLS dispatches concurrent requests to different instances of the servlet.
              This doesn't completely eliminate the problem - still only one customer can be
              connected at a time. The improvement is that once the first customer is disconnects,
              the second can be served even if the doPost method for the first has not finished
              yet.
              2. Flushing the response buffer in WLS 6.1
              The servlet response buffer is not flushed automatically until doPost ends, unless
              you
              explicitly call response.flushBuffer(). Closing the output stream doesn't flush
              the
              buffer as per the documentation.
              I see that other people are experiencing the same problems.
              Has anyone found any solutions/workarounds or at least an explanation.
              Any input would be highly appreciated.
              Thanks in advance.
              Samuel Kounev
              

    Thanks for replying. Here my answers:
              > Did you mark your doPost as synchronized?
              No.
              > Also, try testing w/ native i/o vs not ... is there a difference?
              With native I/O turned off I get a little lower performance, but the
              difference is not too big.
              Best,
              Samuel Kounev
              > Peace,
              >
              > --
              > Cameron Purdy
              > Tangosol Inc.
              > << Tangosol Server: How Weblogic applications are customized >>
              > << Download now from http://www.tangosol.com/download.jsp >>
              >
              > "Samuel Kounev" <[email protected]> wrote in message
              > news:[email protected]...
              > >
              > > Hi all,
              > >
              > > I encountered the following 2 servlet problems in WLS 6.0/ 6.1:
              > >
              > > 1. Processing concurrent POST requests
              > >
              > > WLS seems to disallow concurrent executions of any servlet's doPost
              > servlet method.
              > >
              > > When two clients attempt to send a request to a servlet using POST, the
              > socond
              > > one
              > > is blocked until the first customer is served. In essence, the servlet
              > ends up
              > > operating in
              > > 1-user mode. I just learned from Jervis Liu that the problem is solved in
              > WLS6.0
              > >
              > > if you disable http-keepalive.
              > >
              > > For WLS 6.1 a partial workaround is to make the servlet work in a
              > single-thread
              > >
              > > mode (by implementing the javax.servlet.SingleThreadModel interface). In
              > this
              > > case,
              > > WLS dispatches concurrent requests to different instances of the servlet.
              > > This doesn't completely eliminate the problem - still only one customer
              > can be
              > >
              > > connected at a time. The improvement is that once the first customer is
              > disconnects,
              > > the second can be served even if the doPost method for the first has not
              > finished
              > > yet.
              > >
              > > 2. Flushing the response buffer in WLS 6.1
              > > The servlet response buffer is not flushed automatically until doPost
              > ends, unless
              > > you
              > > explicitly call response.flushBuffer(). Closing the output stream doesn't
              > flush
              > > the
              > > buffer as per the documentation.
              > >
              > > I see that other people are experiencing the same problems.
              > >
              > > Has anyone found any solutions/workarounds or at least an explanation.
              > > Any input would be highly appreciated.
              > >
              > > Thanks in advance.
              > >
              > > Samuel Kounev
              =====================================================
              Samuel D. Kounev
              Darmstadt University of Technology
              Department of Computer Science
              DVS1 - Databases & Distributed Systems Group
              Tel: +49 (6151) 16-6231
              Fax: +49 (6151) 16-6229
              E-mail: mailto:[email protected]
              http://www.dvs1.informatik.tu-darmstadt.de
              http://skounev.cjb.net
              =====================================================
              [att1.html]
              

  • Weblogic 12c Servlet Response - Special characters show up as question mark

    My web app is running on Weblogic 12c (12.1.1) using WebWork + Hibernate. The program streams data (bytes making up a pdf) from a CLOB in an Oracle Database to the AsciiStream of the servlet output response. No exceptions are thrown, but the generated pdf contains blank pages. Comparing the bytes of the generated pdf, special characters are showing up as question marks.
    Some of the bytes read in from the database contain 8 bits (correct data), but the bytes that the servlet return contain only 7 (all bytes with 8 bits become "1111111"). The number of bytes returned from the servlet is correct.
    Code:
    //Response is HttpServletResponse
    response.setContentType("application/pdf");
    response.setHeader("Content-Disposition", "inline; filename=\"test.pdf\"");
    out = response.getOutputStream();
    byte[] buf = new byte[16 * 1024];
    InputStream in = clob.getAsciiStream();
    int size = -1;
    while ((size = in.read(buf)) != -1){
    // buf contains the correct data
    out.write(buf, 0, size);
    // other exception handling code, etc
    out.flush();
    out.close();
    "Correct" pdf byte example:
    10011100
    10011101
    1010111
    1001011
    1101111
    11011011
    Incorrect pdf byte example:
    111111
    111111
    1010111
    1001011
    1101111
    111111
    I have verified that the data read from the CLOB in the database IS correct. My guess is that the Weblogic server has some strange servlet settings that causes the bytes to be written to the servlet output stream incorrectly, or a character encoding issue. Any ideas?
    Edited by: 944705 on Jul 26, 2012 10:17 AM

    Solution found, I'll post the work around to those who might encounter the same problem.
    Somewhere in the layers of technology (webwork or weblogic I'd guess), the servlet response is encoded into UTF-8 regardless. The encoding in the database was ISO-8859-1. Sending ISO encoded bytes by UTF-8 caused the conflicting character codes (anything above 127) to show up as undefined.
    The fix is to decode the input byte array into ISO-8859 string, then encode that string into UTF-8, which can be send by Weblogic.
    isoConvert = new String(buf, "ISO-8859-1");
    out.write(isoConvert.getBytes("UTF-8"), 0, isoConvert.getBytes("UTF-8").length);

  • Tomcat servlet/JSP container default files on 10gAS(10.1.2.0.2)

    Hi Friends,
    I am using Oracle Application Server 10g (10.1.2.0.2) on windows
    I have the Vulnerability: Apache Tomcat servlet/JSP container default files.
    and the fix is Review the files and delete those that are not needed.
    i would like to know the location of the files to review and delete.Please suggest?
    Regards,
    DB

    Apache/Tomcat is not related to OAS, where did you get this info? OAS is based in a Orion Web Server and Apache HTTP Server, not Tomcat.
    For this kind of problems there are the CPU you may want to check in Metalink for them.
    Can you clarify also what default files?
    Greetings.

  • IOException - WEB8001 - when writing to servlet response outputstream

    I am attempting to port a Java servlet application from iws 6.0 to 6.1, sp2, but am encountering IOExceptions during load testing.
    The servlet composes its response in a character array, and then calls the following method to write the characters to the servlet response object:
    static void writeResponse( HttpServletResponse response, char[] chars, String charset ) throws IOException {
        OutputStreamWriter writer =
            new OutputStreamWriter( response.getOutputStream(), charset );
        char[] buffer = new char[8192];
        CharArrayReader reader = new CharArrayReader( chars );
        int read = 0;
        while(( read = reader.read( buffer, 0, 8192 )) > -1 )
           writer.write( buffer, 0, read );
        writer.close();
    }Under moderate load (2-4 simultaneous connections), an IOException will sometimes be thrown. The stack dump is:
    java.io.IOException: WEB8001: Write failed
         at com.iplanet.ias.web.connector.nsapi.NSAPIConnector.write(NSAPIConnector.java:750)
         at com.iplanet.ias.web.connector.nsapi.NSAPIResponseStream.write(NSAPIResponseStream.java:74)
         at org.apache.catalina.connector.ResponseBase.flushBuffer(ResponseBase.java:765)
         at org.apache.catalina.connector.HttpResponseBase.flushBuffer(HttpResponseBase.java:779)
         at com.iplanet.ias.web.connector.nsapi.NSAPIResponse.flushBuffer(NSAPIResponse.java:127)
         at org.apache.catalina.connector.ResponseBase.write(ResponseBase.java:738)
         at org.apache.catalina.connector.ResponseStream.write(ResponseStream.java:325)
         at sun.nio.cs.StreamEncoder$CharsetSE.writeBytes(StreamEncoder.java:336)
         at sun.nio.cs.StreamEncoder$CharsetSE.implWrite(StreamEncoder.java:395)
         at sun.nio.cs.StreamEncoder.write(StreamEncoder.java:136)
         at java.io.OutputStreamWriter.write(OutputStreamWriter.java:191)
         at eng.pubs.servlet.DocServlet.writeResponse(DocServlet.java:1034)The exception is not thrown consistently for any given URL, but appears to be random. When run under iws 6.0, the exceptions do not occur at all. Most of the time, the method will have written 32K
    of data when the exception is thrown.
    Any clues about how I might debug this?

    What are you using as your test client?The test client is WebStone 1.0. WebStone always downloads the whole response, and reports the size of the response in bytes. From this I can see that when the IO exception occurs, webstone is unable to read the whole response, as it reports a smaller size.
    So, I do not think the problem is that the client has prematurely aborted its download. WebStone doesn't work that way. I think something has gone awry on the server side, and this worries me.

  • How to modify a servlet response?

    Hi all,
    I want to modify the servlet response string returned by the portal irj servlet.
    For this I created a filter.
    Now my requirement is to do something like this in the doFilter method:
    doFilter(ServletRequest req, ServletResponse res, FilterChain chain) {
    PrinterWriter pq = res.getWriter();
    Reader reader = new StringReader(printWriter.toString());
    BufferedReader bufferedReader = new BufferedReader(reader);
    String line;
    while ((line = bufferedReader.readLine()) != null) {
    line.replaceAll("Welcome", "Welcome to XXXX");
    What I am trying to do is in the response stream replace the letter welcome with "Welcome to XXXX".
    I know I cant accomplish this by the code given above.
    Any body has a code snippet of how to get this working?
    Thanks

    Hi,
    You are already in the right way, things missing are:
    1. Forgot the do the filter chain     
          filterChain.doFilter(request, wrapper);
    2. Write back the modified stream to response
    // write the response stream           
          response.setContentLength(responseStr.length());
          response.getWriter().write(responseStr);      
    You can use the HttpServletResponseWrapper to manipulate the response too, check the examples at this link:
    http://www.jsp-develop.de/faq/show/47/
    Greetings,
    Praveen Gudapati
    [Points are always welcome for helpful answers]

  • Redirecting java compilation errors to a file

    Hi,
    How do I redirect java compilation errors to a file while using a dos environment ? Help needed asap.
    Gayathri

    javac FileName.java 2> errorFileName

Maybe you are looking for