Applet qanday qilib rasmni veb-serverga o'tkazishi mumkin

Men imzo to'plami bilan bog'laydigan va tasvirni ushbu kod bilan bir faylga yozish imkoniyatiga ega bo'lgan ilovada ishlayapman:

sigObj.setImageXSize(30);
sigObj.setImageYSize(10);
sigObj.setImageJustifyMode(5);
sigObj.setImagePenWidth(5);
BufferedImage sigImage = sigObj.sigImage();
try
{
int w = sigImage.getWidth(null);
int h = sigImage.getHeight(null);
int[] pixels = new int[(w * h) * 2];

sigImage.setRGB(0, 0, 0, 0, pixels, 0, 0);
FileOutputStream fos = new
FileOutputStream("c:\\_img\\sig.jpg");
JPEGImageEncoder jpeg = JPEGCodec.createJPEGEncoder(fos);
jpeg.encode(sigImage);
fos.close();                            
}
catch (java.io.IOException exception) { System.out.println("Error IO Exception."); }

Maqsad, faylni veb-serverga uzatish va oxir-oqibatda .jpg yoki .bmp tasvirini Oracle blobiga joylashtirishdir. Buning eng yaxshi yo'li qanday?

Bu erda faqat taxmin:

Boshqaruv 1:
Applet .jpg faylini hex kodli mag'lubiyatga yozib olishi, mag'lubiyatni yashirin ariza maydoniga ko'chirish va keyinroq oraclening yashirin maydonni o'qiy oladigan va pl/sqldagi bl/sqlda blobVar: = HEXTORAW (url ("sigJpg"));

2-usul:
Dasturni POST qilish va faylni topshiring

Mening java ko'nikmalarim juda yashil, shuning uchun men ushbu uslublardan birortasining tavsiya etilishiga ishonchim komil emas. Fayl veb-serverga ko'chirilgandan so'ng, men uni Oracle pl/sql-dan foydalanib JBga kiritish uchun yo'l topa olaman deb o'ylayman. Faylni veb-serverga qanday qilib olish mumkinligiga ishonchim komil emas.

1

2 javoblar

Your method 2 is the method you should implement. Actually it is not a so huge problem. Here is a good example for you: http://www.exampledepot.com/egs/java.net/Post.html

URL manzilidan siz faylni yozayotganda bajarganingizdagidek, rasmingizni oqimga yozishingiz kerak.

Lekin bu etarli emas. Server tomonini amalga oshirishingiz kerak. Odatda servletni amalga oshirishingiz va o'zingizning postingizni olishingiz mumkin bo'lgan doPost() usulini bekor qilishingiz kerak. Keyin kerakli narsani bajaring: JDBC ulanishini oching va faylni JBga yozing. Ushbu yondashuvni tavsiya qilmasam ham, sizda JBB BLOB bilan aloqasi yo'q. Yaxshiroq yo'l - bu fayl tizimiga rasm yozish va faqat JBga yo'lni saqlashdir.

Umid qilamanki, sizlarga etarli maslahatlar berdi. Qo'shimcha ma'lumotlarni 2 daqiqalik googleing orqali topishingiz mumkin. Omad.

0
qo'shib qo'ydi
Misol yordamida, rasm URL manziliga yoziladi (va mahalliy fayl tizimiga hech qachon ta'sir qilmaydi). Vay, bu yaxshi bo'lar edi. JDBC dan foydalanishni xohlamayman. Ilova o'rnatilgan veb-sahifada sessiya/cookie-fayllari mavjud. Haqiqatan ham bu http-pochtasi bilan (agar u hozir bo'lmasa) uzatilgan bo'lsa yaxshi bo'lardi .Shuningdek, tasvirni blob sifatida saqlash ham, uni kimlar ko'rishi mumkinligini cheklash imkonini beradi.
qo'shib qo'ydi muallif Brian McGinity, manba

Ishladim. Men 2004 yildan buyon birovni topdim. Bitta farq - bu faylni joylashtirishdan oldin heksli qatorga aylantiraman. Buni qilishning yagona sababi - men olti burchakni qanday qilib Oracle-dagi blobga aylantirishni bilaman.

private String byteToString(byte[] data) {

    String text = new String();

    for ( int i = 0; i < data.length; i++ )
        text += (char) ( data[i] & 0x00FF );
    return text;
}

