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
- Next message: Len Burman: "concatenate contents of variable with string"
- Previous message: Andrew Thompson: "Re: can not create package"
- Next in thread: Oscar kind: "Re: How to update a file on a server from a JSP page"
- Reply: Oscar kind: "Re: How to update a file on a server from a JSP page"
- Reply: Chris Smith: "Re: How to update a file on a server from a JSP page"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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
}
%>
- Next message: Len Burman: "concatenate contents of variable with string"
- Previous message: Andrew Thompson: "Re: can not create package"
- Next in thread: Oscar kind: "Re: How to update a file on a server from a JSP page"
- Reply: Oscar kind: "Re: How to update a file on a server from a JSP page"
- Reply: Chris Smith: "Re: How to update a file on a server from a JSP page"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|