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

Fresher Job


 

Search Host

Monthly Fee($)
Disk Space (MB)
Register With us for Newsletter!
Visit Forum! Post Questions!
Jobs At RoseIndia.net!

Have tutorials?
Add your tutorial to our Java Resource and get tons of hits.

We offer free hosting for your tutorials. and exposure for thousands of readers. drop a mail
roseindia_net@yahoo.com
 
   

Tutorials

Java Server Pages

JAXB

Java Beans

JDBC

MySQL

Java Servlets

Struts

Bioinformatics

Java Code Examples

Interview Questions

 
Join For Newsletter

Powered by groups.yahoo.com
Visit Group! Post Questions!

Web Promotion

Web Submission

Submit Sites

Manual Submission?

Web Promotion Guide

Hosting Companies

Web Hosting Guide

Web Hosting

Linux

Beginner Guide to Linux Server

Frameworks

Persistence Framework

Web Frameworks

Free EAI Tools

Web Servers

Aspect Oriented Programming

Free Proxy Servers

Softwares

Adware & Spyware Remover

Open Source Softwares

Uploading multiple files in JSP
Expert:sam
Hi,

I have this code in JSP for Uploading multiple files :

<html>
<%@ page language="java" import="javazoom.upload.*,java.util.*,java.sql.*" %>



<jsp:useBean id="upBean" scope="page" class="javazoom.upload.UploadBean" >
<jsp:setProperty name="upBean" property="folderstore" value="F:/Program Files/CA/Unicenter Service Delivery/view/webapps/upload/Attach_doc"/>
</jsp:useBean>
<!-- <jsp:useBean id="bean" scope="page" class="javazoom.upload.attach" ></jsp:useBean> -->
<head>
<title>Samples : Simple Upload</title>
<style TYPE="text/css">
<!--
.style1 {
font-size: 12px;
font-family: Verdana;
}
-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body onload="parent.resizeTo('300','500'); moveTo(0,0);" background = 'background.JPG'>
<ul class="style1">

<%
String i1=request.getParameter("req");
out.println(i1);
int i2=Integer.parseInt(request.getParameter("role"));
%>
<%

if (MultipartFormDataRequest.isMultipartFormData(request))
{
// Uses MultipartFormDataRequest to parse the HTTP request.
MultipartFormDataRequest mrequest = new MultipartFormDataRequest(request);
String todo = null;
String userid="";
if (mrequest != null) { todo = mrequest.getParameter("todo"); userid = mrequest.getParameter("Userid");}
if ( (todo != null) && (todo.equalsIgnoreCase("upload")) )
{ try{

String filename="";
Hashtable files = mrequest.getFiles();
if ( (files != null) && (!files.isEmpty()) )
{
UploadFile file = (UploadFile) files.get("uploadfile");
file.setFileName(file.getFileName());
filename=file.getFileName();
if (file != null) out.println("<li>Form field : uploadfile"+"<BR> Uploaded file : "+file.getFileName()+" ("+file.getFileSize()+" bytes)"+"<BR> Content Type : "+file.getContentType());
// Uses the bean now to store specified by jsp:setProperty at the top.
upBean.store(mrequest, "uploadfile");
//out.println(bean.insert());
}
else
{
out.println("<li>No uploaded files");
}



Class.forName("com.microsoft.jdbc.sqlserver.SQLServerDriver");
//out.println("InitiLIZE");
String url="jdbc:microsoft:sqlserver://e-dhq-sladbdv:1433;databaseName=mdb";
//out.println("Conected");
Connection con1 = DriverManager.getConnection(url,"usmuser","usmuser");
//out.println("con obj");
Statement stmt=con1.createStatement();
String s1="insert into zusm_Attachment (userID,role_id,document) values ('"+request.getParameter("req")+"',"+request.getParameter("role")+",'"+filename+"')";

//out.println(s1);

stmt.executeUpdate(s1);
}catch(Exception e){
out.println(e);
}
}
else out.println("<BR> todo="+todo);
}
%>
</ul>


<form method="post" action="SimpleUpload1.jsp?req=<%=i1%>&role=<%=i2%>" name="upform" enctype="multipart/form-data">
<br><br><center><font size=5><b>Upload Attachment</b></font></center><br>
<table width="95%" border="0" cellspacing="1" cellpadding="1" align="center" class="style1">
<tr>
<td align="left">
<br><br>
<b>User ID:</b>
</td>
<td>
<INPUT TYPE="text" NAME="userID" size="30" value=<%=i1%> readonly>
</td>
<INPUT TYPE="hidden" name="role" value=<%=i2%>>
</tr>
<tr>
<td align="left">
<b>Select a file to upload :</b>
</td>

</tr>
<tr>
<td align="center">
<input type="hidden" name="todo" value="upload">
</td>
<td>
<input type="file" name="uploadfile" id="uploadfile" onchange="document.getElementById('moreUploadsLink').style.display = 'block';" />
<div id="moreUploads"></div>
<div id="moreUploadsLink" style="display:none;"><a href="javascript:addFileInput();">Attach another File</a></div>

<script>
var upload_number = 2;
var test="null";
function addFileInput() {
var d = document.createElement("div");
var file = document.createElement("input");
file.setAttribute("type", "file");
file.setAttribute("name", "uploadfile"+upload_number);
d.appendChild(file);
document.getElementById("moreUploads").appendChild(d);
upload_number++;
var test = upload_number;

}
</script>
<Center><input type="submit" name="Submit"value="Upload">
&nbsp;&nbsp;&nbsp;&nbsp;
<input type="submit" value="Close" onclick="window.close()"></Center>
</td>
</tr>
</table>
<br>
<br>
<table border="0" cellspacing="1" cellpadding="0" align="center">
<tr>
<td bgcolor="#666666">

</td>
</tr>
</table>
</form>
</body>
</html>



Now when ever I am clicking on the upload button only the first file is getting uploaded. Please tell me what modification I need to do in the code to upload all the files attached.
Answers
Hi Friend,

Please visit the following link:

http://www.roseindia.net/jsp/file_upload/uploadingMultipleFiles.shtml

Hope that it will be helpful for you

Thanks

More Questions
Post Answers
 
Ask Question Facing Programming Problem?
Useful Links
  JDO Tutorials
  EAI Articles
  Struts Tutorials
  Java Tutorials
  Java Certification

Tell A Friend
Your Friend Name
Search Tutorials

 

 
 
Browse all Java Tutorials
Java JSP Struts Servlets Hibernate XML
Ajax JDBC EJB MySQL JavaScript JSF
Maven2 Tutorial JEE5 Tutorial Java Threading Tutorial Photoshop Tutorials Linux Technology
Technology Revolutions Eclipse Spring Tutorial Bioinformatics Tutorials Tools SQL
 

Home | JSP | EJB | JDBC | Java Servlets | WAP  | Free JSP Hosting  | Search Engine | News Archive | Jboss 3.0 tutorial | Free Linux CD's | Forum | Blogs

About Us | Advertising On RoseIndia.net

Send your comments, Suggestions or Queries regarding this site at roseindia_net@yahoo.com.

Copyright © 2007. All rights reserved.