How to update a file on a server from a JSP page

From: Jérôme VUIBERT (jerome.vuibert_at_fleximage.fr)
Date: 02/27/04


Date: Fri, 27 Feb 2004 16:44:25 +0100

Hi.

I have to update a file on the server where a JSP file is .

To read the previous value, I use an InputStream, and close it.
I then do the update in my object representing the data file.
I use an OutputStream, do the flush, close the stream, but the file still
stay unupdated, and no error is throwed

Can someone give me a solution ?

Jerome

======================

<%@ page language="java" %>
......
<%@ page import="......." %>
<%
  String l_szJalonFileName =
"http://the_server_address/data.xml";
 java.net.URL l_fileURL = null;
 JAXBContext l_jc = null;
 DataClass l_data = null;

 // Read the old value
 try
 {
     l_jc = JAXBContext.newInstance("data.jaxb");
     Unmarshaller unmarshaller = l_jc.createUnmarshaller();
     l_fileURL = new java.net.URL(l_szJalonFileName);
     java.net.URLConnection l_connection = l_fileURL.openConnection();
     java.io.InputStream l_is = l_connection.getInputStream();
     l_data = (DataClass ) unmarshaller.unmarshal(l_is);
     l_is.close();
 }
    catch(Exception e)
    {
     // -- study error messages
    }

    // Update the value in the l_data object

    // Write the new value in the previous file
    try
    {
     Marshaller marshaller = l_jc.createMarshaller();
     java.net.URLConnection l_connection = l_fileURL.openConnection();
     l_connection.setDoOutput(true);
     java.io.OutputStream l_os = l_connection.getOutputStream();
     marshaller.marshal(l_sessionList, l_os);
     l_os.flush();
     l_os.close();
 }
    catch(Exception e)
    {
     // -- study error messages
    }
%>



Relevant Pages

  • Re: Dateien per Socket =?ISO-8859-15?Q?=FCbertragen?=
    ... Offensichtlich geht es darum, dem Server explizit mitzuteilen, dass die Datei zu Ende ist. ... es wird solange vom InputStream "in" gelesen, bis dieser ein EOF liefert, erst ... Wir sagen die Verbindung beginnt im CommMode und mit je nach übertragener Nachricht wechseln wir danach in den TransferMode oder bleiben im CommMode. ...
    (de.comp.lang.java)
  • Re: Socket communication issues.
    ... long time for the reply on the inputstream before finally timing out. ... My server is not Java and I ... Somewhere during this communication the server socket closes for any ...
    (comp.lang.java.programmer)
  • Re: problem getting a db4o file from a server with an Applet
    ... when anyone answers my help request, please send a copy of your ... When I start my Applet I need to retrieve a db4o database file from a server. ... I tried reading the file with an InputStream and then writing it to a FileOutputStream, but this doesn't work, because when trying to write a File, I get some kind of SecurityException. ...
    (comp.lang.java.help)
  • problem getting a db4o file from a server with an Applet
    ... When I start my Applet I need to retrieve a db4o database file from a server. ... I tried reading the file with an InputStream and then writing it to a FileOutputStream, but this doesn't work, because when trying to write a File, I get some kind of SecurityException. ...
    (comp.lang.java.help)
  • http request problem
    ... and it is a jsp file. ... while i am trying to access to another file, from another server it run ... this is the error message i get: ...
    (php.general)