HTTP Web Server

Hi!
I have to make an http web server: in a browser, I write http://ServerName:port/file and the browser must display the file. The only problem now seems to be that I changed
This line gets the OutputStream of the client socket
out = new PrintWriter(new OutputStreamWriter(scliente.getOutputStream(),"8859_1"),true) ;And this thing sends the response to the browser:
out.println("HTTP/0.9 200 ok");
                out.println("Server: Nombre del Servidor/1.0");
                out.println("Date: " + new Date());
                out.println("Content-Type: text/html");
                out.println("Content-Length: " + file.length());
                out.println(System.getProperty("line.separator"));
                BufferedReader localFile= new BufferedReader(new FileReader(archivo));
                String line= "";
                do         
                    line = localFile.readLine();
                    if (line != null )
                        // sleep(500);
                        out.println(line);
                while (linea!= null);The thing is... That didn't work for displaying images and other file types, which is why I changed the previous code to:
out = scliente.getOutputStream();And the other part to:
byte[] contenido;
                int tamano;
                escribirEnCliente("HTTP/1.1 200 ok");
                escribirEnCliente("Server: Nombre del Servidor/1.0");
                escribirEnCliente("Date: " + new Date());
                escribirEnCliente("Content-Type: " + new MimetypesFileTypeMap().getContentType(archivo));
                escribirEnCliente("Content-Length: " + archivo.length());
                FileInputStream archivoLocal = new FileInputStream(archivo);
                tamano = archivoLocal.available();
                contenido = new byte[tamano];
                do         
                  tamano = archivoLocal.read(contenido);
                  out.write(contenido);
                while (tamano != -1);escribir en cliente is a procedure like this:
public void escribirEnCliente(String str)
            out.write(str.getBytes("8859_1"));
}This way, I thought, I could send all types of files, not only text files. But it doesn't work, it doesn't even load the page. Any suggestions?

...and in your do/while loop think what happens when read() does return -1. You still write the entire buffer. You should do something like this instead:
    while (true) {
        int count = in.read(buf);
        if (count == -1)
            break;
       out.write(buf, 0, count);
    }

