EOFException in Applet-Servlet communication
Hello everyone, I am writing 2 serializable objects to servlet - after the url connection is setup .The same code is working at number of other places.But at one place it is throwing a EOFException.Could u tell me a way to remove this exception? Regards, Teja. - Do you Yahoo!? Yahoo! Hotjobs: Enter the "Signing Bonus" Sweepstakes
RE: Applet-servlet communication problem with Tomcat 4.0.3
Many thanks. -George -Original Message- From: Douglas, Rory [mailto:[EMAIL PROTECTED]] Sent: Monday, May 13, 2002 3:56 PM To: 'Tomcat Users List' Subject: RE: Applet-servlet communication problem with Tomcat 4.0.3 This looks like something to do with your CATALINA_HOME directory. I had problems installing to Program Files/Apache Tomcat, because of the space in Program Files. You could try moving/re-installing your tomcat to somewhere else without spaces in the pathname - like c:\dev\tomcat4.0.3 or something. -Original Message- From: KAKARONTZAS GEORGE [mailto:[EMAIL PROTECTED]] Sent: Monday, May 13, 2002 7:27 AM To: [EMAIL PROTECTED] Subject: Applet-servlet communication problem with Tomcat 4.0.3 I'm having an Applet oppening a URLConnection with a servlet and sending an object. Here's the Applet side of the communication: //This is the method initiating the connection public void available(SellOrder o) throws Exception { URL servlet = new URL("http", "localhost", 8080, "/servlet/AvailableServlet"); Serializable objs[] = { o }; ObjectInputStream in = ServletWriter.postObjects(servlet, objs); String status = (String) in.readObject(); in.close(); } public class ServletWriter { static public ObjectInputStream postObjects(URL servlet, Serializable objs[]) throws Exception { URLConnection con = servlet.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setDefaultUseCaches(false); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // Write the arguments as post data ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); int numObjects = objs.length; for (int x = 0; x < numObjects; x++) { out.writeObject(objs[x]); } out.flush(); out.close(); return new ObjectInputStream( con.getInputStream() ); } } On the server side of the communication I have the AvailableServlet with the following code: public class AvailableServlet extends HostServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { System.out.println("Available is called."); ObjectInputStream in= new ObjectInputStream(req.getInputStream()); ObjectOutputStream out= new ObjectOutputStream(res.getOutputStream()); try { //read the host order SellOrder o = (SellOrder) in.readObject(); _server.available(o); out.writeObject("OK"); in.close(); out.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } This communication works fine when running with Tomcat 3.2.1 (Windows XP Pro - standalone). But it throws the following exception on the server when running on Tomcat 4.0.3 (same platform standalone or service): Available is called. RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested excep tion is: java.net.MalformedURLException: no protocol: Files/Apache As you can see from the output the doPost() method is called. The exception is thrown when the doPost() method executes the readObject() method on the stream. Any help would be greately appreciated. Thanks -George -- To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]> For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>
RE: Applet-servlet communication problem with Tomcat 4.0.3
This looks like something to do with your CATALINA_HOME directory. I had problems installing to Program Files/Apache Tomcat, because of the space in Program Files. You could try moving/re-installing your tomcat to somewhere else without spaces in the pathname - like c:\dev\tomcat4.0.3 or something. -Original Message- From: KAKARONTZAS GEORGE [mailto:[EMAIL PROTECTED]] Sent: Monday, May 13, 2002 7:27 AM To: [EMAIL PROTECTED] Subject: Applet-servlet communication problem with Tomcat 4.0.3 I'm having an Applet oppening a URLConnection with a servlet and sending an object. Here's the Applet side of the communication: //This is the method initiating the connection public void available(SellOrder o) throws Exception { URL servlet = new URL("http", "localhost", 8080, "/servlet/AvailableServlet"); Serializable objs[] = { o }; ObjectInputStream in = ServletWriter.postObjects(servlet, objs); String status = (String) in.readObject(); in.close(); } public class ServletWriter { static public ObjectInputStream postObjects(URL servlet, Serializable objs[]) throws Exception { URLConnection con = servlet.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setDefaultUseCaches(false); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // Write the arguments as post data ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); int numObjects = objs.length; for (int x = 0; x < numObjects; x++) { out.writeObject(objs[x]); } out.flush(); out.close(); return new ObjectInputStream( con.getInputStream() ); } } On the server side of the communication I have the AvailableServlet with the following code: public class AvailableServlet extends HostServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { System.out.println("Available is called."); ObjectInputStream in= new ObjectInputStream(req.getInputStream()); ObjectOutputStream out= new ObjectOutputStream(res.getOutputStream()); try { //read the host order SellOrder o = (SellOrder) in.readObject(); _server.available(o); out.writeObject("OK"); in.close(); out.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } This communication works fine when running with Tomcat 3.2.1 (Windows XP Pro - standalone). But it throws the following exception on the server when running on Tomcat 4.0.3 (same platform standalone or service): Available is called. RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested excep tion is: java.net.MalformedURLException: no protocol: Files/Apache As you can see from the output the doPost() method is called. The exception is thrown when the doPost() method executes the readObject() method on the stream. Any help would be greately appreciated. Thanks -George
Applet-servlet communication problem with Tomcat 4.0.3
I'm having an Applet oppening a URLConnection with a servlet and sending an object. Here's the Applet side of the communication: //This is the method initiating the connection public void available(SellOrder o) throws Exception { URL servlet = new URL("http", "localhost", 8080, "/servlet/AvailableServlet"); Serializable objs[] = { o }; ObjectInputStream in = ServletWriter.postObjects(servlet, objs); String status = (String) in.readObject(); in.close(); } public class ServletWriter { static public ObjectInputStream postObjects(URL servlet, Serializable objs[]) throws Exception { URLConnection con = servlet.openConnection(); con.setDoInput(true); con.setDoOutput(true); con.setDefaultUseCaches(false); con.setUseCaches(false); con.setRequestProperty("Content-Type", "application/x-www-form-urlencoded"); // Write the arguments as post data ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream()); int numObjects = objs.length; for (int x = 0; x < numObjects; x++) { out.writeObject(objs[x]); } out.flush(); out.close(); return new ObjectInputStream( con.getInputStream() ); } } On the server side of the communication I have the AvailableServlet with the following code: public class AvailableServlet extends HostServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { System.out.println("Available is called."); ObjectInputStream in= new ObjectInputStream(req.getInputStream()); ObjectOutputStream out= new ObjectOutputStream(res.getOutputStream()); try { //read the host order SellOrder o = (SellOrder) in.readObject(); _server.available(o); out.writeObject("OK"); in.close(); out.close(); } catch (Exception ex) { System.out.println(ex.getMessage()); } } } This communication works fine when running with Tomcat 3.2.1 (Windows XP Pro - standalone). But it throws the following exception on the server when running on Tomcat 4.0.3 (same platform standalone or service): Available is called. RemoteException occurred in server thread; nested exception is: java.rmi.UnmarshalException: error unmarshalling arguments; nested excep tion is: java.net.MalformedURLException: no protocol: Files/Apache As you can see from the output the doPost() method is called. The exception is thrown when the doPost() method executes the readObject() method on the stream. Any help would be greately appreciated. Thanks -George
Applet-Servlet communication using Tomcat-Apache cooperation
Hi everybody!! I'm new using Tomcat, instead I'm new developing web applications, so I need help and patient... I'm trying to make a applet-servlet communication thru Apache-Tomcat cooperation. Before I tried it with a Blazix web server, but it was just for tests, because the web server was installed locally in a PC.. and it works perfect and I got the Applet-Servlet communication. Now, I'm trying to do the same with Apache-Tomcat installed in a Solaris Server, and I had been trying that communication for days and I can't yet. I'm trying to make an application that can solve a educational situation, like registration of subjects in my database (Oracle). In this case the Applet only is used like an interface for the user. The user can register a new subject thru the Applet, then the Applet send an object to the Servlet thru a serializable class (Ubc.class) [all this using ObjectInputStream and ObjectOutputStream classes]. The Servlet recieve the Ubc object and interpret it from register all data like a field in a table of the database. Anyway, if the user only want to see all the list of subjects, the Applet sends the url of the Servlet next to a parameter (UserOption = "Display") and the servlet recieve the parameter and make a vector with Ubc objects filling them with the database information and finally the Servlet sends the vector with a writeObject method to the Applet, whose displays the information in the screen. And that's all!!. So, in Tomcat I create the next stucture: tomcat-directory/webapps/proyectoprueba2/WEB-INF/classes/ ---in classes directory store the servlet classes and the ubc.class in Apache I did this: apache-directory/htdocs/proyectoprueba2/ ---in proyectoprueba2 directory store the html file that invokes the applet class, of course, I store the applet class, and the ubc.class. Now I invoke the html file and it works very well, but when I tried to register a subject invoking the servlet thru the applet, I only got an error: Error: 500 Location: /proyectoprueba2/servlet/Servlet3 Internal Servlet Error: java.lang.NullPointerException at java.lang.ClassLoader.resolveClass0(Native Method) at java.lang.ClassLoader.resolveClass0(Compiled Code) at java.lang.ClassLoader.resolveClass(Compiled Code) at org.apache.tomcat.loader.AdaptiveClassLoader.loadClass(Compiled Code) at org.apache.tomcat.loader.AdaptiveServletLoader.loadClass(AdaptiveServletLoader.java:174) at org.apache.tomcat.core.ServletWrapper.loadServlet(Compiled Code) at org.apache.tomcat.core.ServletWrapper.init(Compiled Code) at org.apache.tomcat.core.Handler.service(Handler.java:254) at org.apache.tomcat.core.ServletWrapper.service(ServletWrapper.java:372) at org.apache.tomcat.core.ContextManager.internalService(ContextManager.java:797) at org.apache.tomcat.core.ContextManager.service(ContextManager.java:743) at org.apache.tomcat.service.http.HttpConnectionHandler.processConnection(HttpConnectionHandler.java:213) at org.apache.tomcat.service.TcpWorkerThread.runIt(Compiled Code) at org.apache.tomcat.util.ThreadPool$ControlRunnable.run(Compiled Code) at java.lang.Thread.run(Compiled Code) All the classes I did are part of a proyectoprueba2 package, so I had to create the directory... Where do I have put the Ubc class in Tomcat?? I'm working with Tomcat in a stand alone mode. Do I need to connect it with Apache?? HOW??? I had been testing other servlets that are like "HelloWorld"... they only print a text.. and they works perfect with Tomcat... Can you help me??? I'll be waiting for your help Thank you advanced.. Nancy.
applet-servlet communication problem
Hello, Hello, I got the following error msg. My applet is supposed to send sql string to servlet and servlet is supposed to send back the result. Do I need to signed applet for doing this? If I need to sign and other procedure, where can I refer or get detail information? Thank you in advance. Paul com.ms.security.SecurityExceptionEx[DbApplet.getChartData]: cannot access "test.applet.com":80 at com/ms/security/permissions/NetIOPermission.check at com/ms/security/PolicyEngine.deepCheck at com/ms/security/PolicyEngine.checkPermission at com/ms/net/wininet/WininetURLConnection.checkSecurity at com/ms/net/wininet/WininetURLConnection.connect at com/ms/net/wininet/http/HttpURLConnection.getOutputStream at DbApplet.getChartData at DbApplet.actionPerformed at java/awt/Button.processActionEvent at java/awt/Button.processEvent at java/awt/Component.dispatchEventImpl at java/awt/Component.dispatchEvent at java/awt/EventDispatchThread.run
Re: Applet-servlet communication examples
http://javaranch.com/common.jsp Look for the HTTP, ObjectServlet and Servlets packages. JavaRanch also hosts a servlets discussion board http://www.javaranch.com/cgi-bin/ubb/Ultimate.cgi -- WBB - [EMAIL PROTECTED] Java Cert mock exams http://www.lanw.com/java/javacert/ Author of Java Developer's Guide to Servlets and JSP ISBN 0-7821-2809-2
Re: Applet-servlet communication examples???
http://developer.java.sun.com/developer/technicalArticles/RMI/rmi/ - Original Message - From: "Adam Fowler" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Thursday, March 15, 2001 3:00 AM Subject: RE: Applet-servlet communication examples??? > I second that question 8o) > > Adam. > > > Adam Fowler > Second year Computer Science undergraduate > University of Wales, Aberystwyth > Carroll College, WI, USA(2000-2001) > web: http://gucciboy.dyndns.org/aff9 > e-mail: [EMAIL PROTECTED] > "Every new beginning comes from some other beginning's end" > > > > -Original Message- > From: Paul Yoon [mailto:[EMAIL PROTECTED]] > Sent: Wednesday, March 14, 2001 3:47 PM > To: [EMAIL PROTECTED]; [EMAIL PROTECTED] > Subject: Applet-servlet communication examples??? > > > Hello, > > Could you let me know sites where I can see Applet-servlet communication > examples? > If I can get sources from there, that would be better. > Thank you so much. > > Paul > > >
RE: Applet-servlet communication examples???
I second that question 8o) Adam. Adam Fowler Second year Computer Science undergraduate University of Wales, Aberystwyth Carroll College, WI, USA(2000-2001) web: http://gucciboy.dyndns.org/aff9 e-mail: [EMAIL PROTECTED] "Every new beginning comes from some other beginning's end" -Original Message- From: Paul Yoon [mailto:[EMAIL PROTECTED]] Sent: Wednesday, March 14, 2001 3:47 PM To: [EMAIL PROTECTED]; [EMAIL PROTECTED] Subject: Applet-servlet communication examples??? Hello, Could you let me know sites where I can see Applet-servlet communication examples? If I can get sources from there, that would be better. Thank you so much. Paul
Applet-servlet communication examples???
Hello, Could you let me know sites where I can see Applet-servlet communication examples? If I can get sources from there, that would be better. Thank you so much. Paul
Re: applet-servlet communication
Carlos - Sorry 'bout that. You do need a HttpURLConnection to use setRequestMethod. --- Carlos R Armas <[EMAIL PROTECTED]> wrote: > > Will give that a shot. Although it will require a minor modification. > I remember > that rather than using URLConnection, I should use HttpURLConnection > (not sure, > but I think the latter is derived from URLConnection). > > armas > > (*) Will not know the results til tomorrow... machine is at home!! > > > > Wyn Easton wrote: > > > > Try adding: > > > > uc.setRequestMethod("POST"); > > > > Before you get the output stream. > > > > Also, a word of caution. I have found that if the response from > > the web server takes longer that the keep-alive timeout value set > > for your web sever, your applet will not be notified (no exception > > thrown). I client will hang on the read "forever". I've tried > > looping on the available() method of InputStream but it always > > returns 0 (zero) bytes and never throws an exception, even if the > > web server has closed the connection. > > > > Maybe some one has a suggestion that could help both of us??? > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] > = Wyn Easton [EMAIL PROTECTED] __ Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: applet-servlet communication
Will give that a shot. Although it will require a minor modification. I remember that rather than using URLConnection, I should use HttpURLConnection (not sure, but I think the latter is derived from URLConnection). armas (*) Will not know the results til tomorrow... machine is at home!! Wyn Easton wrote: > > Try adding: > > uc.setRequestMethod("POST"); > > Before you get the output stream. > > Also, a word of caution. I have found that if the response from > the web server takes longer that the keep-alive timeout value set > for your web sever, your applet will not be notified (no exception > thrown). I client will hang on the read "forever". I've tried > looping on the available() method of InputStream but it always > returns 0 (zero) bytes and never throws an exception, even if the > web server has closed the connection. > > Maybe some one has a suggestion that could help both of us??? > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: applet-servlet communication
Try adding: uc.setRequestMethod("POST"); Before you get the output stream. Also, a word of caution. I have found that if the response from the web server takes longer that the keep-alive timeout value set for your web sever, your applet will not be notified (no exception thrown). I client will hang on the read "forever". I've tried looping on the available() method of InputStream but it always returns 0 (zero) bytes and never throws an exception, even if the web server has closed the connection. Maybe some one has a suggestion that could help both of us??? --- Carlos R Armas <[EMAIL PROTECTED]> wrote: > > I am using something like the following (applet): > > URL url = new URL("http://localhost:8080/..."); > URLConnection uc = url.openConnection(); > uc.setDoOutput(true); > uc.setDoInput(true); > uc.setUseCaches(false); > uc.setRequestProperty(...); > DataOutputStream out = new DataOutputStream(uc.getOutputStream()); > out.writeBytes(...); > out.flush(); > out.close(); > > then I use InputStreamReader to read whatever the servlet sent back. > > My assumption was that this is the mechanism to send POST data from > the > applet. Maybe here is my mistake. > > I haven't tried calling doPost from the doGet method. > > > > > Wyn Easton wrote: > > > > Carlos - I'm curious, how are you sending the data from the applet > > to the servlet? Why do you think the applet is setup to use the > "POST" > > method? > > > > You could always call your doPost() method in your servlet from > > the doGet() method. > > > > --- Carlos R Armas <[EMAIL PROTECTED]> wrote: > > > > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] > = Wyn Easton [EMAIL PROTECTED] __ Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: applet-servlet communication
I am using something like the following (applet): URL url = new URL("http://localhost:8080/..."); URLConnection uc = url.openConnection(); uc.setDoOutput(true); uc.setDoInput(true); uc.setUseCaches(false); uc.setRequestProperty(...); DataOutputStream out = new DataOutputStream(uc.getOutputStream()); out.writeBytes(...); out.flush(); out.close(); then I use InputStreamReader to read whatever the servlet sent back. My assumption was that this is the mechanism to send POST data from the applet. Maybe here is my mistake. I haven't tried calling doPost from the doGet method. Wyn Easton wrote: > > Carlos - I'm curious, how are you sending the data from the applet > to the servlet? Why do you think the applet is setup to use the "POST" > method? > > You could always call your doPost() method in your servlet from > the doGet() method. > > --- Carlos R Armas <[EMAIL PROTECTED]> wrote: > > - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: applet-servlet communication
Carlos - I'm curious, how are you sending the data from the applet to the servlet? Why do you think the applet is setup to use the "POST" method? You could always call your doPost() method in your servlet from the doGet() method. --- Carlos R Armas <[EMAIL PROTECTED]> wrote: > > I am trying to have an applet communicate with a servlet. I don't > want > to use so I can't set the method to GET/POST. I do want to > restrict > the servelt to only use POST, not GET. > > The HttpServletResponse/HttpServletRequest classes are being used to > exchange the messages. I have the applet "sending" the data... I > believe > using the POST method. The servlet on the other hand, gets the > initial > communication and session information but the actual data never > arrives and the method that the servlet claims to have used is GET. > The > servlet communicates back to the applet with no problem. > > Now, the question is: Is there some configuration needed so that when > the > applet sends the information (to tomcat?) it can be passed on to the > servlet using the chosen -POST- delivery method? > > The servlet works fine if I test it with a html file that has a form > which > uses POST to send the data. So half the implementation is working. > > Any help will be appreciated. > > armas > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] > = Wyn Easton [EMAIL PROTECTED] __ Get personalized email addresses from Yahoo! Mail - only $35 a year! http://personal.mail.yahoo.com/ - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
Re: applet-servlet communication
GOOD CODE. I am going through it and will get back to you very soon.can I reply to you offlist?? RKJHA, ELECTRONICS ENGINEER At 10:41 30/01/01 +0100, you wrote: >I wrote a pair applet-servlet to do a server-based circuit simulation from an >applet located in some client computer. Here are the sources, FYI (yet in >development). If you want, you can email me directly to discuss the >implementation details. > >Applet source >follows-- >This applet has a simple GUI interface to allow the user to input a electronic >circuit description (text format) in a multi-line text edit control. Then, by >pressing the "Simulate" button, the text edit content is sent to the servlet >via a POST method. The servlet writes down this text to a file and invokes the >simulator (ng-spice), sending the results back to the applet for displaying >them into the user screen. > >//Title: SPICE - Applets i Servlets >//Version: >//Copyright: Copyright (c) 2000 >//Author: Orestes Mas >//Company: GEC-UPC >//Description: Execució de SPICE en mode client-servidor > >package es.upc.gec; > >import java.awt.*; >import java.awt.event.*; >import java.applet.*; >import java.net.*; >import java.io.*; > >public class SpiceApplet extends Applet { > boolean isStandalone = false; > BorderLayout Layout = new BorderLayout(); > Label titol = new Label(); > Panel panellBotons = new Panel(); > Button botoSimular = new Button(); > Button botoVisualitzar = new Button(); > TextArea arxiu = new TextArea(); > private String arxiuCIR = ""; > private String arxiuOUT = ""; > private String direccio = "http:///SPICEServlet"; > private URL urlservlet; //Es crea la URL > private URLConnection conservlet; > private ObjectOutputStream sortida; //Streams de comunicació amb el >Servlet > private ObjectInputStream entrada; > > //Construct the applet > public SpiceApplet() { > } > > //Initialize the applet > public void init() { >try { > jbInit(); >} >catch(Exception e) { > e.printStackTrace(); >} > } > > //Component initialization > private void jbInit() throws Exception { >titol.setFont(new java.awt.Font("SansSerif", 0, 20)); >titol.setText("SPICE - Simulador Remot"); >this.setLayout(Layout); >botoSimular.setLabel("Simular"); >botoSimular.addActionListener(new java.awt.event.ActionListener() { > > public void actionPerformed(ActionEvent e) { >botoSimular_actionPerformed(e); > } >}); >botoVisualitzar.setEnabled(false); >botoVisualitzar.setLabel("Veure .OUT"); >botoVisualitzar.addActionListener(new java.awt.event.ActionListener() { > > public void actionPerformed(ActionEvent e) { >botoVisualitzar_actionPerformed(e); > } >}); >arxiuCIR = "Circuit de prova\n"; >arxiuCIR += "* Canvia el titol per un de mes adient\n"; >arxiuCIR += "* i entra la descripcio del circuit a continuacio\n"; >arxiu.setFont(new java.awt.Font("Monospaced", 0, 14)); >arxiu.setText(arxiuCIR); >this.add(titol, BorderLayout.NORTH); >this.add(panellBotons, BorderLayout.SOUTH); >panellBotons.add(botoSimular, null); >panellBotons.add(botoVisualitzar, null); >this.add(arxiu, BorderLayout.CENTER); > } > > //Get Applet information > public String getAppletInfo() { >return "Applet Information"; > } > > void botoSimular_actionPerformed(ActionEvent e) { >// 1) Desactivar el botó de "Veure .OUT" i netejar continguts >botoVisualitzar.setEnabled(false); >// 2) Copiar el contingut de la TextArea a una var. interna >arxiuCIR = arxiu.getText(); >try { >// 3) Obrir una connexió amb el Servlet >//Missatge: Connectant amb el simulador remot... >titol.setText("Connectant amb el simulador remot..."); >urlservlet = new URL(direccio); >conservlet = urlservlet.openConnection(); // Obrim connexió amb el >Servlet >// Fixem diversos paràmetres de la connexió... >conservlet.setDoInput(true); >conservlet.setDoOutput(true); >conservlet.setUseCaches(false); >conservlet.setDefaultUseCaches(false); > >conservlet.setRequestProperty("Content-Type","application/octet-stream"); > >// 4) Enviar el contingut de la TextArea >//Missatge: Enviant .CIR al simulador... >titol.setText("Connectat: Enviant .CIR al simulador..."); >//Se crea un Stream de sortida (para objetos). >sortida = new ObjectOutputStream(conservlet.getOutputStream()); >sortida.writeObject(arxiuCIR); // Se escribe el objeto. > >// 5) Esperar resposta i col.locar-la en un objecte intermig >//Missatge: Esperant resposta... >titol.setText("Arxiu enviat: Esperant resposta..."); >//Se abre un Stream de entrada, (importante, tanto si se esperan datos >como si no) >entrada = new ObjectInputStream(conservlet.getIn
Re: applet-servlet communication
I wrote a pair applet-servlet to do a server-based circuit simulation from an applet located in some client computer. Here are the sources, FYI (yet in development). If you want, you can email me directly to discuss the implementation details. Applet source follows-- This applet has a simple GUI interface to allow the user to input a electronic circuit description (text format) in a multi-line text edit control. Then, by pressing the "Simulate" button, the text edit content is sent to the servlet via a POST method. The servlet writes down this text to a file and invokes the simulator (ng-spice), sending the results back to the applet for displaying them into the user screen. //Title: SPICE - Applets i Servlets //Version: //Copyright: Copyright (c) 2000 //Author: Orestes Mas //Company: GEC-UPC //Description: Execució de SPICE en mode client-servidor package es.upc.gec; import java.awt.*; import java.awt.event.*; import java.applet.*; import java.net.*; import java.io.*; public class SpiceApplet extends Applet { boolean isStandalone = false; BorderLayout Layout = new BorderLayout(); Label titol = new Label(); Panel panellBotons = new Panel(); Button botoSimular = new Button(); Button botoVisualitzar = new Button(); TextArea arxiu = new TextArea(); private String arxiuCIR = ""; private String arxiuOUT = ""; private String direccio = "http:///SPICEServlet"; private URL urlservlet; //Es crea la URL private URLConnection conservlet; private ObjectOutputStream sortida; //Streams de comunicació amb el Servlet private ObjectInputStream entrada; //Construct the applet public SpiceApplet() { } //Initialize the applet public void init() { try { jbInit(); } catch(Exception e) { e.printStackTrace(); } } //Component initialization private void jbInit() throws Exception { titol.setFont(new java.awt.Font("SansSerif", 0, 20)); titol.setText("SPICE - Simulador Remot"); this.setLayout(Layout); botoSimular.setLabel("Simular"); botoSimular.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { botoSimular_actionPerformed(e); } }); botoVisualitzar.setEnabled(false); botoVisualitzar.setLabel("Veure .OUT"); botoVisualitzar.addActionListener(new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { botoVisualitzar_actionPerformed(e); } }); arxiuCIR = "Circuit de prova\n"; arxiuCIR += "* Canvia el titol per un de mes adient\n"; arxiuCIR += "* i entra la descripcio del circuit a continuacio\n"; arxiu.setFont(new java.awt.Font("Monospaced", 0, 14)); arxiu.setText(arxiuCIR); this.add(titol, BorderLayout.NORTH); this.add(panellBotons, BorderLayout.SOUTH); panellBotons.add(botoSimular, null); panellBotons.add(botoVisualitzar, null); this.add(arxiu, BorderLayout.CENTER); } //Get Applet information public String getAppletInfo() { return "Applet Information"; } void botoSimular_actionPerformed(ActionEvent e) { // 1) Desactivar el botó de "Veure .OUT" i netejar continguts botoVisualitzar.setEnabled(false); // 2) Copiar el contingut de la TextArea a una var. interna arxiuCIR = arxiu.getText(); try { // 3) Obrir una connexió amb el Servlet //Missatge: Connectant amb el simulador remot... titol.setText("Connectant amb el simulador remot..."); urlservlet = new URL(direccio); conservlet = urlservlet.openConnection(); // Obrim connexió amb el Servlet // Fixem diversos paràmetres de la connexió... conservlet.setDoInput(true); conservlet.setDoOutput(true); conservlet.setUseCaches(false); conservlet.setDefaultUseCaches(false); conservlet.setRequestProperty("Content-Type","application/octet-stream"); // 4) Enviar el contingut de la TextArea //Missatge: Enviant .CIR al simulador... titol.setText("Connectat: Enviant .CIR al simulador..."); //Se crea un Stream de sortida (para objetos). sortida = new ObjectOutputStream(conservlet.getOutputStream()); sortida.writeObject(arxiuCIR); // Se escribe el objeto. // 5) Esperar resposta i col.locar-la en un objecte intermig //Missatge: Esperant resposta... titol.setText("Arxiu enviat: Esperant resposta..."); //Se abre un Stream de entrada, (importante, tanto si se esperan datos como si no) entrada = new ObjectInputStream(conservlet.getInputStream()); //Se lee el objeto, es necesario un "moldeo" del objeto leido. arxiuOUT = (String)entrada.readObject(); entrada.close(); //Se cierran las conexiones. sortida.close(); } catch (IOException ex) {titol.setText("Excepció!!!");} catch (ClassNo
Re: applet-servlet communication
I don't have problem using POST to submit data under IE4.0 and IE5.5. Your problem may have to do with a reported IE5.5 bug which cause data to be truncated when it encounters a NULL byte in the data. As to the original question, my suggestion is to make sure to set the Content-Length header, as it is required by POST. - Curtz Allen Akers wrote: > I ran into the same issue and found that due to some reason (purported > to be security-related, although I can't see how) applets running under > IE will NOT use the post protocol to submit requests no matter WHAT you > do. If you are insistent on using post then you'll be limited to > running under Netscape from everything I've seen and done. I was lucky > that the particular applet I needed to post from (it was posting edited > JSPs back to the web server, which is why I needed to use post) was only > for our in-house developers, so I could tell them that they HAVE to use > Netscape. Unless there is a really good reason (like content length, in > my case) that you have to use post then I'd say to use get so that > you'll have cross-browser compatibility. > >Allen Akers >Programmer Analyst >Strategic Web and Voice Development > >[EMAIL PROTECTED] > > >>> [EMAIL PROTECTED] 01/29/01 03:07PM >>> > > I would guess that you are not actually POSTing information. > Searching on jGuru just now I found a snippet of code (totally > unrelated to > your problem) that does an example of POST. Its at > http://www.jguru.com/jguru/faq/orphan_view.jsp?EID=141034. Maybe this > example can help you to figure out what's not going quite right. If > you > still can't figure it out, you will need to post code for anyone to be > able > to help you. > > Randy > > -Original Message- > From: Carlos R Armas [mailto:[EMAIL PROTECTED]] > Sent: Monday, January 29, 2001 4:28 PM > To: [EMAIL PROTECTED] > Subject: applet-servlet communication > > I am trying to have an applet communicate with a servlet. I don't want > to use so I can't set the method to GET/POST. I do want to > restrict > the servelt to only use POST, not GET. > > The HttpServletResponse/HttpServletRequest classes are being used to > exchange the messages. I have the applet "sending" the data... I > believe > using the POST method. The servlet on the other hand, gets the initial > communication and session information but the actual data never > arrives and the method that the servlet claims to have used is GET. > The > servlet communicates back to the applet with no problem. > > Now, the question is: Is there some configuration needed so that when > the > applet sends the information (to tomcat?) it can be passed on to the > servlet using the chosen -POST- delivery method? > > The servlet works fine if I test it with a html file that has a form > which > uses POST to send the data. So half the implementation is working. > > Any help will be appreciated. > > armas > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] > > - > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
RE: applet-servlet communication
I ran into the same issue and found that due to some reason (purported to be security-related, although I can't see how) applets running under IE will NOT use the post protocol to submit requests no matter WHAT you do. If you are insistent on using post then you'll be limited to running under Netscape from everything I've seen and done. I was lucky that the particular applet I needed to post from (it was posting edited JSPs back to the web server, which is why I needed to use post) was only for our in-house developers, so I could tell them that they HAVE to use Netscape. Unless there is a really good reason (like content length, in my case) that you have to use post then I'd say to use get so that you'll have cross-browser compatibility. Allen Akers Programmer Analyst Strategic Web and Voice Development [EMAIL PROTECTED] >>> [EMAIL PROTECTED] 01/29/01 03:07PM >>> I would guess that you are not actually POSTing information. Searching on jGuru just now I found a snippet of code (totally unrelated to your problem) that does an example of POST. Its at http://www.jguru.com/jguru/faq/orphan_view.jsp?EID=141034. Maybe this example can help you to figure out what's not going quite right. If you still can't figure it out, you will need to post code for anyone to be able to help you. Randy -Original Message- From: Carlos R Armas [mailto:[EMAIL PROTECTED]] Sent: Monday, January 29, 2001 4:28 PM To: [EMAIL PROTECTED] Subject: applet-servlet communication I am trying to have an applet communicate with a servlet. I don't want to use so I can't set the method to GET/POST. I do want to restrict the servelt to only use POST, not GET. The HttpServletResponse/HttpServletRequest classes are being used to exchange the messages. I have the applet "sending" the data... I believe using the POST method. The servlet on the other hand, gets the initial communication and session information but the actual data never arrives and the method that the servlet claims to have used is GET. The servlet communicates back to the applet with no problem. Now, the question is: Is there some configuration needed so that when the applet sends the information (to tomcat?) it can be passed on to the servlet using the chosen -POST- delivery method? The servlet works fine if I test it with a html file that has a form which uses POST to send the data. So half the implementation is working. Any help will be appreciated. armas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
RE: applet-servlet communication
I would guess that you are not actually POSTing information. Searching on jGuru just now I found a snippet of code (totally unrelated to your problem) that does an example of POST. Its at http://www.jguru.com/jguru/faq/orphan_view.jsp?EID=141034. Maybe this example can help you to figure out what's not going quite right. If you still can't figure it out, you will need to post code for anyone to be able to help you. Randy -Original Message- From: Carlos R Armas [mailto:[EMAIL PROTECTED]] Sent: Monday, January 29, 2001 4:28 PM To: [EMAIL PROTECTED] Subject: applet-servlet communication I am trying to have an applet communicate with a servlet. I don't want to use so I can't set the method to GET/POST. I do want to restrict the servelt to only use POST, not GET. The HttpServletResponse/HttpServletRequest classes are being used to exchange the messages. I have the applet "sending" the data... I believe using the POST method. The servlet on the other hand, gets the initial communication and session information but the actual data never arrives and the method that the servlet claims to have used is GET. The servlet communicates back to the applet with no problem. Now, the question is: Is there some configuration needed so that when the applet sends the information (to tomcat?) it can be passed on to the servlet using the chosen -POST- delivery method? The servlet works fine if I test it with a html file that has a form which uses POST to send the data. So half the implementation is working. Any help will be appreciated. armas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED] - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]
applet-servlet communication
I am trying to have an applet communicate with a servlet. I don't want to use so I can't set the method to GET/POST. I do want to restrict the servelt to only use POST, not GET. The HttpServletResponse/HttpServletRequest classes are being used to exchange the messages. I have the applet "sending" the data... I believe using the POST method. The servlet on the other hand, gets the initial communication and session information but the actual data never arrives and the method that the servlet claims to have used is GET. The servlet communicates back to the applet with no problem. Now, the question is: Is there some configuration needed so that when the applet sends the information (to tomcat?) it can be passed on to the servlet using the chosen -POST- delivery method? The servlet works fine if I test it with a html file that has a form which uses POST to send the data. So half the implementation is working. Any help will be appreciated. armas - To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, email: [EMAIL PROTECTED]