wood burning stoves 2.0*
The moose likes Servlets and the fly likes how to overwrite an existing document on the server Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "how to overwrite an existing document on the server" Watch "how to overwrite an existing document on the server" New topic
Author

how to overwrite an existing document on the server

pravallika reddy
Greenhorn

Joined: Feb 24, 2002
Posts: 10
hi..
my problem is,when ever i am uploading an existing document on the server.iam gettig internal servererror .i am getting this only for those files r having size more than 3kb.below 3kb.
it is working fine.
i am using linux server.coding part is in jsp.
my code is below..
code:
user=(String)session.getValue("username");
try
{
int i=0,conlen=0;
conlen=request.getContentLength();

InputStream is=request.getInputStream();
DataInputStream dis=new DataInputStream(is);
String id=dis.readLine();
while(!((str=dis.readLine()).equals("")))
{
if(str.indexOf("filename=")>0)
{
name=str.substring(str.indexOf("filename=")+"filename=".length());
String ff=name;
session.putValue("fullname",ff);
conlen=name.lastIndexOf('/');
if(conlen<0)
conlen=name.lastIndexOf('\\');
if(conlen <0) conlen=0;
//out.println("the index :"+conlen+"<br>");
name =name.substring(conlen+1,(name.length()-1));
name=name.replace(' ','_');
session.putValue("file",name);
}
}
rs=docs.displayFiles(user);
while(rs.next())
{
filename=rs.getString(1);
int c=filename.compareTo(name);
out.println("after compare");
if(c==0)
{
out.println("equal");
session.putValue("file1",name);
out.println("in if"+name);
%>
<jsp:forward page="UploadOptions.jsp" />
<%
}
}
fos=new FileOutputStream("/usr/tomcat/webapps/ap123/users/"+user+"/"+name);
byte b[]=new byte[1024];
while(true)
{
i=is.read(b);
if(i<0) break;
conlen=new String(b).indexOf(id);
if(conlen <0)
fos.write(b,0,i);
else
fos.write(b,0,conlen);
}
is.close();
fos.close();
}catch(Exception e){}

thanks
siri
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: how to overwrite an existing document on the server
 
Similar Threads
Problem in uploading file in jsp
Uploading an Image File
Error calling Servlet from java file, while Servlet downloading file from website
How to Upload a image or video where it will be attached or keep in email?
OutOfMemoryError while Data above 16 MB