Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to overwrite an existing document on the server

 
pravallika reddy
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic