| Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Spring Framework | Web Services | BioInformatics | Java Server Faces | Jboss 3.0 tutorial | Hibernate 3.0 | XML | ||||
|
||||
|
|
||||
| Tutorial Categories: Ajax
| Articles
| JSP
| Bioinformatics
| Database
| Free
Books |
Hibernate
| J2EE
| J2ME
| Java
| JavaScript
| JDBC
| JMS
| Linux
| MS
Technology |
PHP
| RMI
| Web-Services
| Servlets
| Struts
| UML
|
|
||||||||||||||||||||||||||||||
|
Home | JSP | EJB | JDBC | Java Servlets | WAP | Free JSP Hosting | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs |
||||||||||||||||||||||||||||||
Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.
Copyright © 2007. All rights reserved.
Current Comments
9 comments so far (post your own) View All Comments Latest 10 Comments:excellant tutorial
robost
simple
good for biggen
Posted by mirza on Friday, 10.12.07 @ 15:38pm | #33435
Hi iam developing an application using JSP. I need to download the files and alsoto upload .Could u please suggest me how to proceed
Posted by sameer mohammed on Saturday, 06.23.07 @ 12:17pm | #20017
my doubt is how the textbox values is saved into a file when the file is uploading.that's my problem..any solution for this.
Posted by ashitha on Thursday, 05.24.07 @ 13:33pm | #17146
Hi,
We are developing example application "JSF File Upload". Hopefully it will be done by tomorrow.
Any idea how to upload files using jsf?
You can read File upload in struts in our struts section.
Do you need this application in struts? or jsp application will also work?
Thanks
Posted by Deepak on Thursday, 05.24.07 @ 12:16pm | #17137
hi...why no one replied for my messages..I want ur help very urgently.because i got littlebit confused..about this program.i am trying for this many ways.but i could't get it..so please help me...
Posted by ashitha on Thursday, 05.24.07 @ 10:38am | #17132
hi...
sorry for late reply...i am writing a program for uploading files...that i got.but in the form one textbox values and memu list is included for company name and category level..if i am writing the company name in textbox and category level as level1,level2 etc.then this values is also automatically writing into that uploading file...when the encryption type is set as multipart/form data then the textbox value is not taken..otherwise no uploading is worked..but the text value is null..here is my code
<%@ page import="java.beans.*"%>
<%@ page import="java.lang.*"%>
<%@ page import="java.io.*,javax.servlet.http.HttpServletRequest,javax.servlet.ServletInputStream"%>
<%@ page import="java.io.FileWriter,java.io.IOException "%>
<%@ page contentType="text/html"%>
<html>
<head>
<title>
</title>
</head>
<body>
<p>
<%
try
{
String cname=request.getParameter("cname");
out.println(cname);
String category=request.getParameter("category");
out.println(category);
String ss="welcome";
byte[] buf1=new byte[1024];
buf1=ss.getBytes();
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("\n"));
//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("\n", pos) + 1;
pos = file.indexOf("\n", pos) + 1;
pos = file.indexOf("\n", 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.write(buf1);
fileOut.flush();
fileOut.close();
out.println("File saved as " +saveFile);
}
}
catch(Exception e)
{
}
finally
{
out.println();
}
%>
</p>
<p> </p>
</body>
</html>
and design page is
<html>
<head>
<title>
</title>
</head>
<body>
<p> </p>
<p> </p>
<form name="form1" method="post" action="form2">
<p> </p>
<p>
<label>Company Name<br>
<input name="cname" type="text" id="cname">
</label>
</p>
<p>
<label>Category
<select name="category" id="category">
<option>Level1</option>
<option>Level2</option>
<option>Level3</option>
<option>Level4</option>
<option>Level5</option>
</select>
</label>
<label></label>
</p>
<p>
<input type="submit" name="Submit" value="upload" onClick="store6.jsp">
<label>
<input type="reset" name="Submit2" value="reset">
</label>
</p>
<p> </p>
</form>
<form action="store6.jsp" method="post" enctype="multipart/form-data" name="form2">
<table width="438">
<tr>
<td>Select a File to upload </td>
</tr>
<tr>
<td><label>
<input type="file" name="file" />
</label></td>
</tr>
<tr>
<td><label>
<input name="Upload" type="submit" id="Upload" value="Upload" />
</label>
<label>
<input name="reset" type="reset" id="reset" value="Reset" />
</label></td>
</tr>
</table>
<p> </p>
<p> </p>
</form>
<p> </p>
<br>
</body>
</html>
Posted by ashitha on Wednesday, 05.23.07 @ 14:02pm | #17076
Hi,
Can you explain me what do you want to do in detail? Write the program flow, we will develop the example code for you.
Thanks
Posted by Deepak Kumar on Thursday, 05.17.07 @ 16:25pm | #16264
hi....
In jsp can u explain how to write the values of textbox into a file.....i can upload the file...but after this i can't write the textbox values into that file...but the null valus is coming....why.....i want to uplad the file and write the textbox values into that..
Posted by ashitha on Thursday, 05.17.07 @ 15:15pm | #16253
Thank you very much!
Posted by LondonNewbie on Thursday, 05.10.07 @ 04:00am | #15541