Similar Messages

  • Resources for implementing HTTP web server using java

    hi ,
    Thanks for giving your precious time in reading the message.I want to build a HTTP web server using java,which will run on my machine and I can communicate with it through web browser(IE) using HTTP requests and response.
    I know java language, but quite new to network programming.I want to gain enough knowledge on network programming in java.Can you please suggest me good books or any other resources available on the internet for the required subject.Any help will be greatly appreciated.
    my email-id is : [email protected]

    hi there my friend,
    I am writing my own web server too. in w3c there is a sample web server called jigsaw-open source :) and simple-
    I do think it worth trying.
    you can contact me if you want to share some source and info. cause I will.
    [email protected]
    but within 2 weeks I will be back for studying for my web server. you have to wait for a while.

  • IBM HTTP Web Server

    Can one put IBM HTTP Web Server in front of WLS so that all HTTP requets go to IBM HTTP Web Server and redirects to WLS.

    Yes, but I've never tested the plug-in (Apache) for Weblogic with IBM's
    build. (The IBM HTTP server is Apache.)
    Peace,
    Cameron Purdy
    Tangosol, Inc.
    http://www.tangosol.com/coherence.jsp
    Tangosol Coherence: Clustered Replicated Cache for Weblogic
    "SY" <[email protected]> wrote in message
    news:3d2c57b9$[email protected]..
    Can one put IBM HTTP Web Server in front of WLS so that all HTTP requetsgo to IBM HTTP Web Server and redirects to WLS.

  • Strange HTTP/Web Server Problem - HELP ~~~~~~~

    HI all,
    I would like to seek help from you - the apple expert!
    I received my mac mini server and immediate want to setup a web/http server. I encountered one very strange problem that only the mac mini server itself can access the http server page but not all other machines in the same internal network. I tried to troubleshoot and so simplify the setting as follow
    Here is my setting
    - The Web Server service is ON
    - I closed all the built in web services (wiki, cal, blogs, webmail) for troubleshoot
    - I created a "Custom Sites" with 192.168.11.9:8080 <- this is my mac mini ip
    - Ensured the /Library/WebServer/Sites/192.168.11.9 got right permission
    When i open IE in my window vista laptop, type in address "http://192.168.11.9:8080", it doesn't work. Is there anything i need to config so that other machine (Win OS) in the internal network can also access the http server in my mac mini?
    Thank you very much.
    A newbies in mini

    ...and in your do/while loop think what happens when read() does return -1. You still write the entire buffer. You should do something like this instead:
        while (true) {
            int count = in.read(buf);
            if (count == -1)
                break;
           out.write(buf, 0, count);
        }

  • HTTP web server disappeared ?

    Hi there,
    please help me as I cannot connect to the HP HTTP Server in my own LAN any more.
    My HP 8500 a910g is connected to LAN with a static IP 10.0.0.1 assigned.  Up until now, I always used http://10.0.0.1/# to access the web server and a dyndns with portforward to access it from outside.
    Printing and scanning works alright, but when I try to open 10.0.0.1 I only see the following output :
      It works!
    This is the default web page for this server.
    The web server software is running but no content has been added, yet.
    What is going on here and what can I do to restore the Web Server  ?
    Thank you for your help.

    I found the solution - I reenabled Web Server by following this & it works now.
    http://h30434.www3.hp.com/t5/ePrint-Print-Apps-Mobile/Enable-Disable-Web-Services-on-your-printer/td...

  • Oracle 10g HTTP Web Server on Windows 2008 R2 (64-bit) server.

    I downloaded the Oracle 10g HTTP server for Windows 2008 R2 (64-bit) from the link below
    http://www.oracle.com/technetwork/database/10204-winx64-vista-win2k8-082253.html
    10204_vista_w2k8_x64_production_companion.zip (344,455,851 bytes)
    Did anyone have luck installing the 10g HTTP server on a Windows 2008 R2 (64-bit) server ?
    I could see the installation went fine, but I don't see any "Oracle_HTTP" windows service getting created.

    I have not installed on this OS but I'm betting the service is a different name.
    Check "log on as" under services to narrow your search

  • Disabling logging of HEAD request in HTTP web server logs

    Hi,
    I would like to stop the logging of HEAD requests in my HTTP server logs. I was thinking of using the Rewrite rule, however, there may be a more direct way of doing this. Is there a configuration setting within HTTP Server to do this?
    I'm using WebTier component of Weblogic 10.3.2.
    Thanks,

    I found the solution to disable HEAD requests.
    Edited by: WallyP on Mar 11, 2010 12:24 PM

  • DBD/DBI perl modules for HTTP Web Server

    Hi,
    I installed the http webserver from the 9i database CDs. But it seems to come without the DBi and DBD:Oracle modules. Where do I get them for the windows plattform ? binaries preferred.
    Regards
    Knut

    First, check if the version of perl installed is ActiveState's. I doubt it is...at least it's not on my 9.2 version.
    DBI does not seem to be installed, you're right.
    You have two options:
    1) The best way is to ensure you have the same compiler they do (probably MSVC 6.0 SP3), but it's hard to tell and build DBI and DBD::XXXX yourself.
    2) Install ActivePerl and their modules, then force Apache to use that...
    Regards,
    Jeff

  • Web Server code !!

    hi friends !!
    can any1 provide a simple http web server code which also acts as a servlet container. it should also access the form data.
    pls help me...i am in urgent need !!!
    with regards,
    n@v

    Stupid dolt! Ever heard of Tomcat???

  • G web server

    Hello,
    I have an application made in Labview7.1, that should be remotely controled. Also it must be protected with user name and passwords. For that I used G web server from Internet toolkit ver.6.0. I followed the instructions for password protecting the web pages, so the G web server is sharing the same port as the Labview web server, and when I run the VI from Labview enviroment it works fine. But when I build the application, the G web server is returning the error 60, the port is already used by anaother application, that application beeing the Labview web server from the app. How can I get around this?

    Can't you use the G Web Server to both give you remote control and security? I've linked a thorough discussion of using the HTTP Web Server with an executable, which also has links to some additional information on this topic. The discussion even specifically mentions not being able to use both servers on the same port, so you should really switch entirely to the HTTP web server to get both remote control and security. If you can't get things working, feel free post a small example that illustrates your dilemma.
    Kind Regards,
    Message Edited by AESulzer on 11-14-2005 02:54 PM
    E. Sulzer
    Applications Engineer
    National Instruments

  • Sun Web Server Reverse Proxy and Weblogic HTTP to HTTPS redirection

    Hi,
    I am currently testing reverse-proxy from SJSW 7.0 update 5 to Weblogic server but I have encountered an issue.
    I have configured a context root to be forwarded to weblogic:
    Web Server: www.server.com
    URI: /path
    Reverse Proxy URL: wlserver:9000
    When I access https://www.server.com/path, I am getting the correct page. The issue is, the weblogic server is configured to redirect HTTP access to HTTPS, i.e., when I access http://www.server.com/path, it should be redirected to https://www.server.com/path. However, that is not the case. What happens is that I am being redirected instead to https://www.server.com/.
    If I don't use reverse proxy, that is, if I use the libproxy.so from weblogic, I get the correct redirection.
    Would appreciate it very much if someone can help me troubleshoot this issue.
    Thanks in advance!
    Edited by: agent_orange on Jul 29, 2010 2:30 AM
    Edited by: agent_orange on Jul 29, 2010 2:31 AM

    I am not sure, how you have configured your reverse proxy since you didn't attach / refer your current configuration file. this is how I would do it..
    - create a new configuration (using web server 7 admin gui , within configuration wizard, disable java option if you plan to use web server 7 only for reverse proxy)
    - select this new configuration and go to reverse proxy and try to reverse proxy / to the origin server.
    that is all it should need.
    your obj.conf or <hostname>-obj.conf depending on your configuration should look like following snippet
    <Object name="default">
    AuthTrans..
    NameTrans fn=map from="/" to="/path" name="reverse-proxy-/"
    </object>
    <Object name="reverse-proxy-/">
    Route fn=....
    Service ..
    </Object>
    this is all you should need..
    However, if you wanted to add complexity to your configuration, you could do some thing like
    <Object name="default">
    Auth..
    <If defined $security>
    NameTrans fn=map from="/" to="/path" name="reverse-proxy-/"
    </If>
    </Object>
    <Object name="reverse-proxy-/">
    Route...
    </Object>

  • Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout).

    Hi, I am using HP11 and iPlanet web server. When trying to upload files over HTTP using FORM ENCTYPE="multipart/form-data" that are bigger than a few Kilobytes i get a 408 error. (client timeout). It is as if the server has decided that the client has timed out during the file upload. The default setting is 30 seconds for AcceptTimeout in the magnus.conf file. This should be ample to get the file across, even increasing this to 2 minutes just produces the same error after 2 minutes. Any help appreciated. Apologies if this is not the correct forum for this, I couldn't see one for iPlanet and Web, many thanks, Kieran.

    Hi,
    You didnt mention which version of IWS. follow these steps.
    (1)Goto Web Server Administration Server, select the server you want to manage.
    (2)Select Preference >> Perfomance Tuning.
    (3)set HTTP Persistent Connection Timeout to your choice (eg 180 sec for three minutes)
    (4) Apply changes and restart the server.
    *Setting the timeout to a lower value, however, may    prevent the transfer of large files as timeout does not refer to the time that the connection has been idle. For example, if you are using a 2400 baud modem, and the request timeout is set to 180 seconds, then the maximum file size that can be transferred before   the connection is closed is 432000 bits (2400 multiplied by 180)
    Regards
    T.Raghulan
    [email protected]

  • How can I make the web server work on port 80 and not 443. I can only access my website using https.

    On a Mac Mini server with OS X Lion 10.7.2, I am unalbe to get the web server working on port 80. It switches automatically to port 443 (https).
    This situation complicates the access to FileMaker Web publishing, as I don't want my clients having to use https.
    How can I change that? Does anyone know?
    Thanks for any reply

    in the server: I checked the SSL certificate. Tried several configuration.
    Well, that's a problem for a start.
    Your port 80 connection should NOT use SSL. Port 80 is the standard HTTP port, not HTTPS and most applications that connect to port 80 will not expect to use SSL
    If you want to run a site under both HTTP and HTTPS then you create two sites, one on port 80 without SSL and one on port 443 with SSL

  • Web Dynpro application calling external web server using HTTPS giving error

    Hello,
    I don't know whether this is the right question in this forum but my ABAP web-dynpro applicaiton is expected to call another HTTP application on external web server through HTTPS. Presently it is calling through plain HTTP but we want to have HTTPS.
    Here are the steps that we followed based on the link from help.sap.com
    1] Received the certificate files from external web server
    2] Created SSL Anonymous client
    3] Imported the certificate files under this client and added into the certificate list
    4] Re-started ICM
    5] Created RFC Destination of type HTTP to connect to external server with SSL option and basic authentication. This RFC destination was working under plain HTTP.
    When tried with Test connection it gave error "ICM_HTTP_CONNECTION_FAILED".
    Any idea what might be missing. Thanks in advance.
    Regards
    Rajeev

    Used proper certificate after which the error went away

  • Is there a restriction on length of Http request posted to a Iplanet Web Server ?

    I am submitting an Http Request by POST method to my server. The request will be received and forwarded by Iplanet Web Server to a clustered Weblogic environment, which will then be handled by Java Servlets. The problem I am facing is that when the length of the request shoots up to around 2000 bytes, NES doesn't receive and forward the request to Weblogic. There is no fixed cut-off for the length, it keeps fluctuating.
    I observed the following after hitting the server hundreds of times with Http Requests that vary in length.
    1) If length of Request is below 1500 bytes, request always goes through successfully.
    2) In a range of 1500 bytes to 2000 bytes, request fails most of the times. (Around 80 %)
    3) Requests with length above 2000K invariably fail, though it just worked for a 2.4K request on one occasion (out of some 100 hits)
    Note that by "length of request", I mean the data I post through Http Request (I just have a single parameter in Http request having the literal "XML" as key and a well formed XML document as value. That is equivalent to submitting a HTML form just having a text area called "XML" containing a XML document. )
    I presume that the length of actual Http Request is slightly greater than that of XML (probably by around 100 bytes).
    My Iplanet documentation says that the upper limit on the length of a POST Http Request is 64 K, which is way above the value (2-3 K) at which I am facing the problem.

    Hi Ganesh
    Did you check the HTTP Persistent timeout of your server? Check the value which has been set up by default. Try increasing the timeout value and try again.
    follow these steps it might solve your problem:
    (1)Goto Web Server Administration Server, select the server you want to manage.
    (2)Select Preference >> Perfomance Tuning.
    (3)set HTTP Persistent Connection Timeout to your choice (eg 180 sec for three minutes)(note : if you are posting large amount of data or file increase the value accordingly)
    (4) Apply changes and restart the server.
    *Setting the timeout to a lower value, however, may    prevent the transfer of large files as timeout does not refer to the time that the connection has been idle. For example, if you are using a 2400 baud modem, and the request timeout is set to 180 seconds, then the maximum file size that can be transferred before   the connection is closed is 432000 bits (2400 multiplied by 180)
    If this doesnot solve your problem notify me
    regards
    T.Raghulan
    [email protected]

Maybe you are looking for

  • FOR ALL ENTRIES - CDHDR / CDPOS Tables

    Hi, I know there have been a lot of threads concerning the "for all entries" statement. Nevertheless I got a problem downloading the change document tables CDHDR/CDPOS with this statement and I haven't found anything in this forum regarding this spec

  • "Close Project" to be made inactive until a particular phase is reached.

    Hi All , I am having requirement of making "Close Project" under Document tab in Document toolbaras inactive until the Project reaches the final phase of it.what I thght of it is like locking/inactivating the "Close Project" by scripting when the pro

  • Permanent TCP connection

    dear all , my server connects to another server using TCP connection. how do i maintain Permanent TCP Connection . There shud be no timeout . i have not started working on it yet . iam not familiar in socket programming . kindly help ........ thanks

  • Registration is removed after sendNotification call

    Hi All,    I am using Java and com.windowsazure.messaging.NotificationHub wrapper to push notifications to mobile devices. I can successfully register my Android device and then call getRegistration() method without problem, it returns correct result

  • PA30 Problem

    Dear Friends: Using T.code PA30, I entered the personnel no and clicked on change. I get the message No data stored for Travel Privileges in the selected period      Message no. PG009 Diagnosis      No records exist in the chosen period.      The sys