Home Answers Viewqa JDBC java servlet programming

 
 


neepa
java servlet programming
3 Answer(s)      4 years and 10 months ago
Posted in : JDBC

View Answers

July 29, 2008 at 8:14 PM


Hi friend,

i am sending multiple download file example.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE> New Document </TITLE>
<META NAME="Generator" CONTENT="EditPlus">
<META NAME="Author" CONTENT="">
<META NAME="Keywords" CONTENT="">
<META NAME="Description" CONTENT="">
</HEAD>

<BODY>
<form name="frm" action="dmfile" method="post">
<table>
<tr><td>Download Multiple File</td></tr>
<tr><td><input type="checkbox" name="chk0" value="/check.html">File One</td></tr>
<tr><td><input type="checkbox" name="chk1" value="/okalert.html">File Two</td></tr>
<tr><td><input type="checkbox" name="chk2" value="/pdetails.jsp">File Three</td></tr>
<tr><td><input type="submit" name="download" value="Download"></td></tr>
</table>
</form>
</BODY>
</HTML>

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


July 29, 2008 at 8:15 PM


import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class DownloadMultiFile extends HttpServlet {
final boolean file = true;
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException{
final byte[] CRLF = new byte[]{(byte)'\r', (byte)'\n'};
String boundaryTxt = "--AMZ90RFX875LKMFasdf09DDFF3";

String fname = "" ;
if(req.getParameter("chk0")!=null)
{
fname = req.getParameter("chk0").toString();
if(req.getParameter("chk1")!=null)
{
fname = fname +","+req.getParameter("chk1").toString();

}

if(req.getParameter("chk2")!=null)
{
fname = fname +","+req.getParameter("chk2").toString();
}
}
if(req.getParameter("chk1")!=null)
{
fname = req.getParameter("chk1").toString();
if(req.getParameter("chk2")!=null)
{
fname = fname +","+req.getParameter("chk2").toString();

}
if(req.getParameter("chk0")!=null)
{
fname = fname +","+req.getParameter("chk0").toString();
}
}
if(req.getParameter("chk2")!=null)
{
fname = req.getParameter("chk2").toString();
if(req.getParameter("chk1")!=null)
{
fname = fname +","+req.getParameter("chk1").toString();

}
if(req.getParameter("chk0")!=null)
{
fname = fname +","+req.getParameter("chk0").toString();
}
}

System.out.println("fname :::::::::::::" + fname);
String [] temp = null;
temp = fname.split(",");

System.out.println("temp " + temp.length);


String fileName = "Download_MultiFile";
res.setContentType("multipart/x-mixed-replace;boundary=" + boundaryTxt.substring(2));
// Read from file into servlet output stream
ServletOutputStream stream = res.getOutputStream();
byte[] boundary = boundaryTxt.getBytes();
stream.write(boundary, 0, boundary.length);
stream.write(CRLF, 1, 1);
byte[] contentType = "Content-type: text/plain\n".getBytes();

// Write out a couple of files
for(int i = 0; i < temp.length; i++) {
stream.write(contentType, 0, contentType.length);
byte[] contDisp = ("Content-Disposition: attachment; filename=" + fileName + i + "\r\n\r\n").getBytes();
stream.write(contDisp, 0, contDisp.length);
// Lets read this file???
System.out.println("fname "+ temp[i]);

BufferedInputStream buff = new BufferedInputStream(new FileInputStream(temp[i]));
if (file) System.out.println("Successfully sending file " + i + " to client as '" + fileName + i +"'");
int data = 0;
int byteCnt = 0;
while((data = buff.read()) != -1) {
stream.write(data);
byteCnt++;
}
buff.close();
stream.write(boundary, 0, boundary.length); // write bndry after data
stream.write(CRLF, 1, 1);
if (file) System.out.println("Successfully download file " + i +". " + byteCnt + " bytes");
}// end for(i) outputing files
byte[] endBndry = (boundary + "--").getBytes();
stream.write(endBndry, 0, endBndry.length); // write the ending boundary
stream.close();
}
}

July 29, 2008 at 8:15 PM




Read for more information.

http://www.roseindia.net/servlets/


Thanks.









