java servlet programming
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();
}
}
Related Tutorials/Questions & Answers:
java servlet programming - JSP-Servletjava 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
Advertisements
java servlet programming - JDBCjava servlet programming Hii!
frnds
My reqiurement...
programming through servlets
Thanx
Hi friend,
i am sending multiple...));
// Read from file into
servlet output stream
ServletOutputStream
java servlet programming - JDBCjava 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 - JDBCjava 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 server programming : servlet - JSP-Servletjava 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
Socket Programming in Servlet - JSP-ServletSocket
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
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
Programming Error - JSP-ServletProgramming 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
Programming Error - JSP-ServletProgramming 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
problem in programming - JSP-Servletproblem 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
Programming Error - JSP-ServletProgramming Error Hello Sir,
import java.util.*;
import...
Java");
//msg.setSentDate(new Date());
// Set... a " +
"plain text e-mail through
Java.\n
Programming Error - JSP-ServletProgramming 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
Programming error - JSP-ServletProgramming 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-Servletprogramming 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-ServletProgramming 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-Servletprogramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming Error
Place Ad
Advertisement Management System
Create Ad
State:
City:
Main Category:
Sub Category:
Title:
Draft Your Ad Here
Programming Error - JSP-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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-ServletProgramming 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
Programming error - JSP-ServletProgramming error Actually there is an error in placeorder.jsp file where there are 5 fields OrderNo ,Name , Address, Email, PhoneNo
where if I delete an order of client based on orderno then suppose in database if there are 5
programming error - JSP-Servletprogramming error
Place Order
function Validate()
{
var valid=true;
if(document.forms.OrderNo.value=="")
{ alert("Please enter valid OrderNo");
valid=false;
}
if(document.forms.Name.value
Programming Error - JSP-ServletProgramming Error
Place Ad
Advertisement Management System
State:
City:
Main Category:
Sub Category:
Title:
Draft Your Ad Here:
Count:
Image
Another Image
Email:
Phone No:
Select Newspaper
Programming Error - JSP-ServletProgramming Error
Place Ad
function func()
{
var filename = document.form.img.value;
window.location.href=("http://localhost:8080/ProjectAd/Preview?
filename="+filename);
}
function Draft
Programming error - JSP-ServletProgramming error Place.jsp code
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-ServletProgramming error Register.jsp
Registration Form
function checkName(text)
{
if(isNaN(text)){ return 1;}
else{alert("Invalid Name! The only charachters accepted are A - Z and a - z");return 0
Programming error - JSP-ServletProgramming error
--%>
Place Order
function Validate()
{
var valid=true;
if(document.forms.OrderNo.value=="")
{ alert("Please enter valid OrderNo");
valid=false;
}
if(document.forms.Name.value
Programming Error - JSP-ServletProgramming Error import javax.servlet.*;
import java.io.*;
import javax.servlet.http.*;
import java.sql.*;
public class UpdateOrd extends HttpServlet
{
public void doPost(HttpServletRequest req,
HttpServletResponse
web programming - JSP-Servletweb 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 ProgrammingJava Programming Hi,
What is
Java Programming? How I can learn
Java Programming in one month?
Thanks
Programming in JDBC and JSP - JSP-ServletProgramming in JDBC and JSP Write a program using JDBC and JSP to display the names and addresses of all those MCA students at your study centre who have completed/submitted their theory assignments of all the courses of IV
Programming Help URGENT - JSP-ServletProgramming Help URGENT Respected Sir/Madam,
I am R.Ragavendran. I am in urgent need of the coding. My requirement is as follows:
Beside Enter Employee ID text Box, There must be a small button. When user clicks
java programming java programming Companies and people often buy and sell stocks... in question
Implement the program described above using the
Java programming language...
programming method you want to accomplish this task.
Both your stack and queue
java programming java programming Companies and people often buy and sell stocks... in question
Implement the program described above using the
Java programming language...
programming method you want to accomplish this task.
Both your stack and queue