Add library upload image in jsp ม อะไรบ าง

posted 12 years ago

  • Number of slices to send: Optional 'thank-you' note:

Hello I need to send data from a form to a database but... this form have a field input also. I trying to send all the data together (image and input text values) but I can't. Is to say in the database I just get the image but not the input text values! I read in someplace that is not possible but...I had seen that working fine in some websites! What is wrong? Here the code that I am -testing: 1)the jsp form:

  1. and the uploadimage servlet

NOTE: the 2 values showed with System.out.print are null.

Please give me an idea.

THANKS

Skip to Main Content

807603Jan 8 2008 — edited Jan 8 2008

This is my Jsp code for image upload in database:

---Upload.jsp---- <html>

<head>

</head> <body bgproperties="fixed" bgcolor="

CCFFFF">

<form method="POST" action="UploadPicture.jsp" enctype="multiform/form-data">

<%! int update=0; %>

<%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.text.*" %> <%@ page import="java.sql.Date" %> <%@ page import="java.io.*"%>

<%@ page language = "java" %>

<% try { String ct="3"; String path;

File image=new File(request.getParameter("upload")); path=request.getParameter("upload"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");

PreparedStatement pstmt=con.prepareStatement("insert into graphics values(?,?,?)"); pstmt.setString(2,path); pstmt.setString(3,ct);

InputStream is=new FileInputStream(path); pstmt.setBinaryStream(1, is, (int)(image.length())); int s=pstmt.executeUpdate(); if(s>0) { out.println("Uploaded"); } else { %> unsucessfull <%} is.close(); pstmt.close(); } catch(Exception e) { }%> </p>

<p><br> <img src="UploadedPicture.jsp">image</img>

<p></p> </form> </body> </html>

--------- My database name is itPlusElectronics and the table name is "graphics". I have seen as a result of the above code that the image is stored in database as "Long binary data". and database table is look like as follows---

picture path id Long binary data D:\AMRIT\1-1-Picture.jpg 3

---------- To retrive and display i use this JSP code as--

----UploadedPicture.jsp------

<html>

<head>

</head> <body bgproperties="fixed" bgcolor="

CCFFFF">

<%! int update=0; %>

<%@ page import="java.util.*" %> <%@ page import="java.sql.*" %> <%@ page import="java.text.*" %>

<%@ page import="java.io.*"%> <%@ page language = "java" %> <%@page import="javax.servlet.ServletOutputStream"%>

<%

try {

String path; path=request.getParameter("upload1"); Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con = DriverManager.getConnection("jdbc:odbc:itPlusElectronics","","");

PreparedStatement pst = con.prepareStatement("SELECT * FROM graphics WHERE id ='3'"); // pst.setString(3, id); ResultSet rs = pst.executeQuery(); path=rs.getString("path"); if(rs.next()) {

byte[] bytearray = new byte[4096]; int size=0; InputStream sImage; sImage = rs.getBinaryStream(1); response.reset(); response.setContentType("image/jpeg"); response.addHeader("Content-Disposition","filename=path"); while((size=sImage.read(bytearray))!= -1 ) { response.getOutputStream().write(bytearray,0,size) ; } response.flushBuffer(); sImage.close(); rs.close(); }

} catch(Exception e) { } %>

</body> </html>

---------- Now after browsing a jpg image file from client side and pressing submit button ; I am unable display the image in the Upload.jsp file.Though I use <img src="UploadedPicture.jsp">image</img> HTML code in Upload.jsp file .

Now I am unable to find out the mistakes which is needed for displaying the picture in the Upload.jsp page.. If any one can help with the proper jsp code to retrive and display the image ,please please help me !!!!!!!!!!!!!!!!!!!!!!!!!!

กระทู้ที่เกี่ยวข้อง

Toplist

โพสต์ล่าสุด

แท็ก

แปลภาษาไทย ไทยแปลอังกฤษ แปลภาษาอังกฤษเป็นไทย pantip โปรแกรม-แปล-ภาษา-อังกฤษ พร้อม-คำ-อ่าน อาจารย์ ตจต ศัพท์ทหาร ภาษาอังกฤษ pdf lmyour แปลภาษา ชขภใ ห่อหมกฮวกไปฝากป้าmv กรมพัฒนาฝีมือแรงงาน อบรมฟรี 2566 ขขขขบบบยข ่ส ศัพท์ทางทหาร military words หนังสือราชการ ตัวอย่าง หยน แปลบาลีเป็นไทย ไทยแปลอังกฤษ ประโยค การไฟฟ้านครหลวง การไฟฟ้าส่วนภูมิภาค ข้อสอบโอเน็ต ม.3 ออกเรื่องอะไรบ้าง พจนานุกรมศัพท์ทหาร เมอร์ซี่ อาร์สยาม ล่าสุด แปลภาษามลายู ยาวี Bahasa Thailand กรมพัฒนาฝีมือแรงงาน อบรมออนไลน์ การ์ดจอมือสอง ข้อสอบคณิตศาสตร์ พร้อมเฉลย คะแนน o-net โรงเรียน ค้นหา ประวัติ นามสกุล บทที่ 1 ที่มาและความสําคัญของปัญหา ร. ต จ แบบฝึกหัดเคมี ม.5 พร้อมเฉลย แปลภาษาอาหรับ-ไทย ใบรับรอง กรมพัฒนาฝีมือแรงงาน PEA Life login Terjemahan บบบย มือปราบผีพันธุ์ซาตาน ภาค2 สรุปการบริหารทรัพยากรมนุษย์ pdf สอบโอเน็ต ม.3 จําเป็นไหม เช็คยอดค่าไฟฟ้า แจ้งไฟฟ้าดับ แปลภาษา มาเลเซีย ไทย แผนที่ทวีปอเมริกาเหนือ ่้แปลภาษา Google Translate กระบวนการบริหารทรัพยากรมนุษย์ 8 ขั้นตอน ก่อนจะนิ่งก็ต้องกลิ้งมาก่อน เนื้อเพลง ข้อสอบโอเน็ตม.3 มีกี่ข้อ คะแนนโอเน็ต 65 ตม กรุงเทพ มีที่ไหนบ้าง