-
Salve a tutti,
illustro il mio problema sperando possiate aiutarmi.
Ho un file PHP che genera un JSON e uno JSP che lo dovrebbe leggere.
Questo mi serve perchè devo sincronizzare 2 db su due server differenti.
Come faccio a leggere ciò che mi restituisce il file.php nel file.jsp??
x -
Ciao spizzico7,
ti potrebbero aiutare queste librerie (ma ce ne sono molte altre analoghe):
json.org/java/
json-lib.sourceforge.net -
mister.jinx
Ciao spizzico7,
ti potrebbero aiutare queste librerie (ma ce ne sono molte altre analoghe):
json.org/java/
json-lib.sourceforge.netGrazie dell'aiuto ma ho trovato un modo migliore...ovvero:
avendo già un json generato molto semplicemente in php mi basta leggere il codice in jsp con il seguente codice.public class JavaGetUrl { public static void main (String[] args) { //-----------------------------------------------------// // Step 1: Start creating a few objects we'll need. //-----------------------------------------------------// URL u; InputStream is = null; DataInputStream dis; String s; try { //------------------------------------------------------------// // Step 2: Create the URL. // //------------------------------------------------------------// // Note: Put your real URL here, or better yet, read it as a // // command-line arg, or read it from a file. // //------------------------------------------------------------// u = new URL("h t t p : / / 2 0 0 . 2 1 0 . 2 2 0 . 1 : 80 8 0 / i n d e x . ht m l "); //----------------------------------------------// // Step 3: Open an input stream from the url. // //----------------------------------------------// is = u.openStream(); // throws an IOException //-------------------------------------------------------------// // Step 4: // //-------------------------------------------------------------// // Convert the InputStream to a buffered DataInputStream. // // Buffering the stream makes the reading faster; the // // readLine() method of the DataInputStream makes the reading // // easier. // //-------------------------------------------------------------// dis = new DataInputStream(new BufferedInputStream(is)); //------------------------------------------------------------// // Step 5: // //------------------------------------------------------------// // Now just read each record of the input stream, and print // // it out. Note that it's assumed that this problem is run // // from a command-line, not from an application or applet. // //------------------------------------------------------------// while ((s = dis.readLine()) != null) { System.out.println(s); } } catch (MalformedURLException mue) { System.out.println("Ouch - a MalformedURLException happened."); mue.printStackTrace(); System.exit(1); } catch (IOException ioe) { System.out.println("Oops- an IOException happened."); ioe.printStackTrace(); System.exit(1); } finally { //---------------------------------// // Step 6: Close the InputStream // //---------------------------------// try { is.close(); } catch (IOException ioe) { // just going to ignore this one } } // end of 'finally' clause } // end of main } // end of class definition -
Ciao spizzico7,
è vero: certamente puoi fare come tu indichi.
Le librerie che ti avevo suggerito ti risparmiano il parsing degli oggetti successivo.
Ciao! Sembra che tu sia interessato a questa conversazione, ma non hai ancora un account.
Stanco di dover scorrere gli stessi post a ogni visita? Quando registri un account, tornerai sempre esattamente dove eri rimasto e potrai scegliere di essere avvisato delle nuove risposte (tramite email o notifica push). Potrai anche salvare segnalibri e votare i post per mostrare il tuo apprezzamento agli altri membri della comunità.
Con il tuo contributo, questo post potrebbe essere ancora migliore 💗
Registrati Accedi