P
Pradyut
Hi
i m using the commons file upload with jsp...(http://
commons.apache.org/fileupload/)
My form is : -[/QUOTE]
<input type="submit" value="submit" name="Upload" />
</form>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I m able to retrieve the details using this code...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try
{
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Upload</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Upload at " +
request.getContextPath () + "</h1>");
boolean isMultipart = ServletFileUpload.isMultipartContent
(request);
if(isMultipart)
{
ServletFileUpload upload = new ServletFileUpload();
/*List items = upload.parseRequest(request);
Iterator iter = items.iterator();
int count = 0;*/
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext())
{
//count++;
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
out.println("Form field " + name + " with value "
+ Streams.asString(stream) + " detected.");
}
else
{
out.println("File field " + name + " with file
name " + item.getName() + " detected.");
// Process the input stream
}
}
out.println("</body>");
out.println("</html>");
}
}
catch(FileUploadException fue) {
out.print(fue);
}
finally
{
out.close();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
How do i use the "item" object in the else part(not a form field)
to point to a FileItem(org.apache.commons.fileupload.FileItem)
or particularly how do i use to store it to a database blob???
If i use another code for retrieving into FileItem i m getting
exceptions........
DeferredFileOutputStream (probably at the line List /* FileItem */
items = upload.parseRequest(request)
The code is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet UploadServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet UploadServlet at " +
request.getContextPath () + "</h1>");
out.print("<br> This is a test a<br>");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload
(factory);
List /* FileItem */ items = upload.parseRequest
(request);
Iterator iter = items.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
out.print("<br> This is a test a<br>");
}
out.println("</body>");
out.println("</html>");
}
catch(FileUploadException fue) {
out.print(fue);
}
catch(ClassCastException cce) {
out.print(cce);
}
catch(NullPointerException npe) {
out.print(npe);
}
catch(Exception e) {
out.print(e);
}
finally {
out.close();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks
Pradyut
http://pradyut.tk
India
i m using the commons file upload with jsp...(http://
commons.apache.org/fileupload/)
My form is : -[/QUOTE]
<input type="submit" value="submit" name="Upload" />
</form>
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
I m able to retrieve the details using this code...
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try
{
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet Upload</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet Upload at " +
request.getContextPath () + "</h1>");
boolean isMultipart = ServletFileUpload.isMultipartContent
(request);
if(isMultipart)
{
ServletFileUpload upload = new ServletFileUpload();
/*List items = upload.parseRequest(request);
Iterator iter = items.iterator();
int count = 0;*/
FileItemIterator iter = upload.getItemIterator(request);
while (iter.hasNext())
{
//count++;
FileItemStream item = iter.next();
String name = item.getFieldName();
InputStream stream = item.openStream();
if (item.isFormField()) {
out.println("Form field " + name + " with value "
+ Streams.asString(stream) + " detected.");
}
else
{
out.println("File field " + name + " with file
name " + item.getName() + " detected.");
// Process the input stream
}
}
out.println("</body>");
out.println("</html>");
}
}
catch(FileUploadException fue) {
out.print(fue);
}
finally
{
out.close();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
How do i use the "item" object in the else part(not a form field)
to point to a FileItem(org.apache.commons.fileupload.FileItem)
or particularly how do i use to store it to a database blob???
If i use another code for retrieving into FileItem i m getting
exceptions........
DeferredFileOutputStream (probably at the line List /* FileItem */
items = upload.parseRequest(request)
The code is
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
try {
out.println("<html>");
out.println("<head>");
out.println("<title>Servlet UploadServlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>Servlet UploadServlet at " +
request.getContextPath () + "</h1>");
out.print("<br> This is a test a<br>");
FileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload
(factory);
List /* FileItem */ items = upload.parseRequest
(request);
Iterator iter = items.iterator();
while (iter.hasNext())
{
FileItem item = (FileItem) iter.next();
out.print("<br> This is a test a<br>");
}
out.println("</body>");
out.println("</html>");
}
catch(FileUploadException fue) {
out.print(fue);
}
catch(ClassCastException cce) {
out.print(cce);
}
catch(NullPointerException npe) {
out.print(npe);
}
catch(Exception e) {
out.print(e);
}
finally {
out.close();
}
------------------------------------------------------------------------------------------------------------------------------------------------------------------------
Thanks
Pradyut
http://pradyut.tk
India