Here, some code that you can use to file upload. This code use o'reilly's
jar.
The package is: package com.oreilly.servlet
text of licence:
18 September 1998
This is the README file for the com.oreilly.servlet package.
------------------------------------------------------------
The com.oreilly.servlet package contains a set of (what I hope to be) useful
utility classes for servlet developers. Included are classes to help
servlets parse parameters, handle multipart requests (file uploads),
generate multipart responses (server push), negotiate locales for
internationalization, return files, manage socket connections, and act as
RMI servers, among other things. There's even a class to help applets
communicate with servlets.
Why did I write these classes? They started out as chapter examples in my
book Java Servlet Programming being published by O'Reilly & Associates. Then
one happy day I recognized they could, with a little modification, live on
their own as reusable utility classes. That day, or maybe a few
procrastinating days later, com.oreilly.servlet was born.
The classes in the com.oreilly.servlet package have existed in their current
form more or less unchanged since April 1998. In the six months since April,
they have been widely distributed for testing purposes, but I've kept the
package in official "beta" until now to time its release with the book
release. The reward for everyone's patience is that the classes already have
been widely tested on a multitude of platforms and server configurations,
and you should find this a very stable 1.0 release.
I hope you enjoy using these classes and that they help you write more
powerful and elegant servlets.
/*************** HTML SOURCE ********************/
<html>
<head>
<title>Panel de Control</title>
</head>
<body>
<FORM ACTION="/servlet/FileUpload" METHOD=POST
ENCTYPE="multipart/form-data">
What is your name? <INPUT TYPE=TEXT NAME=submitter> <BR>
Which file to upload? <INPUT TYPE=FILE NAME=file> <BR> <INPUT
TYPE=SUBMIT>
</FORM>
</body>
</html>
/****************************************************/
/******************* JAVA SOURCE *****************/
package archivo;
import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import com.oreilly.servlet.MultipartRequest;
public class SubirArchivo extends HttpServlet {
public void doPost(HttpServletRequest req, HttpServletResponse res)
throws IOException{
res.setContentType("text/html");
PrintWriter out = res.getWriter();
//cargarFile(out, req);
String dir= req.getParameter("quien");
System.out.println(dir);
out.println(dir);
out.close();
}
private void cargarFile(PrintWriter out, HttpServletRequest req){
try {
String dir= req.getParameter("quien");
System.out.println("Directorio: " + dir);
if (dir == null){
dir= ".";
}
MultipartRequest multi = new MultipartRequest(req, dir);
out.println("Params:");
Enumeration params = multi.getParameterNames();
while (params.hasMoreElements()) {
String name = (String)params.nextElement();
String value = multi.getParameter(name);
out.println(name + " = " + value);
}
out.println();
out.println("Files:");
Enumeration files = multi.getFileNames();
while (files.hasMoreElements()) {
String name = (String)files.nextElement();
String filename = multi.getFilesystemName(name);
String type = multi.getContentType(name);
File f = multi.getFile(name);
out.println("name: " + name);
out.println("filename: " + filename);
out.println("type: " + type);
if (f != null) {
out.println("f.toString(): " + f.toString());
out.println("f.getName(): " + f.getName());
out.println("f.exists(): " + f.exists());
out.println("f.length(): " + f.length());
out.println();
}
}
}catch (IOException e){
System.out.println("Error: " + e.toString());
}
}
}
/****************************************************/
Saludos
Jorge Middleton
-----Original Message-----
From: Clair e Simon [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, May 15, 2001 10:18 AM
To: [EMAIL PROTECTED]
Subject: JSP Upload
Hi Everyone,
I'm doing a web site in JSP and I need to upload files in a folder on my
server.
Someone know how to do this or where on the Net I could have more
information?
Thank you
Simon
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets