Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa JSP-Servlet File Upload And download JSP Urgent
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Ragavendran.R
File Upload And download JSP Urgent
2 Answer(s)      6 years and 3 months ago
Posted in : JSP-Servlet



Advertisement
View Answers

September 8, 2008 at 4:42 PM


Hi Ragavendran,


i am sending code of file download in jsp. Plz implement this code.


<%@ page import="java.sql.*,java.io.*,java.util.*" %>

<HTML>

<HEAD>

<TITLE>file download in jsp</TITLE>

</HEAD>



<BODY>


<br><br>

<table align="center" border="1" width="400px" cellspacing="0" cellpadding="0" bgcolor="bluelight">

<tr>

<td colspan=2 align="center"><font color="red"><b>File download</b></font></td>

</tr>

<tr><td colspan=2>&nbsp;</td></tr>

<%
Connection con = null;
String url = "jdbc:mysql://192.168.10.211:3306/";;
String db = "amar";
String driver = "com.mysql.jdbc.Driver";
String userName ="amar";
String password="amar123";



try{

Class.forName(driver);
con = DriverManager.getConnection(url+db,userName,password);

Statement stmt=con.createStatement();

String strQuery = "select id from FileUpload";

ResultSet rs = stmt.executeQuery(strQuery);

int sno=0;

while(rs.next())

{

sno++;

%>

<tr>

<td><b><%=sno%></b></td>

<td align="center"><a href="fileShow.jsp?imgid=<%=rs.getString(1)%>"><a href="fileShow.jsp?imgid=<%=rs.getString(1)%>">Click on link for file Download</a></td>

</tr>

<%

}

rs.close();

con.close();

stmt.close();

}

catch(Exception e){

System.out.println("SQl connot Execute: " +e.getMessage());

}

%>



</table>



</BODY>

</HTML>


September 8, 2008 at 4:44 PM


<%@ page import="java.sql.*,java.io.*,java.util.*" %>

<%



String connectionURL = "jdbc:mysql://192.168.10.211:3306/amar";;

if(request.getParameter("imgid")!=null && request.getParameter("imgid")!="")

{

int id = Integer.parseInt(request.getParameter("imgid"));



String filename = "fileShow"+id+".java";
System.out.println("id " + id);

Connection con=null;

try{

Class.forName("com.mysql.jdbc.Driver").newInstance();

con=DriverManager.getConnection(connectionURL,"amar","amar123");

Statement st1=con.createStatement();

String strQuery = "select filename from FileUpload where id="+id;



ResultSet rs1 = st1.executeQuery(strQuery);

String imgLen="";
System.out.println("strQuery " + strQuery);

if(rs1.next()){

imgLen = rs1.getString(1);

}

rs1 = st1.executeQuery(strQuery);

if(rs1.next()){

int len = imgLen.length();

byte [] rb = new byte[len];

InputStream readImg = rs1.getBinaryStream(1);

int index=readImg.read(rb, 0, len);

st1.close();

response.reset();

response.setContentType("text/html");

response.setHeader("Content-disposition","attachment; filename=" +filename);

response.getOutputStream().write(rb,0,len);

response.getOutputStream().flush();

}

}

catch (Exception e){

e.printStackTrace();

}

}

%>


----------------------------------------

Read for more information.

http://www.roseindia.net/jsp/fileupload.shtml

Thanks.

Amardeep.



