بتاريخ: 28 سبتمبر 20178 سنة comment_290403 السلام عليكم دي السيرفلت اللي انا عملتها ورابطها مع الصوره في خانة ال source ب /displayimage?compid=#{bindings.CompId.inputValue} ولكن مش بيظهرلي الصوره في المتصفح package view;import java.io.IOException;import java.io.OutputStream;import java.io.PrintWriter;import java.sql.Connection;import java.sql.DriverManager;import java.sql.PreparedStatement;import java.sql.ResultSet;import java.sql.SQLException;import javax.naming.Context;import javax.naming.InitialContext;import javax.servlet.*;import javax.servlet.annotation.WebServlet;import javax.servlet.http.*;@WebServlet(name = "DisplayImage", urlPatterns = { "/displayimage" })public class DisplayImage extends HttpServlet { private static final String CONTENT_TYPE = "text/html; charset=UTF-8"; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType(CONTENT_TYPE); String imageId = request.getParameter("compid"); OutputStream os = response.getOutputStream(); Connection conn = null; String imgLen = ""; try { Context ctx = new InitialContext(); conn = getMySQLConnection(); PreparedStatement statement = conn.prepareStatement("SELECT comp_logo FROM company WHERE comp_id = '" + imageId + "'"); ResultSet rs = statement.executeQuery(); if (rs.next()) { //imgLen = rs.getString(1); // int len = imgLen.length(); byte[] rb = rs.getBytes(1); //InputStream readImg = rs.getBinaryStream(1); // int index = readImg.read(rb, 0, len); response.reset(); response.setContentType("image/png"); response.getOutputStream().write(rb); response.getOutputStream().flush(); //response.getOutputStream().close(); } } catch (Exception e) { System.out.println(e); } finally { try { if (conn != null) { conn.close(); } } catch (SQLException sqle) { System.out.println("SQLException error"); } } } public static Connection getMySQLConnection() throws Exception { String driver = "com.mysql.jdbc.Driver"; String url = "jdbc:mysql://localhost:3306/publicsales"; String username = "****"; String password = "******"; Class.forName(driver); Connection conn = DriverManager.getConnection(url, username, password); return conn; }} تم تعديل 28 سبتمبر 20178 سنة بواسطة tolba hamdi_133096 تقديم بلاغ
بتاريخ: 1 أكتوبر 20178 سنة كاتب الموضوع comment_290488 هل تم إرجاع بيانات؟ نعم تم ارجاع بيانات ولكن الصوره لم ترجع تقديم بلاغ
بتاريخ: 2 أكتوبر 20178 سنة كاتب الموضوع comment_290532 يبدو الكود صحيحاً جرب تثبيت القيمة تم حل المشكله الخطأ كان عند عمل السيرفلت كان ال checkbox علي annotation وليس configuriation flie (web.xml) ولكن انا عندي استفسار اخر هذا الكود بيتم عرض الصوره من الداتا بيز وانا اعلم الكود لعرض الصوره من ملف عن طريق مسار الصوره ولكن السؤال هنا ازاي اخلي ال image component ياخد المصدر بتاعه من الداتا بيز عند التنقل بين البيانات او ياخد المصدر بتاعه لما اجي اعمل createinsert واختار الصوره من ملف تقديم بلاغ
بتاريخ: 3 أكتوبر 20178 سنة كاتب الموضوع comment_290553 كيف اربط الصوره بالمسار اللي اختاره المستخدم من خلال ال input file component بدون عمل ابلود للصوره علي السيرفر يعني مجرد ما يعمل بروز للصوره يتم عرضها في ال image component تقديم بلاغ
انضم إلى المناقشة
يمكنك المشاركة الآن والتسجيل لاحقاً. إذا كان لديك حساب, سجل دخولك الآن لتقوم بالمشاركة من خلال حسابك.