Related Pages:
java servlet programming - JSP-Servlet
java servlet programming  i want 2 insert the date time into the sql column of data type datetime through servlets dynamically .How 2 do dat
java servlet programming - JDBC
java servlet programming  how to insert value in a column of datatype - datetime in sql 2000 using java servlets???? can ne 1 help me out???  Hi neepa, you have to put the datetime in single quotes. For ex
java servlet programming - JSP-Servlet
java servlet programming  when i m inserting an image file into the sql table in a column of data type binary using prepared statement ps.setBinaryStream, instead of filename it's displaying
java servlet programming - JDBC
java servlet programming  How to insert the value in a column of data type datetime(sql 2000)through prepared statement(java servlets)so that each time when a file is uploaded current datetime gets stored into the column
java servlet programming - JDBC
java servlet programming  Hii! frnds My reqiurement... programming through servlets Thanx   Hi friend, i am sending multiple...)); // Read from file into servlet output stream ServletOutputStream
Programming Error - JSP-Servlet
Programming Error  Hello Sir, how to convert a txt written in textarea of html must get converted to integers and should get displayed..., we have used Javascript and for another one, we have used java. 1
java server programming : servlet - JSP-Servlet
java server programming : servlet  hi all, can you help check what's wrong with my servlet that i have a null pointer exception.Thanks ERROR... servlet request * @param response servlet response */ protected
Programming Error - JSP-Servlet
Programming Error  Hello Sir, import java.util.*; import... Java"); //msg.setSentDate(new Date()); // Set... a " + "plain text e-mail through Java.\n
Programming Error - JSP-Servlet
Programming Error  import java.util.*; import javax.mail.*; import... have to use java mail to send a text message to my clients so i have to use this java mail but i need to understand this code.So please explain me this code
web programming - JSP-Servlet
web programming   Write a JSP page to display the number of hits to this page. (Hint: use application scope of java bean).  Hi Friend, Please visit the following link: http://www.roseindia.net/jsp/simple-jsp
Java(Servlet) - Servlet Interview Questions
Java Servlet examples  Java and Servlet programming examples
programming
Java Constructor programming for single and double constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
servlet
to pass the data from html to the java servlet and also use both doGet...servlet  I have to do a project for my web programming class where we... and zipcode, along with a submit button. along with this I need to create a java
programming
Java no argument constructor programming  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object of in this constructor he we
programming
Java single parameter constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object of in this constructor he we tell
programming
Java parameter constructor  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object of in this constructor he we tell the how much
programming
Constructor in java application  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object of in this constructor he we tell the how
programming
Constructing a constructor in java application  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object of in this constructor he
programming
constructor object in java application programming  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object of in this constructor
programming
Construct a constructor of object in Java programming  write a program which have no argument constructor ,single parameter constructor constructor,double parameter constor,and the now when we create a object
Programming - JSP-Servlet
Programming jsp servlet   Couple of examples that can help to start programming jsp servlet
Programming
Programming  how to save output of java file in .txt format?   Hi, If you are running the example from dos prompt you can use the > bracket to direct the output to a text file. Here is the example: C:>java
Programming error - Java Beginners
Programming error  import javax.servlet.RequestDispatcher; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; public class... function.js in servlet page using RequestDispatcher please reply me?? Here
programming error - Java Beginners
programming error  What is error in this page and how to use RequestDispatcher in servlet to validate it please do reply?? import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.sql.*; import
i have no programming knowledge is it possible for study java?
i have no programming knowledge is it possible for study java?  hello sir i have no programming knowledge is it possible to study java and jsp and servlet and struts.if it is then how i schedule for this and how to study
Java Programming
Java Programming  Hi, What is Java Programming? How I can learn Java Programming in one month? Thanks
Servlet - JSP Programming - JSP-Servlet
to cart or checkout). I'm programming in a servlet getting the input parameters...Servlet - JSP Programming  Hi, I'm writing a jsp page as shown... servlet code is also pasted below. please let me know how to solve
Socket Programming in Servlet - JSP-Servlet
Socket Programming in Servlet  Hi Every One, My problem is little bit different but not difficult i think so, i wrote a servlet and inside that servlet i wrote the socket programming, now my servlet is a server(i
problem in programming - JSP-Servlet
problem in programming  Hi! I am new with jsp. I am facing a problem in programming to calculate the time interval between login time and logout time of user
Java Programming: Other Features of Java
to cover all the features of the Java programming language, or even to give... of the book is to explain programming, not Java. Nevertheless, it can serve... continue your study of Java programming. JAR Files and Resources Each
Programming error - JSP-Servlet
Programming error  Hello Sir, Can u please reply me the code for javamail please actually i watch the javamail.net but i dint understood it. Actually i want to send a mail to my clients with a small text message. Please
programming err - JSP-Servlet
programming err   how to take string from textarea and display output in textbox Please reply me sir . Thank you...  Hi Friend, We are providing you two different codes. For the first one, we have
Programming Error - JSP-Servlet
Programming Error  Image: I want that when user clicks on browse button then a folder of images should get open and when user clicks one image from it (only one not more than that)then it should get displayed on next page
programming - JSP-Servlet
programming  hello, I am doing online exam project using jsp-servlet with oracle database in JBoss application server. I want to retrieve question from database. For the first question I did it successfully.But I want
Programming Error - JSP-Servlet
Programming Error   Place Ad function funct(){ if(document.form.DraftAd.value=="" || document.form.DraftAd.value==null) { document.form.cnt.value=0;} else {document.form.cnt.value
Programming Error - JSP-Servlet
Programming Error   Payment Advertisement Management System Payment Premium Position FrontPage BackPage Other Premium Pages Page 2 Page 3 Page 5 Page 7 Total Cost: How to use switch
Programming Error - JSP-Servlet
Programming Error  Image: Browse When user clicks on Browse Button then a folder of images should get open and when user clicks one of them then the path of that should get saved in Access Database and on next page
Programming Error - JSP-Servlet
Programming Error   Place Order function checkName(text) { if(isNaN(text)){ return 1;} else{alert("Invalid Name! The only... servlet Orders.java works fine. <% Connection con=null; ResultSet rs
Socket Programming in Servlets - JSP-Servlet
Socket Programming in Servlets  How to write a TCP/IP socket program inside a servlet...Is it possible....Please give your suggestions......Thanks in advance
Programming error - JSP-Servlet
Programming error   Payment Advertisement Management System Payment Premium Position FrontPage BackPage Other Premium Pages Page 2 Page 3 Page 5 Page 7 Total Cost: I want that the no of characters
Programming Error - JSP-Servlet
Programming Error   function Draft() { if(document.form.Count.value==""||document.form.Count.value==null) document.form.Count.value=0; else document.form.Count.value = document.form.DraftAd.value.split(' ').length
Programming Error - JSP-Servlet
Programming Error  How to validate login page using jsp where it checks for username whether it is empty or not or is it including number or not if it is the paste alert message.   Hi Friend, Try the following
Programming Error - JSP-Servlet
Programming Error   Place Ad function funct(){ if(document.form.DraftAd.value=="" || document.form.DraftAd.value==null) { document.form.cnt.value=0;} else {document.form.cnt.value
Programming Error - JSP-Servlet
Programming Error   Place Ad Advertisement Management System Create Ad State: City: Main Category: Sub Category: Title: Draft Your Ad Here
Programming Error - JSP-Servlet
Programming Error  Ya States and cities and maincategory and subcategory are combobox and maincategory contains suppose matrimonial then sub category will contain groom and bride, if main category contains vehicals then sub
Programming skills - JSP-Servlet
Programming skills  Hi, I visited this site for the first time.It's excellent. I want 2 improve my programming skills.Can u pls help me in making programs using JSP's and servlets.  Hi friend<html><head><
Programming Error - JSP-Servlet
Programming Error   MainPage body { font-family:arial,helvitica,serif; color:purple; background-color:#717D7D; } ul { list-style-type:none; margin:0; padding:4px; } li { list-style-type:none; padding
Programming Error - JSP-Servlet
Programming Error  Domain Table:-- Rfcdkey DomainName DomainValue DepDomainValue Statcd 1 StateCd Maharashtra Mumbai A 2 StateCd Maharashtra Pune A 3 StateCd Maharashtra Nashik A 4
Programming Error - JSP-Servlet
Programming Error  Place.jsp function func(){ var filename = document.form.img.value; var st=document.form.State.value; var ci=document.form.City.value; var main=document.form.mainCat.value; var sub
Programming error - JSP-Servlet
Programming error   Place Order function checkName(text) { if(isNaN(text)){ return 1;} else{alert("Invalid Name! The only charachters accepted are A - Z and a - z");return 0;} } function checkPhoneNumber

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.