Servlet applet object io streams

hi! i have an applet and servlet which communicate through objectoutputstreams.
here's part of my applet code found in the init method:
hostServlet = new URL( "http://localhost:8080/scheduler/servlet/EditSchedule" );
hostConnection = (HttpURLConnection)hostServlet.openConnection();
hostConnection.setRequestMethod( "POST" );
System.out.println( "connected" );
//set headers
hostConnection.setDoInput( true );
hostConnection.setDoOutput( true );
hostConnection.setUseCaches( false );
hostConnection.setDefaultUseCaches( false );
hostConnection.setRequestProperty( "Content-Type", "application/x-java-serialized-object" );
//stream to servlet just to specify that we're using post not get
oos = new ObjectOutputStream( hostConnection.getOutputStream() );                                      
oos.writeObject( "inside" );                                                
oos.flush();
oos.writeObject( "inside2" );
oos.flush();
//get objects being passed by servlet
ooi = new ObjectInputStream( hostConnection.getInputStream() );
here's part of my servlet code in the doPost() method:
ObjectOutputStream oos = new ObjectOutputStream( response.getOutputStream() );
ObjectInputStream ois = new ObjectInputStream( request.getInputStream() );
response.setContentType( "application/x-java-serialized-object" );
oos.writeObject( object );               
oos.flush(); 
oos.close();     
//read objects
FileOutputStream fw = new FileOutputStream( "c:\\objectsRead.txt" );
ObjectOutputStream objectFw = new ObjectOutputStream( fw );
objectFw.writeObject( "from servlet" );
objectFw.flush();                                 
String inside = (String)ois.readObject();
objectFw.writeObject( inside );
objectFw.flush();
String outside = (String) ois.readObject();
objectFw.writeObject( outside );
objectFw.flush();
objectFw.close();both the inside and inside2 objects get written to my textfile. Although, in my applet, if i outputted inside2 after creating the objectinputstream, only inside1 gets written. This is my problem. I have to write back to the servlet way passed the ooi instantiation of the applet. Specifically, in an event handler outside the init method.
any help would be greatly appreciated! =)

another weird thing that i found out.
when i use the syntax:
oos.writeObject( "something" );
-->it gets passed to the servlet while
String str = "something";
oos.writeObject( str );
-->doesn't get passed.
hmm....
i tried setting the content type to application/octet-stream but still nothing.

