Servlet Response Problem

Hello all,
My simple servlet takes in a URL as a parameter and the uses the httpUrlConnection method to retrieve that page. It then just writes the html to the browser in the hope that it would be displayed as if retrieved directly.
Although the source of a page retrieved in this way is identicle to the expected source, no images appear. I think (guess) this is because the address of a page retrieved in this way will not be the same as if retrieved normally. This, in turn, messes up the relative file paths. e.g www.mypage.com becomes something like http://localhost/httpProxyServer?URL=http%3A%2F%2Fwww.mypage.com (httpProxyServer is the name of the servlet).
To get to the point, idoes anyone know if there is a way i can set the address of the returned page to be as if retrieved directly? I have looked in to response headers with little luck although i am very new to servlets. Thanks for any tips or advice.
Christie

This question can be better answered if you point out the need to examine each response before actually sending it out to the browser. What exactly do you look for in the response ? Do you compress it / transform it / parse it ?
Having said that, you could use filters to meet any of your above needs.
1. The first obvious gain is that it is a standard, widely accepted and part of the j2ee specification. As you said, it provides modularity and resuability of code. Somebody who goes through your work would easily pick up the trail, comprehend concisely the effort and the ends you attempt to achieve. You would have implicit server support (more of this later)
2. You use a servlet that intercepts each request. It then uses a HttpURLConnection to get the response from each resource. As you can see straight away, this essentially makes it two requests per request - the original request goes to your general purpose servlet; then the general purpose Servlet(GPS hereafter) makes the url connection to the resource, its a brand new request. The original request may have lots of params coming in which have to be reconstructed by the GPS and included in the call to the resource which delivers the actual response back to the GPS. Hope you begin to see the pitfalls here (for example imagine the incoming stream is a byte stream resulting from a file upload)
**in short** the 'simple servlet' is going to get very very complex as your application grows.
3. All the above rerouting (even if you manage to achieve it successfully) will take its toll on the performance measured in terms of the response time.
4. In established MVC2 framework like Struts or JSF, the Servlet that intercepts every request is a Controller Servlet (which knows how to handle the request, which validations to perform, which beans to invoke and so on). Your GPS should in addition to examining responses, do all this stuff or else you would end up with multiple Controllers making your app quite unwieldy.
5. Using filters, you could side step all the above which in itself is a huge advantage (me thinks :)) besides providing a standard way to implement tasks similar to yours. I mentioned implicit server support, right ? Filters are supported by all standard j2ee web severs. You neednt write a single line of code to have your filter modify the response. All you have to write is the actual modification algorithm. However the path you choose, you would have to manually do all the dirty work of transferring the request to the actual resource (using HttpUrlConnection). You should receive each request params and convey that to the resource being accessed and so on. (see #2 above)
Hope all that helps.
cheers,
ram.

Similar Messages

  • 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);

  • 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.

  • 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

  • Servlet Compilation Problem !

    Hi,
    I am just starting to learn servlets and I got problem in compiling them. I got compilation error in
    import javax.servlet.*;statement. Seems that the compiler cannot find the servlet package. I got J2EE 1.4 beta installed on my machine but there is no servlet.jar package. I am using J2SDK 1.4.1_02, J2EE 1.4 beta and Tomcat 4.1.24.
    Can anyone help me with my servlet compilation problem?
    Thanks in advance!
    Josh

    servlet.jar is here :
    <tomcatdir>\common\lib
    add it to your compiler classpath

  • 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?

  • Servlet chaining problem..

    import java.io.*;
        import javax.servlet.*;
        import javax.servlet.http.*;
        public class Deblink extends HttpServlet {
          public void doGet(HttpServletRequest req, HttpServletResponse res)
                                       throws ServletException, IOException {
            String contentType = req.getContentType();  // get the incoming type
            if (contentType == null) return;  // nothing incoming, nothing to do
            res.setContentType(contentType);  // set outgoing type to be incoming type
            PrintWriter out = res.getWriter();
            BufferedReader in = req.getReader();
            String line = null;
            while ((line = in.readLine()) != null) {
              line = replace(line, "<BLINK>", "");
              line = replace(line, "</BLINK>", "");
              out.println(line);
          public void doPost(HttpServletRequest req, HttpServletResponse res)
                                        throws ServletException, IOException {
            doGet(req, res);
          private String replace(String line, String oldString, String newString) {
            int index = 0;
            while ((index = line.indexOf(oldString, index)) >= 0) {
              // Replace the old string with the new string (inefficiently)
              line = line.substring(0, index) +
                     newString +
                     line.substring(index + oldString.length());
              index += newString.length();
            return line;
    What is pre request fo above code to work.
    I had tried this many time but it is not working, what will be calling servlet look like

    And can you explain why your title is "Servlet chaining problem"?

  • 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]

  • Delaying server [servlet] response

    I'm using AJAX to update my div tag telling me if a username is valid / invalid. I've tried using wait(long) to pause the doGet thread , init thread and start thread but I get the following warning:
    "Current thread not owner"
    Who's the owner or "main" thread? I've also tried respone.wait and request.wait but the same exception is being thrown. Or is there a different way to delay the servlets response, or is this impossible with XML?
    Thanks,
    -ls6v

    it sort of sounds to me like you're used to thick
    client gui programming - not sure why - but trying to
    control the number of hits to a database in a web
    app
    by messing with javascript controls smells a bit (it
    may be because of the nature of AJAX which I admit I
    haven't used). Embedding in depth knowledge of the
    back end in the front end is always a bit odd.
    Would it not be better to implement this sort of
    control (as in programmatic logic) server side ? Is
    there a need for an AJAX request to hit a database
    each time ? Might create an awful load (maybe this is
    what you're addressing). Perhaps some cached server
    side data structure might be of better use than
    trying to hack the front end in this fashion.Basically I'm going to use AJAX for the its look and feel, even if it isn't necessary. The load was what the other person brought up so I thought I could test it by slowing things down because I can't simulate 1,000 simultaneous connections. I'm not really worried about it because I figured that AJAX might actually help an over loaded server. If the server is too busy to respond I would catch that in my JS and and try to request it again after a few seconds. req.open("GET", url2, true);
    req.onreadystatechange = callback;
    req.send(null);
    function callback()
    if (req.readyState == 4)
            if (req.status == 200)
    else if(){...}
    }So if it comes back busy it'll wait before requesting the server again. I'll use DOM to manipulate the original login.html page so the input field will call a different JS function if it fails the first time. There's a bit more but that's what I'm going to try to do and hopefully bypassing this slow down testing won't matter.

  • Jsp waiting for servlet response how to make

    Hi All,
    i have some doubts about making servlet response for jsp request
    Am watched some online reservation sites it search some hotel names untill the hotel names display (between that time)
    the image processing shows how can i make like that via jsp and servlet plz expalin with example code plz.
    how to make jsp wait to servlet response like that plz reply
    Thanks

    It's a client side thing. Learn Javascript (and CSS) and if necessary also learn Ajax afterwards. There are nice tutorials at w3schools.com. This issue is not really related to JSP/Servlets.
    Displaying the progress image isn't that hard. Just show some <div> element with an image during the onclick.

  • How to Modify Data in a Servlet Response

    Hi..
    I have a servlet that upon receving an http request from client sends some data to the client browser, but i want to modify the data that is being sent to the client and resend it somehow (like its a kind of bypassing...without sending the original data..i want to modify the data and send the response ON THE FLY.
    Any ideas of suggestions how to do it, if some one of you has already done it then pls do send some code snippet.
    Thanx in advance
    mark.

    Aha... now the truth comes out. You asked how to do it, but your secret question was that you were already doing it and you were having some problems. It's generally just better to come out and ask the question, even though it may be embarrassing that what you did isn't working.
    To me, what you did sounds like a perfectly good method, except that writing the data to a temp file is going to run you into problems as soon as you get two requests at about the same time. I would do that in memory instead (write to a ByteArrayOutputStream, get the resulting array of bytes, modify it, and write the end result out to the servet response's output stream).
    The problem you describe, though, is probably caused because the browsers are caching requests to your servlet. Do you have something like this code in your servlet that tells the browsers not to cache it?response.setHeader("Cache-Control", "no-cache");
    response.setHeader("Pragma", "no-cache");

  • Error in getting the servlet response

    Below is my ErrorPage Servlet. Whenever a 404 page not found error is encountered, the error page servlet reads the 404.html, and writes the content to the response. But I am not able to see the content in IE, but works fine in mozilla.
    public class ErrorPageServlet extends HttpServlet {
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
            String errorPath = request.getAttribute("javax.servlet.error.request_uri").toString();
            int statusCode = Integer.parseInt(request.getAttribute("javax.servlet.error.status_code")
                    .toString());
            String[] errorPathSegment = errorPath.split("/");
            String site = errorPathSegment[2];
            switch (statusCode) {
            case HttpServletResponse.SC_NOT_FOUND:
                writeOutFile(request, response, "/" + site + "/error/404.html");
                break;
            case HttpServletResponse.SC_INTERNAL_SERVER_ERROR:
            case HttpServletResponse.SC_NOT_IMPLEMENTED:
            case HttpServletResponse.SC_BAD_GATEWAY:
            case HttpServletResponse.SC_SERVICE_UNAVAILABLE:
            case HttpServletResponse.SC_GATEWAY_TIMEOUT:
            case HttpServletResponse.SC_HTTP_VERSION_NOT_SUPPORTED:
                writeOutFile(request, response, "/" + site + "/error/500.html");
                break;
        public void writeOutFile(HttpServletRequest request, HttpServletResponse response,
                String fileName) throws IOException {
            ServletContext context = request.getSession().getServletContext();
            response.setContentType("text/html");
            PrintWriter writer = response.getWriter();
            InputStream resourceStream = context.getResourceAsStream(fileName);
            if (resourceStream != null) {
                InputStreamReader streamReader = new InputStreamReader(resourceStream);
                BufferedReader reader = new BufferedReader(streamReader);
                StringBuilder builder = new StringBuilder();
                for (String line = reader.readLine(); line != null; line = reader.readLine()) {
                    builder.append(line);
                    builder.append('\n');
                writer.write(builder.toString());
                writer.flush();
            } else {
                log.info("Problem occurred with " + fileName);
                response.sendRedirect("/");
        }Also attached is my 404.html
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd]">
    <html xmlns="[http://www.w3.org/1999/xhtml]">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
    <meta http-equiv="refresh" content="10;URL=/" >
    </head>
    <body>
    <h1>Error</h1>
    <p>A technical error has occurred. You will redirected in 10 seconds</p>
    </body>
    </html>

    Hi..
    Thanks for the comment.
    Below is how my web.xml entry looks like.
    The requirement is to send a 404 error response and that will be handled by a servlet which inturn writes the output to the response object.
         <servlet>
              <servlet-name>ErrorPageServlet</servlet-name>
              <servlet-class>com.test.ErrorPageServlet</servlet-class>
         </servlet>
         <servlet-mapping>
              <servlet-name>ErrorPageServlet</servlet-name>
              <url-pattern>/error</url-pattern>
         </servlet-mapping>
         <error-page>
              <error-code>404</error-code>
              <location>/error</location>
         </error-page>>>
    the first option to turn off the "show friendly html error pages" works fine.
    It would be better if I can get a different solution

  • Applet-Servlet Communication problem EOFException

    Hi! i´ve been searching and searching through forums because it seems this problem is very common, but none of the solutions i´ve seen so far suits me, so i´m here looking for some help because i´ve been stuck one week with this. First of all sorry if my english isn´t the best... i´m a bit rusty...
    Well, i had some code that worked perfectly, but i needed to perform some changes because i needed the servlet to send more info to the applet, and here started the problems, when i made the changes it started to throw EOFException when i was trying to read the InputStream, and furthermore when i came back to the original code it started to throw the exception in the same place too
    So here i am... don´t know what to do now and i entrust to you to give me some tips.
    Here comes some code. This is the original code, the one that runned but it doesn´t run right now
    Applet:
    public ListasComponentesSeleccionables cargarListasComponentes( ) throws IOException, ClassNotFoundException {
              String serv = "/Desaladora/cargarListasComponentesApplet.do";
              String host = Principal.documentBase.getHost( );
              URL direccion = new URL( "http", host, 8080, serv );
              // Create conection
              URLConnection connection = direccion.openConnection( );
              connection.setDoInput( true ); 
              connection.setDoOutput( true );
              connection.setUseCaches( false );
              connection.setRequestProperty( "Content-Type", "application/x-java-serialized-object" );
              ObjectOutputStream output;
              output = new ObjectOutputStream( connection.getOutputStream( ) );
              output.writeObject( new Boolean(true) );
              output.flush( );
              output.close( );
              ObjectInputStream input = new ObjectInputStream( connection.getInputStream( ) ); //<-- Here is the problem
              ListasComponentesSeleccionables response = new ListasComponentesSeleccionables( );
              response = ( ListasComponentesSeleccionables ) input.readObject( );
              return response;
         }Servlet:
    ublic class CargarListasComponentesAppletAction extends Action {
    public ActionForward execute(     ActionMapping mapping,
                                                     ActionForm form,
                                                     HttpServletRequest request,
                                                     HttpServletResponse response )
                            throws ServletException, IOException, Exception  {
              InitialContext context = new InitialContext();
              SensorManagerService sensor_service;
              ActuatorManagerService actuator_service;
              Globals.LOGGER_SECURITY.debug( "Entering ACTION 'CargarListasComponentesAppletAction'" );
              response.setContentType("application/x-java-serialized-object");
              try
                   ObjectInputStream bufferentrada = new ObjectInputStream(request.getInputStream());
                   Boolean peticionOK = (Boolean)bufferentrada.readObject();
                   ObjectOutputStream buffersalida = new ObjectOutputStream(response.getOutputStream());
                   sensor_service = ( SensorManagerService ) context.lookup( "desaladora/SensorManagerServiceBean/local" );
                   ArrayList<AlarmConnectedSensorDTO> sensorList = sensor_service.findAllSensorsToAlarms();
                   actuator_service = ( ActuatorManagerService ) context.lookup( "desaladora/ActuatorManagerServiceBean/local" );
                   ArrayList<AlarmConnectedActuatorDTO> actuatorList = actuator_service.findAllActuatorsToAlarms();
                   buffersalida.writeObject( crearListasSeleccionables(sensorList, actuatorList) );
                   buffersalida.flush();
              catch(Exception e)
                   System.out.println("Error en la trasmision de datos");
              return null;
         private ListasComponentesSeleccionables crearListasSeleccionables(ArrayList<AlarmConnectedSensorDTO> sensorList,
                    ArrayList<AlarmConnectedActuatorDTO> actuatorList) {
              Vector<Integer> vectorSensores = new Vector<Integer>();
              Vector<Integer> vectorActuadores = new Vector<Integer>();
              for(AlarmConnectedSensorDTO sensor : sensorList) {
                   vectorSensores.add(sensor.getIdSensor( ));
              for(AlarmConnectedActuatorDTO actuator : actuatorList) {
                   vectorActuadores.add(actuator.getIdActuator( ));
              ListasComponentesSeleccionables listasComponentesSeleccionables =
                                  new ListasComponentesSeleccionables(vectorSensores, vectorActuadores);
              return listasComponentesSeleccionables;
    }i´ve been running some test in another computer, and this code simply works, but it doesn´t work in the machine i usually work.
    Maybe someway the stream get corrupt? the info i´ve been trying to send and started throwing the exception may still be in the stream? I don´t know what to think right now.
    Hope someone has any idea, thankyou.

    I dont see the problem. However, I suggest you change this;
    System.out.println("Error en la trasmision de datos"); t
    to e.printStackTrace() to see what it is doing when it stops working.
    I also suggest peppering your code with System.out.println() statements to see what it is doing just before stopping.
    Also, try your code with a brand new file with only a few characters in it. If it works, add to it some of your originial file content until it stops working. This way, you can determine if its the file size that is causing the crash or something in the file content. If all else fails, study java I/O and try some other way to read/write the file. You can also try a different browser. If it works, its the browser. Still having problems? Create a new project with a simple applet and file read/write program and get that working. That way, all the other stuff in your original project isn't in the way.

  • How to ask for a servlet response into a JSP?

    Hi guys,
    I have the following problem. I developed a servlet able to return a string with some information.
    I would like to see this information from a JSP page. In other words, I would like to encapsule in the jsp page, the info requested to the servlet.
    Is it possible? In this case the servlet returns a piece of HTML text. If there is a way, could it be possible to use the same mechanism for a JSP to ask a servlet to include a picture in the page?
    Many thanks
    /Massimo

    maxqua72 wrote:
    Hi guys,
    I have the following problem. I developed a servlet able to return a string with some information.
    I would like to see this information from a JSP page. In other words, I would like to encapsule in the jsp page, the info requested to the servlet.Just put the result in the request scope and forward the request to the JSP.
    Is it possible? In this case the servlet returns a piece of HTML text. E.g.
    protected void doGet(HttpServletRequest request, HttpServletResponse response) {
        String result = "<b>result</b>";
        request.setAttribute("result", result);
        request.getRequestDispatcher("page.jsp").forward(request, response);
    }page.jsp<p>Result is: ${result}</p>If the servlet actually writes HTML to its response (not so nice) then you can use <jsp:include/> to include it in your JSP page.
    If you want to do it all asynchronously, then indeed consider AJAX.
    If there is a way, could it be possible to use the same mechanism for a JSP to ask a servlet to include a picture in the page?Write an independent servlet for that. You may find this article useful: [http://balusc.blogspot.com/2007/04/imageservlet.html].

Maybe you are looking for

  • Mac book starts to boot, then turns off

    I have Mac Book Pro (13", Yr2011) which will not boot.    It has a 1TB HD which has been partitioned for Mt Lion (primary) and Snow Leopard.  The computer has worked fine in this configuration.    For about 6 wks, the computer was not used and appare

  • Final cut pro gamma correction

    Hello. I bet people have posted this before but after searching I could not find a concrete answer. I have FCP 6 and Color 1.5. My display gamma is at 2.2. I edit my cut in FCP and send it to color. No problems there. I color correct in color and it

  • How do i connect an epson 7900 printer to an apple extreme

    I just purchased an Epson 7900 HDR printer that is in my den. I have it connected with a USB connection on the Airport Extreme to the network connection on the back of the printer.I am trying to print wirelessly from my Imac that is located in anothe

  • ITunes 10.4 & Multimedia Keyboard

    Since I installed iTunes 10.4 for Windows (Windows 7, x64), I can no longer use my Multimedia Keys for Play/Pause and so on. I have a Logitech Illuminated and tried all the usual tricks like mmkeys.dll, but nothing worked. Any help is much appreciate

  • Problem with downloading data from cube into flatfile

    Hi, I am writing a program to download data from cube into flatfile .The program will be run in the background with user has given his selection in a table.the program works fine .The current problem which i am facing is the character length.e.g. Mat