dcsimg
write the textbox values into a file when the file is uploading
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ash123_pps
Posted On:   Friday, May 18, 2007 08:30 AM

hi..... any one help for how to write the textbox values into a file when the file is uploaing inside a folder...i can uploading the files using multipart/form data..but the problem is textbox value is not taking...if i am change the multipart/form data as text/plain then textbox value is not taking...but the file is not uploading...what to do... here is my code.. And my design page is....              Company Name    More>>

hi.....
any one help for how to write the textbox values into a file when the file is uploaing inside a folder...i can uploading the files using multipart/form data..but the problem is textbox value is not taking...if i am change the multipart/form data as text/plain then textbox value is not taking...but the file is not uploading...what to do...
here is my code..
And my design page is....









 


 


        




















Category
Select a file to upload :



 










<%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream" %>
<%@ page import="java.io.FileWriter,java.io.IOException" %>
<%@page contentType="text/html"%>

<%
try
{
String ss="welcome";
String cname=request.getParameter("cname");
out.println(cname);
String category=request.getParameter("category");
String submit=request.getParameter("upload");

String contentType = request.getContentType();
System.out.println("Content type is :: " +contentType);
if ((contentType != null) && (contentType.indexOf("multipart/form-data") >= 0)) {

DataInputStream in = new DataInputStream(request.getInputStream());
int formDataLength = request.getContentLength();

byte dataBytes[] = new byte[formDataLength];
int byteRead =0;
int totalBytesRead =0;
while (totalBytesRead < formDataLength)
{
byteRead = in.read(dataBytes, totalBytesRead, formDataLength);
totalBytesRead += byteRead;
}
String file = new String(dataBytes);
String saveFile = file.substring(file.indexOf("filename="") + 10);
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(0, saveFile.indexOf("
"));
//out.print("FileName:" + saveFile.toString());
saveFile = saveFile.substring(saveFile.lastIndexOf("\") + 1,saveFile.indexOf("""));
//out.print("FileName:" + saveFile.toString());

//out.print(dataBytes);

int lastIndex = contentType.lastIndexOf("=");
String boundary = contentType.substring(lastIndex + 1,contentType.length());
//out.println(boundary);
int pos;
pos = file.indexOf("filename="");

pos = file.indexOf("
", pos) + 1;

pos = file.indexOf("
", pos) + 1;

pos = file.indexOf("
", pos) + 1;


int boundaryLocation = file.indexOf(boundary, pos) - 4;
int startPos = ((file.substring(0, pos)).getBytes()).length;

int endPos = ((file.substring(0, boundaryLocation)).getBytes()).length;



saveFile = "C:\Program Files\Apache Software Foundation\Tomcat 5.5\webapps\ROOT\textfile\textdir\" + saveFile;
FileOutputStream fileOut = new FileOutputStream(saveFile);


//fileOut.write(dataBytes);
fileOut.write(dataBytes, startPos, (endPos - startPos));
if(submit!=null)
{
String strPath = "C:\\Program Files\\Apache Software Foundation\\Tomcat 5.5\\webapps\\ROOT\\textfile\\textdir\\" + saveFile;
File strFile = new File(strPath);
Writer objWriter = new BufferedWriter(new FileWriter(strFile));
objWriter.write(cname );
objWriter.write(category );
objWriter.flush();
objWriter.close();
}
fileOut.flush();
fileOut.close();

out.println("File saved as " +saveFile);
}
}
catch(Exception e)
{
}

%>    <<Less

Re: write the textbox values into a file when the file is uploading

Posted By:   Robert_Lybarger  
Posted On:   Friday, May 18, 2007 06:39 PM

If you honestly want anyone to read your question, you better format the code you pasted in and preview/edit until it looks correct. It is very rude not to. I am *NOT* bothering to read an unformatted dump.....
About | Sitemap | Contact