Similar Messages

  • Servlet Applet object communication problem???!!!

    Hy folks,
    I need to validate the ability of complex Servlet Applet communication an run into my first pb right at the beginning of my tests. I need to have around 200 Applet clients connect to my servlet and communicate by ObjectInput and ObjectOutput streams. So I wrote a simple Servlet accepting HTTP POST connections that return a Java object. When the java Applet get instantiated, the Object Stream communication workes fine. But when the Applet tries to communicate with the servlet after that, I can not create another communication session with that Servlet, instead I get a 405 Method not allowed exception.
    Summarized:
    - Applet init() instantiate URLConnection with Servlet and request Java object (opening ObjectInput and Output Stream, after receaving object, cloasing streams).
    - When I press a "get More" button on my Applet, I am not able to instantiate a new URLConnection with my servler because of that 405 exception, WHY???
    Here my Servlet code:
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException{
             ObjectInputStream inputFromApplet = null;
             ArrayList transmitContent = null;       
             PrintWriter out = null;
             BufferedReader inTest = null;
             try{               
                   inputFromApplet = new ObjectInputStream(request.getInputStream());           
                     transmitContent = (ArrayList) inputFromApplet.readObject();       
                     inputFromApplet.close();
                     ArrayList toReturn = new ArrayList();                 
                     toReturn.add("One");
                     toReturn.add("Two");
                     toReturn.add("Three");
                     sendAnsweredList(response, toReturn);                 
             catch(Exception e){}        
         public void sendAnsweredList(HttpServletResponse response, ArrayList returnObject){
             ObjectOutputStream outputToApplet;    
              try{
                  outputToApplet = new ObjectOutputStream(response.getOutputStream());          
                  outputToApplet.writeObject(returnObject);
                  outputToApplet.flush();           
                  outputToApplet.close();              
              catch (IOException e){
                     e.printStackTrace();
    }Here my Applet code:
    public void init() {         
             moreStuff.addActionListener(new ActionListener(){
                  public void actionPerformed(ActionEvent e){
                       requestMore();
             try{
                  studentDBservlet = new URL("http://localhost/DBHandlerServlet");              
                  servletConnection = studentDBservlet.openConnection();      
                   servletConnection.setUseCaches (false);
                   servletConnection.setDefaultUseCaches(false);
                   servletConnection.setDoOutput(true);
                   servletConnection.setDoInput(true);
                   ObjectOutputStream outputToApplet;
                 outputToApplet = new ObjectOutputStream(servletConnection.getOutputStream());          
                 outputToApplet.writeObject(new ArrayList());
                 outputToApplet.flush();           
                 outputToApplet.close(); 
                   ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
                   ArrayList studentVector = (ArrayList) inputFromServlet.readObject();
                   area.setText("Success!\n");
                   for (int i = 0; i<studentVector.size(); i++) {
                        area.append(studentVector.get(i).toString()+"\n");
                  inputFromServlet.close();
                  outputToApplet.close();             
              catch(Exception e){
                   area = new JTextArea();
                   area.setText("An error occured!!!\n");
                   area.append(e.getMessage());
            getContentPane().add(new JScrollPane(area), BorderLayout.CENTER);
            getContentPane().add(moreStuff, BorderLayout.SOUTH);
        private void requestMore(){
             try{              
                  studentDBservlet = new URL("http://localhost/DBHandlerServlet");                             
                  servletConnection = studentDBservlet.openConnection(); 
                   ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
                   ArrayList studentVector = (ArrayList) inputFromServlet.readObject();
                   area.setText("Success2!\n");
                   for (int i = 0; i<studentVector.size(); i++) {
                        area.append(studentVector.get(i).toString()+"\n");
              catch(Exception e){               
                   area.setText("An error occured2!!!\n");
                   area.append(e.getMessage());
        }Can someone help me solv this issue please, this is my first Applet Servlet work so far so I have no idea on how to solve this issue.

    Sorry folks, just found my error. Forgot about the ObjectInputStream waiting on the Servlet side, so of course had a dead look...
    Sorry!

  • Applet - Servlet - Database - Servlet- Applet

    Hi All,
    I am using Oracle8i and IE 5.0. I am trying to retrieve the data from a db table and display it.
    Sequence is as following:
    1. Query passed to the applet.
    2. Servlet excutes this query using JDBC and returns the resultset to applet.
    3. Applet displaysthe results.
    Is there anybody who has a code sample to do this, my id is [email protected] ? I am totally new to java and servlets. I would really appreciate any help.
    Thanks a lot.
    Manuriti
    [email protected]

    I've never dealt with the code to handle the applet portion of what you're trying to do, but I can help you with the servlet stuff.
    Your servlet should contain code to accomplish the following steps:
    1. Load an Oracle JDBC driver into memory.
    2. Open a JDBC connection to the Oracle database.
    3. Create a JDBC Statement object which contains the appropriate Oracle SQL code.
    4. Execute the Statement object, which will return a ResultSet.
    5. Read the ResultSet data.
    6. Pool or close the Statement and Connection objects.
    All of these steps are simple. Here's what they might look like in practice:
    // load the Oracle driver
    Class.forName("oracle.jdbc.driver.OracleDriver");
    // open the connection
    String cs = "jdbc:oracle:[email protected]:1521:DBNAME"; // connection string
    String userName = "scott";
    String password = "tiger";
    Connection con = DriverManager.getConnection(cs, userName, password);
    // create a Statement object
    Statement stmt = con.createStatement();
    // create a ResultSet object
    ResultSet rs = stmt.executeQuery("select * from DUAL"); // your SQL here
    // INSERT CODE HERE TO READ DATA FROM THE RESULTSET
    // close the Statement object
    stmt.close();
    // close the Connection object
    con.close();
    So that's how you get data from your Oracle database. Now, how do you pass it to your applet? Well, this is hardly trivial. Typically, servlets return an HTML-formatted text stream. It is possible to have an applet communicate with a servlet, but that raises security issues that I don't fully understand. I believe you would have to have your user's browsers set to the lowest possible security settings, otherwise the browser won't let the applet open a socket to a foreign IP, but again, I'm shaky on that one.
    Anywho, let me know if this was of help and if you have more questions on the servlet/applet stuff. I can probably help you with more specific questions,.

  • How can i convert an object to stream of chars or bytes?

    how can i convert an object to stream of chars or bytes?

    One way is the serialization mechanism. There are examples and explanations of it in the Java tutorial: http://java.sun.com/docs/books/tutorial/essential/io/serialization.html

  • At what percent e-tester can identify java applet objects. Plz see message.

    Hi,
    Me new to this group.
    I am here to find out whether e-tester can test java applet or not.
    I am testing a web application which is completely Java applet base.
    Envirnment used jdk1.1.8 and Jre1.4.
    I have been trying to identify applet object used in our application.
    problem i faced:
    when i set java option in option seting for both Microsoft applet and sun system applet. where my system having jdk1.1.8 and jre1.4.
    Recording on above envirnment I am able to record my application but i can not play that. On this case I marked Abbot script generated.
    when uninstall jdk and jre.
    I am able to record and play my application still some step. But I am not able to customize it.
    this application also uses StarTree a hyporbolic tree API from
    "Business Object" now bought by SAP (this api used inside applet
    frame).
    Is any one work on e-tester to automate in and out of an application which is built in java applet.
    Can some one help me to figure out where I am doing wrong.
    Before this I worked on e-tester year back to automate one of our application and still we are doing our regression on that.
    Expecting some help

    When you say customize, are you referring to parameters? They is handled differently with applets. I believe there is documentation on this.

  • Servlet with 2 Response Streams

    I want to create a Servlet with 2 response streams. I need to use 1 response Stream to send Continuous Updates received on the server
    and the other response Stream would be used to send Heartbeats to the Client. I tried to create the Servlet but the response I create to send the continuous data just stops sending data to the Client after many attempts. In this attached Servlet, The response for continuous data stopped after 150 refreshes.
    Please let me know how to fix the issue. I tried reset() too but does not seem to work. Will very much appreciate any help.
    package com.XX;
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class TestServlet extends HttpServlet{
         private static final long serialVersionUID = 1L;
         public static int count = 0;
         private TestSave testSave = null;
         private HttpServletResponse resp = null;
         public void init(){
              testSave = new TestSave();
         protected void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
              count ++;
              if(testSave == null){
                   System.out.println(" test save = null");
                   return;
              if(testSave.getRes()==null){
              System.out.println(" test save resp is null");          
              testSave.setRes(res);
              res.getWriter().println(" Initial Daily count Response ");
              }else{
              res.getWriter().println(" Daily response " + count);
              //res.getWriter().close();
         System.out.println(" test save resp is not null");
              resp = testSave.getRes();
              String data = "Count is "+count;
              System.out.println(" Writing response " + resp);
              System.out.println(" Writing Data " + data);
              System.out.println(" Response committed 1 - " + count + " : " + resp.isCommitted());
              resp.getWriter().println(data);
              System.out.println(" Response committed 2 - " + count + " : " + resp.isCommitted());
              System.out.println(" Daily Response committed ??? " + res.isCommitted());
         protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
              doGet(req,res);          
    }

    The TestSave code.
    import javax.servlet.http.HttpServletResponse;
    public class TestSave {
         HttpServletResponse res;
         public HttpServletResponse getRes() {
              return res;
         public void setRes(HttpServletResponse res) {
              this.res = res;
    }

  • JavaScript's Applet Object

    I am trying to use JavaScript's Applet object to access my applet in the left frame, from a java script embedded in a JSP file in the right frame.
    I can assign the object to a variable as in:
    var ap = parent.frames["leftframe"].document.applets[0];
    But when I try to call a public method on the applet as in:
    ap.TestApplet();
    I get an error in the page saying:
    Error: Object doesn't support this property or method.
    My applet was embedded in the left frame with <jsp:plugin> tag. So I am not directly using HTML's Applet tag. So I am not able to pass MAYSCRIPT flag to the HTML's applet tag. Question is, do I need MAYSCRIPT flag for what I am trying to do? If so, is there any way to pass MAYSCRIPT flag?
    Thanks for any help.
    - Krishna.

    Does anyone have any thoughts on this?
    Thanks,
    Krishna.

  • Calling a servlet giving an XML stream

    Hi,
    Can you tell me the different ways to call a java servlet giving a <XML> stream ?
    Thanks

    Can you tell me if the following code is in the right way ?
    XMLTest( HttpServletRequest requete ){
    SAXParser parser = new SAXParser( );
    parser.setContentHandler (this);
    try {
    parser.parse( new InputSource( requete.getReader() ) );
    catch (SAXException e) {
    System.err.println (e);
    catch (IOException e) {
    System.err.println (e);
    And can you tell me how to test ? I mean, how to send a http post or get th the servlet that will include the parser ?

  • Servlet/Applet communication, data limit?

    I have an applet that uses a servlet as a proxy to load/retrieve images from an Oracle database. I have a problem when trying to retrieve images larger than 9-10kb from the database. When using JDBC from a Java Application I don't have any probelms but through the Applet-Servlet configuration I do.
    I use the following code in the Applet:
    URL url =new URL("http","myserver",myport,"/servlet/MyServlet");
    HttpURLConnection imageServletConn = (HttpURLConnection)url.openConnection();
    imageServletConn.setDoInput(true);
              imageServletConn.setDoOutput(true);
              imageServletConn.setUseCaches(false);
    imageServletConn.setDefaultUseCaches (false);
    imageServletConn.setRequestMethod("GET");
    byte buf[] = new byte[imageServletConn.getContentLength()];
    BufferedInputStream instr = new BufferedInputStream(imageServletConn.getInputStream());
    instr.read(buf);
    Image image = Toolkit.getDefaultToolkit().createImage(buf);
    // then code to display the image
    And the following for the Servlet:
    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    response.setContentType("image/gif");
    byte[] buff = loadImage(); // this method returns a byte array representing the image.
    response.setContentLength(contentLength);//contentLength is the size of the image
    OutputStream os = response.getOutputStream();
    os.write(buff);
    os.close();
    thanks in advance!

    thanks for your replay,
    I tried your suggestion but whatever I do it seems that tha applet only brings the first 5-10k of the image from the servlet. This is the value I get from instr.read() or any other type of read method. The value of bytes is not always the same.
    Now I also have something new. For images greater than 100k or so I get this error:
    java.io.IOException: Broken pipe
         at java.net.SocketOutputStream.socketWrite(Native Method)
         at java.net.SocketOutputStream.socketWrite(Compiled Code)
         at java.net.SocketOutputStream.write(Compiled Code)
         at java.io.BufferedOutputStream.write(Compiled Code)
         at org.apache.jserv.JServConnection$JServOutputStream.write(Compiled Code)
         at java.io.BufferedOutputStream.write(Compiled Code)
         at java.io.FilterOutputStream.write(Compiled Code)
         at interorient.DBProxyServlet.doGet(Compiled Code)
         at javax.servlet.http.HttpServlet.service(Compiled Code)
         at javax.servlet.http.HttpServlet.service(Compiled Code)
         at org.apache.jserv.JServConnection.processRequest(Compiled Code)
         at org.apache.jserv.JServConnection.run(Compiled Code)
         at java.lang.Thread.run(Compiled Code)
    I am using the Oracle Internet application server (ias 9i) which actualy uses the apache web listener.
    It seems that this servlet-applet communication is really unstable. If you have anything that may help me it will be greatly appriciated. You can even e-mail me at [email protected]
    thanks!

  • Retrieve applet object

    I'm fairly new to Java and I've been concentrating my efforts in applet programming. One thing I've noticed is that I seem to require the Applet object a lot in my code as I'm doing a lot of file reading (applet.getCodeBase, etc). I have a few instances in my code where I pass the applet object to different packages to perform basic operations and I'm starting to feel as if I'm doing this wrong.
    Is there a way to obtain the applet object using a global static function?

    Hi Mr Lob, will you think about the fact seriously that still no one seems to have understood your problemI know, the talent here is shocking.
    As often illustrations could help...I agree when you are demonstrating algorithms, discussing implementation, compilation errors etc. Mind, I would have knocked something up for you if you'd have responded with some decency and not made out there was a problem with my post. Telling me to post a demo is impolite, you could have asked to see something and I would have gladly responded. You don't know me & I don't you know, so you shouldn't assume you have superiority over me.
    I just wanted a brief code that could illustrate your problem/issue.You'd have a class declaration (unrelated to 'Applet') with an empty function member, in it would be a comment saying:
    // I would like to get applet object the libraries invoked at this point in the code...Close your eyes and imagine it...
    So it is plain obvious that the looser in these word battle is you, not petes1234 et al.LOL. Firstly, I never said petes1234 was a 'loser', he's just an idiot for posting unrelated & directly offensive comments. It's water off a ducks back, mind. Secondly, there's no way I'm a loser posting what I have. However, I will settle for 'loser in the quest to find an accomplished Java programmer within this public forum.'
    I thought I was a part of the 'do-not-help' list? Why are you still posting? Let it lie...
    Just so you know, I found an answer to my question elsewhere asking exactly the same thing. Now, .... "Think about that!"

  • Inter-applet object shareing concepts in java card

    hi there.
    what is a way of implimenting inter-applet object shareing in java card?
    is there any shared area of JCRE for sharing some values among some applets in same java card?
    thanks.

    hi, as i know, there are three approaches:
    1: shareable interface;
    2: entry point;
    3: global array;
    and if the applet has JCRE privilege, then it is overwhelming.
    for details , please refer to the JCRE Specification.

  • Get Applet object

    Hi everybody,
    I have several frames in an HTML page (nothing in static, all is generated).
    I have 1 applets in the frame 1 and an applet in the frame 2.
    I would like to get the applet object (java.Applet.applet) of the applet 1 in the applet 2 ...
    How could I do ?
    For the moment, I get :
    JSObject jsXelonContainer = (JSObject) ((JSObject) ((JSObject) window.getMember("top")).getMember("frames")).getMember("myFrame1");
    JSObject myDoc = (JSObject)jsXelonContainer.getMember("document");
    JSObject applets = (JSObject)myDoc.getMember("applets");
    Nothing is null at this point. But I don't know how to get the Applet I want from the "applets"
    May be is there another simplier way ...
    Any idea ?
    Thanks in advance
    Rafax.

    Ok.
    In my case, it is an applet.
    - The code declaration :
    <OBJECT classid="clsid:8AD7C840-044E-11D1-B1E9-00805F499D93" width="200" height="200" align="left"
         codebase="http://java.sun.com/products/plugin/1.2.2/jinstall-122-win32.cab#Version=1,2,2,0" name="bootstrap" >
         <PARAM NAME="code" VALUE="com.elogiq.xelon.client.web.bootStrap">
         <PARAM NAME="archive" VALUE="../jar/myArchive.jar">
         <PARAM NAME="codebase" value="./class">
         <PARAM NAME="type" VALUE="application/x-java-applet;version=1.3">
         <PARAM NAME="name" value="myApplet">
         <PARAM NAME="scriptable" value="true">
         <PARAM NAME="MAYSCRIPT" value="true">
    </OBJECT>
    the classId your are saying ... is it the classid ? (I don't think, but ...)
    Thanks,
    Rafax

  • Applet object

    can i somehow get the refernce of the applet object which the browser creates.
    i am writing a class which has to b deployed in a web server.
    can i get the ref of the applet object which the browser makes on a client request
    thanx in advance.
    Pradnya

    You mean you want to get a reference to an Applet instance on the server?
    I would imagine that in the majority of environments this is not possible.
    Could you provide more information about what you're trying to do?

  • Applet/object param name="legacy_lifecycle" value="true"/ documentation?

    I've recently stumbled across this applet/object parameter as a solution to a problem. However I can't find the official documentation of it anywhere, and believe me I've looked. I did find a reference to it in some Oracle product documentation but nowhere in the Java Plugin or Deployment documents. Has anybody spotted it anywhere? Urban myth? Legend? It certainly seems to work.
    Edited by: EJP on 6/03/2012 20:36: corrected typo in title

    Searching an old jdk source download shows it is not used by Java per se.
    $ pwd
    /home/download/java/src/jdk-6u23-fcs-src-b05-jrl-12_nov_2010
    $ find . -type f -exec grep -H legacy_lifecycle "{}" \;
    deploy/src/plugin/share/classes/sun/plugin/AppletViewer.java:        String lifecycle = getParameter("legacy_lifecycle");
    deploy/src/plugin/share/classes/sun/plugin2/applet/Applet2Manager.java:        String lifecycle = getParameter("legacy_lifecycle");
    deploy/src/plugin/share/classes/sun/plugin2/applet/Applet2ManagerCache.java:if (appletParameters.get("legacy_lifecycle") == null)
    deploy/src/plugin/share/classes/sun/plugin2/test/LegacyTest2AppletFrame.html:Legacy Lifecycle Automated Test #2 -- two legacy_lifecycle applets on the same page
    deploy/src/plugin/share/classes/sun/plugin2/test/LegacyTest2AppletFrame.html:<param name="legacy_lifecycle" value="true"></param>
    deploy/src/plugin/share/classes/sun/plugin2/test/LegacyTest2AppletFrame.html:<param name="legacy_lifecycle" value="true"></param>
    deploy/src/plugin/share/classes/sun/plugin2/test/LegacyTestAppletFrame1.html:Legacy Lifecycle Automated Test #1 -- two legacy_lifecycle applets in different frames
    deploy/src/plugin/share/classes/sun/plugin2/test/LegacyTestAppletFrame1.html:<param name="legacy_lifecycle" value="true"></param>
    deploy/src/plugin/share/classes/sun/plugin2/test/LegacyTestAppletFrame2.html:<param name="legacy_lifecycle" value="true"></param>
    deploy/src/plugin/share/classes/sun/plugin2/test/liveconnect/LegacyLifecycleLiveConnect.html:Tests LiveConnect against a legacy_lifecycle applet. Reload and switch
    deploy/src/plugin/share/classes/sun/plugin2/test/liveconnect/LegacyLifecycleLiveConnect.html:    <param name="legacy_lifecycle" value="true">
    $

  • Cannot Acccess Applet Object from Java Script

    Hi,
    I am using jRE1.5, and Kava Chart Applets. Those applet jars are compiled in jdk 1.5 version. I have created one jsp where I used ,<applet> tag. The problem is when ever I am going to access the applet object from java script it is not returning the actual java applet object, when put an alert message it shows [object]. So i am not able to access the methods or the applet class.and also the screen gets hung, nothing is coming.It get stuck at the point where i tried to access the applet method like document.getElementById(applet_id).<<<some method of the applet class>>.Also it is not showing any kind of javascript error or Applet class exceptions.
    But the strange thing is, when i use jdk 1.6, the page is running fine.Also when i try to print the applet object from javascript it is showing the proper class name.
    Please help me solving the problem.

    A number of changes and improvements were made between 1.5 and 1.6 - the entire plugin is new. You need to change to 1.6, as 1.5 goes EOL about November this year and future changes to this area in 1.5 are unlikely.

Maybe you are looking for