private static String bytesToHexString(byte[] bytes) {   
    StringBuilder sb = new StringBuilder(bytes.length * 2);   

    Formatter formatter = new Formatter(sb);   
    for (byte b : bytes) {   
        formatter.format("%02x", b);   
    }   

    return sb.toString();   
}  


public void writeImageToServer(URL scriptURL, BufferedImage img){
 try {
        ByteArrayOutputStream jpegOutput = new ByteArrayOutputStream();
        JPEGImageEncoder encoder = JPEGCodec.createJPEGEncoder(jpegOutput);

        encoder.encode(img);//imagedata are coded here

        HttpURLConnection urlConnection = (HttpURLConnection)
        scriptURL.openConnection();
        urlConnection.setDoOutput(true);
        urlConnection.setDoInput(true);
        urlConnection.setUseCaches(false);

        urlConnection.setRequestMethod("POST");
        urlConnection.setRequestProperty("Content-type", "application/x-www-form-urlencoded");

        byte[] imageData = jpegOutput.toByteArray();

        //String imageString = byteToString(imageData);    //if you want a string
        String imageString = bytesToHexString(imageData);  //if you want hex string
        String content = "img=" + URLEncoder.encode (imageString,"UTF-8");

        urlConnection.setRequestProperty("Content-length", String.valueOf(content.length()));

        OutputStream urlout = urlConnection.getOutputStream();

        DataOutputStream printOut = new DataOutputStream(urlout);
        printOut.writeBytes(content);//writing data to the serverscript

        urlout.flush();
        urlout.close();
        printOut.flush();
        printOut.close();
        jpegOutput.flush();
        jpegOutput.close();

        urlConnection.disconnect();

        //System.err.println("Serverresponse: "+ urlConnection.getResponseMessage());

       //this works in firefox
        //try { getAppletContext().showDocument (new URL("javascript:msg(\""+ urlConnection.getResponseMessage() + "\")")); } catch (MalformedURLException me) { }

    }
    catch( IOException e ){ e.printStackTrace(); }
}

Mod_plsql orqali oracleda:

procedure image_post_handeler ( img varchar2) is 
    b blob;
begin
    b := HEXTORAW( UTL_URL.UNESCAPE(url('img')) );
    insert into image_table (id,  b) values (id_seq.nextval, b  );  
end;

Ishlab chiqarish uchun tayyor bo'lish uchun HTTPS ulanishini va ehtimol pishiriqlarni amalga oshirishi kerak. Agar url parametridan foydalansam, cookie muammosini ayta olaman.

Men olti burchakni brauzerga qaytarib berishni, keyinchalik forma ichidagi yashirin maydonga qo'yishni va keyinchalik formani topshirishni tanlashim mumkin.

Buning yaxshi usullari bo'lishi mumkin. Ushbu dasturni yaratishni o'rganish, sinfni ochish, uni imzolash, hamma joylarda .dll fayllarini joylashtirishni o'rganib chiqishdan iborat. Faqat appletlarning java uylarida ishlashni bilish uchun u yerda taxminan 6, taxminan 32 bit va 64 bitli muammo bor edi.

Yordamingiz uchun tashakkur. Bu menga googlega kerak bo'lgan narsalar haqida yaxshiroq fikr berdi. Sharhlar juda minnatdor.

0
qo'shib qo'ydi
Yechimni tabriklayman. Javobingizni "qabul qilingan" deb belgilashga ishonch hosil qiling, shunda boshqalar sizning muvaffaqiyatingizdan o'rganishi mumkin. Cheers ~
qo'shib qo'ydi muallif Andrew Kozak, manba
Bu bilan biroz ishlaganimdan so'ng, men bir nechta narsalarni topdim: 1. httpurlconnection HTT ulanishlarini boshqarishi mumkin. 2. Qo'shimcha url parametrlarini qo'shish - "get url" qilish bilan bir xil bo'ladi, shuning uchun ulanish simli quyidagi tarzda yozilishi mumkin: "f = 1234 & img =" + imageString 3. Hex magistrini kodlash yoki jb . Heksli qatorda hech qanday maxsus belgi yo'q.
qo'shib qo'ydi muallif Brian McGinity, manba