• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

I hot error time of file uploading in servlet/jsp

Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

I had use servlet and jsp for file upload processing, but it's getting some error, i am here paste the my code.

import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Enumeration;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import com.oreilly.servlet.MultipartRequest;
import com.oreilly.servlet.multipart.FilePart;
import com.oreilly.servlet.multipart.MultipartParser;
import com.oreilly.servlet.multipart.Part;

import datasourcefactory.DatabaseConnectionFactory;

public class Upload_Ad_imageDAO {

private static final Logger log = Logger

Connection con = null;

PreparedStatement pst = null;

ResultSet rs = null;

boolean state = false;

public void writeImages(HttpServletRequest req,String ad_id)

throws SQLException , IOException {
String email = null;
HttpSession session = req.getSession(true);

email = (String) session.getAttribute("email");

MultipartRequest multi =

new MultipartRequest(req,ad_id);

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);

File f = new File("X:/work/Uno_Car/web/advertise_images/"+ad_id+".gif");

//out.println("name: " + name);


//out.println("filename: " + filename);


//out.println("type: " + type);

if (f != null) {
String s = f.getName();
try {
con = DatabaseConnectionFactory.getInstance().getDBConnection();
pst = con.prepareStatement("update ad_detail set file_name=? where email=?");
pst.setString(1, ad_id);
//pst.setString(2, type);
pst.setString(2, email);
log.info("Image Sucessfuly Uploaded");
state = true;
} catch (SQLException e) {
} finally {
if (pst != null) {
if (con != null) {


what is wrong here. i not write and upload the image.

please any can help me solve this problem.

Thanks in Advance.
Arjun Palanichamy.
Posts: 43028
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If there's an exception, post the full stack trace. If there's some other error, describe in detail what is happening.
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think the problem is in this line

<Code> File f = new File("X:/work/Uno_Car/web/advertise_images/"+ad_id+".gif");</code>

so please check it out or else post your full track trace.

pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
    Bookmark Topic Watch Topic
  • New Topic