Related Tutorials/Questions & Answers:
File Upload And download JSP Urgent - JSP-Servlet
File Upload And download JSP Urgent  Respected Sir/Madam, I... Download in JSP.. In the Admin window, There must be "Upload" provision where admin... Ragavendran, i am sending code of file download in jsp. Plz implement this code
Upload and download file - JSP-Servlet
Upload and download file  What is JSP code to upload and download... the word document file: 1)page.jsp Display file upload form to the user UPLOAD THE FILE Choose the file To Upload: 2
Advertisements
Upload and Download in JSP - JSP-Servlet
and downloading a file in JSP.. When the admin clicks upload, he must be able to upload.... Please visit for more information. http://www.roseindia.net/jsp/file_upload...Upload and Download in JSP  Respected Sir/Madam, I am
file upload download - Java Beginners
file upload download  how to upload and download files from one system to another using java.io.* and java.net.* only please send me code
upload and download files - JSP-Servlet
and download files in JSP visit to : http://www.roseindia.net/jsp/file_upload...upload and download files  HI!! how can I upload (more than 1 file) and download the files using jsp. Is any lib folders to be pasted? kindly
upload and download a file - Java Beginners
upload and download a file  how to upload a file into project folder in eclipse and how to download the same using jsp   Hi Friend, Try the following code: 1)page.jsp: Display file upload form to the user
Upload and Download Large files in jsp
Upload and Download Large files in jsp  I am not able to download large files (>200mb) from any server. I need a code to download and upload large files (atleast 4 gb) to a server using jsp page
java code to upload and download a file - Java Beginners
and Download visit to : http://www.roseindia.net/jsp/file_upload/index.shtml http...java code to upload and download a file  Is their any java code to upload a file and download a file from databse, My requirement is how can i
File Download in jsp
File Download in jsp  file upload code is working can u plz provide me file download
how to upload and download images using buttons in jsp?
how to upload and download images using buttons in jsp?  how to upload and download images using buttons in jsp
code to upload and download a file - Java Magazine
code to upload and download a file  Is their any code to upload a file and download a file from databse, My requirement is how can i store two... user send one a.doc file to x ,he has to download his a.doc another user sends
upload ,download and update file document - JDBC
upload ,download and update file document   hi sir.i am creating one application in jsp in which i need to upload the word document file which... to upload the word file: 1)page.jsp Display file upload form
jsp upload file to server
jsp upload file to server  How to create and upload file to server in JSP?   Find the given example that explains how to upload single and multiple file on server using JSP
Download file - JSP-Servlet
Servlet download file from server  I am looking for a Servlet download file example
Image upload file - JSP-Servlet
://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml http://www.roseindia.net/jsp/file_upload/Sinle_upload.xhtml.shtml Thanks...Image upload file  I want a code for image upload jsp or servlet
File upload - JSP-Servlet
File upload  I am trying to do a file upload program. But, it shows... ----------------------------------------------------------------------------- Display file upload form to the user <... the file To Upload
File upload - JSP-Servlet
File Uload Using JSP   Choose the file To Upload...File upload  Hello Friends, In my JSP project i want to do a file upload part. For this, i designed two files one for input and other
File upload in JSP
File upload in JSP  hi! In my previous interview i got two questions which i could not answer regarding file upload and annotations. I want to know which is the best method can be used for file upload. Whether moving them
file upload using JSP
file upload using JSP  I have created a form to upload a file in a html page, now i want to get the path of the file in a jsp page so what code...="java" %> <HTML> <HEAD><TITLE>Display file upload form
File Upload - JSP-Servlet
File Upload  Hi everyone, I am facing file uploading problem.the multiple file upload code of roseindia is working on localhost but the same code is not working on server.i think the package commons-fileupload-1.2.jar
upload and download mp3
upload and download mp3   code of upload and download Mp3 file in mysql database using jsp and plz mention which data type used to store mp3 file in mysql database
JSP file download - JSP-Servlet
JSP file download  Hi! I am saving (webapp/docs/sample.docx) path of the word file in database. when i want to download that file i am eliminating... to download word file: <% ServletOutputStream output
file upload error - JSP-Servlet
file upload error  Hello friends, In my project when i am trying to upload a file i used the roseindia.net coding from URL: http://www.roseindia.net/jsp/file_upload/employee_upload_profile_image.shtml
upload and download all kinds of files in jsp - Java Beginners
upload and download all kinds of files in jsp  how to upload and download all kinds of files ex: image file,pdf,.xls in jsp. your help is highly appreciated.  we can upload the all type s of files into oracle 10g
Upload and Download multiple files
link: http://www.roseindia.net/jsp/file_upload/uploadingMultipleFiles.shtml...Upload and Download multiple files  Hello Sir/Madam, I need a simple code for upload and download multiple files(it may be image,doc
file upload error - JSP-Servlet
file upload error  Iam doing jsp project. File uploading is one part... ----------- file upload example... file while checkin file size. I am not able to understand this problem
file upload in jsp - Java Beginners
file upload in jsp  how to upload a file using jsp. my operating...: Display file upload form to the user UPLOAD THE FILE   Choose the file To Upload:   2
FTP FILE UPload - JSP-Servlet
FTP FILE UPload  Hi sir, i am doing the file upload via ftp. the program compiled well . but while executing i am getting the below errors... response. Please help me to this solution .Its Urgent. Thank U
file upload in jsp - Java Beginners
file upload in jsp  how to upload a file in jsp and store it in my... += byteRead; } String file = new String(dataBytes); String saveFile...)).getBytes()).length; File f = new File("C:\\"+saveFile); FileOutputStream fileOut
file upload error - JSP-Servlet
file upload error  Iam doing jsp project. File uploading is one part... file while checkin file size. I am not able to understand this problem..., can you send me all file of uploading code. Because here all file uploading
Creat a folder, inside it upload and download files in jsp and mysql
Creat a folder, inside it upload and download files in jsp and mysql  Create one or more folder .inside it we can upload and download multiple files   Here is an application that will upload the file and save
 

 

 

DMCA.com