• 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 ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
Sheriffs:
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
Bartenders:
  • 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
Hi..

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
.getLogger(Upload_Ad_imageDAO.class);

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

log.info(name);

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

log.info(filename);

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

log.info(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);
pst.executeUpdate();
log.info(ad_id);
log.info(email);
log.info("Image Sucessfuly Uploaded");
state = true;
} catch (SQLException e) {
log.error(e);
} finally {
if (pst != null) {
pst.close();
}
if (con != null) {
con.close();
}
}
}
}
}


***********************

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

please any can help me solve this problem.


Thanks in Advance.
Arjun Palanichamy.
Chennai.
 
Rancher
Posts: 43028
76
  • 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.

Thanks
Veeresh
 
pie. tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic