• Post Reply Bookmark Topic Watch Topic
  • New Topic

I hot error time of file uploading in servlet/jsp  RSS feed

Ranch Hand
Posts: 51
  • Mark post as helpful
  • send pies
  • 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: 42975
  • Mark post as helpful
  • send pies
  • 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
  • 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.

With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!