Inconsistent Stream responses b/w servlet & applet

Hi all,
I am facing problem with my servle/applet communication .I am using serialized object transport b/w the two. I am able to send my object using a URL connection class successfully to the server .
However having problems while reading the response on the applet .
It's been so incosistent that I sometimes think of switching over to some activex control instead of an applet .
I have been struggling with this one for quite sometime . Somebody help to fix this out!
First to the problem faced by me
Some times I get StreamCorruptedException saying Input stream does not contain serialized object .
Some times I get EOFException saying Invalid Header-1.
Why so much inconsistency when I am passing the same serialzed object CStreamData? Anyone's valueable input is highly appreciated.
My part of code that reads the object sent from the servlet.
public CStreamData ReadResObj(CServerRequest oRequest)
CStreamData objResponse = null;
isServerRunning = true;
try {
URL url = new URL( "http://localhost:8080"+
"/apps/servlet/MWServer");
URLConnection con = url.openConnection();
con.setUseCaches(false);
con.setRequestProperty("CONTENT_TYPE","application/octet-stream");
con.setDoInput(true);
con.setDoOutput(true);
ObjectOutputStream out = new ObjectOutputStream(con.getOutputStream());
out.writeObject(oRequest);
out.flush();
out.close();
ObjectInputStream ois = new ObjectInputStream(con.getInputStream());
//The exception is thrown here while reading...
objResponse = (CStreamData)ois.readObject();
ois.close();
}catch (Exception e)
isServerRunning = false;
return (CStreamData)objResponse;
return (CStreamData)objResponse;
}//End of readResObj
Best rgds,
prithvi

It would be interesting to see what's the response of your servlet.
Mybe the response of your servlet is an error html page
which of course can't be converted into Object of Type CStreamData.
You should think about doing some error handling before you try read from the ObjectInputStream an before you think about using ActiveX components.
for example
URLConnection con = url.openConnection();
HttpURLConnection httpConnection;
try
  URL url = new URL( "http://localhost:8080"+"/apps/servlet/MWServer");
  URLConnection con = url.openConnection();
  httpConnection = (HttpURLConnection)con;
  out.close();
  if(  httpConnection.getResposeCode() == HttpURLConnection.HTTP_OK )
     ObjectInputStream ois = new ObjectInputStream(con.getInputStream());
     objResponse = (CStreamData)ois.readObject();
     ois.close();
}If you still have problems dump the content of your servlet response
to the console and tell what you see or post parts of the response.

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!

  • Servlet-applet

    hello
    I have an html file, on which an applet is displayed. This applet is actually a frame on which there is a FileDialog. I select a file, and I want to send this String corresponding to the path of the file, to a servlet. But then, I want to stay on the servlet, and not send a response from the servlet to the applet.
    here is my code:
    html:
    <p><form action="servlet/SetOfServicesRegistrationServlet">
    <P>
    <applet code="mobi/das/aca/managementServlets/Openfile.class" width=400 height=100>
    </applet>
    <br /><br />
    Add this list of services
    <input type="submit" value="Add">
    </form>applet:
    public void actionPerformed(ActionEvent evt){
              String composant = evt.getActionCommand();
              if( composant.equals("Open") ){
                             fileToLoad = fd.getDirectory().concat(fd.getFile());
                             try{
                                  String codedValue = URLEncoder.encode(fileToLoad,"ISO-8859-1");
                                  URL url = new URL(getDocumentBase(),"http://asterix:8080/acamanager_2/servlet/SetOfServicesRegistrationServlet?message="+codedValue);
                                  URLConnection connexion = url.openConnection();
                                  BufferedReader reponse = new BufferedReader(new InputStreamReader(url.openStream()));
                             catch(IOException error){}
                        and the servlet:
    public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException, ServletException{
               response.setContentType("text/html");
               response.setBufferSize(1000);           
               PrintWriter out = response.getWriter();
               //we get the parameters sent by the html form
               String fileLocation = request.getParameter("message");
               System.out.println(fileLocation);What I'd like to see, is just a servlet, on which the path of the file is displayed.
    Any ideas?
    Help me please. I've been looking for it for too long now
    Thanks in advance
    Philippe

    Hi, thanks for the reply, let me clarify, the main
    thread is initiated by the servlet. In other words,
    the servlet is called and simply starts my Thread
    class which takes over.A thread started by a servlet, that is really a bad design and bound to cause memory leaks plus deadlocking isssue.
    So, I want my Thread Class to communicate with the
    applet during runtime. The Thread Class is simply an
    object extending the Thread java class.
    The servlet itself does not do anything - it starts
    the process and then it simply receives the results
    and outputs them to the client.just use the javax.servlet.ServletOutputStream class as one of the parameters to ur thread class. that way the thread can communicate with the applet. but i have to warn you again.
    good luck

  • 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!

  • 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,.

  • I want to send a response from the servlet and then call another servlet.

    Hi,
    I want to send a response from the servlet and then call another servlet. can this happen. Here is my scenario.
    1. Capture all the information from a form including an Email address and submit it to a servlet.
    2. Now send a message to the browser that the request will be processed and mailed.
    3. Now execute the request and give a mail to the mentioned Email.
    Can this be done in any way even by calling another servlet from within a servlet or any other way.
    Can any one Please help me out.
    Thanks,
    Ramesh

    Maybe that will help you (This is registration sample):
    1.You have Registration.html;
    2.You have Registration servlet;
    3.You have CheckUser servlet;
    4.And last you have Dispatcher between all.
    See the code:
    Registration.html
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <HTML>
      <HEAD>
        <TITLE>Hello registration</TITLE>
      </HEAD>
      <BODY>
      <H1>Entry</H1>
    <FORM ACTION="helloservlet" METHOD="POST">
    <LEFT>
    User: <INPUT TYPE="TEXT" NAME="login" SIZE=10><BR>
    Password: <INPUT TYPE="PASSWORD" NAME="password" SIZE=10><BR>
    <P>
    <TABLE CELLSPACING=1>
    <TR>
    <TH><SMALL>
    <INPUT TYPE="SUBMIT" NAME="logon" VALUE="Entry">
    </SMALL>
    <TH><SMALL>
    <INPUT TYPE="SUBMIT" NAME="registration" VALUE="Registration">
    </SMALL>
    </TABLE>
    </LEFT>
    </FORM>
    <BR>
      </BODY>
    </HTML>
    Dispatcher.java
    package mybeans;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.ServletException;
    import java.io.IOException;
    import javax.servlet.RequestDispatcher;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Dispatcher extends HttpServlet {
        protected void forward(String address, HttpServletRequest request,
                               HttpServletResponse response)
                               throws ServletException, IOException {
                                   RequestDispatcher dispatcher = getServletContext().
                                   getRequestDispatcher(address);
                                   dispatcher.forward(request, response);
    Registration.java
    package mybeans;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class Registration extends Dispatcher {
        public String getServletInfo() {
            return "Registration servlet";
        public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            ServletContext ctx = getServletContext();
            if(request.getParameter("logon") != null) {          
                this.forward("/CheckUser", request, response);
            else if (request.getParameter("registration") != null)  {         
                this.forward("/registration.html", request, response);
    CheckUser.java
    package mybeans;
    import java.io.*;
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.sql.*;
    public class CheckUser extends Dispatcher {
        Connection conn;
        Statement stat;
        ResultSet rs;
          String cur_UserName;
        public static String cur_UserSurname;;
        String cur_UserOtchestvo;
        public String getServletInfo() {
            return "Registration servlet";
        public void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            try{
                ServletContext ctx = getServletContext();
                Class.forName("oracle.jdbc.driver.OracleDriver");
                conn = DriverManager.getConnection("jdbc:oracle:oci:@eugenz","SYSTEM", "manager");
                stat = conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE, ResultSet.CONCUR_UPDATABLE);
               String queryDB = "SELECT ID, Login, Password FROM TLogon WHERE Login = ? AND Password = ?";
                PreparedStatement ps = conn.prepareStatement(queryDB); 
               User user = new User();
            user.setLogin(request.getParameter("login"));
            String cur_Login = user.getLogin();
            ps.setString(1, cur_Login);
            user.setPassword(request.getParameter("password"));
            String cur_Password = user.getPassword();
            ps.setString(2, cur_Password);
         Password = admin");
            rs = ps.executeQuery();
                 String sn = "Zatoka";
            String n = "Eugen";
            String queryPeople = "SELECT ID, Surname FROM People WHERE ID = ?";
           PreparedStatement psPeople = conn.prepareStatement(queryPeople);
                      if(rs.next()) {
                int logonID = rs.getInt("ID");
                psPeople.setInt(1, logonID);
                rs = psPeople.executeQuery();
                rs.next();
                       user.setSurname(rs.getString("Surname"));
              FROM TLogon, People WHERE TLogon.ID = People.ID";
                       ctx.setAttribute("user", user);
                this.forward("/successLogin.jsp", request, response);
            this.forward("/registration.html", request, response);
            catch(Exception exception) {
    }CheckUser.java maybe incorrect, but it's not serious, because see the principe (conception).
    Main is Dispatcher.java. This class is dispatcher between all servlets.

  • Returning multiple parameters as response from a servlet

    Hii Javaites
    I want a servlet to return multiple parameters as response.
    In my functionality , i am callling the servlet from a swing client .
    I need to get two xml strings as response from the servlet.
    Right now i am using
    PrintWriter pw=response.getWriter();
    pw.write(xmlString);
    for writing xml string . but wht if i want to send another String (xmlString2) as resposne from the servlet to the swing application ?

    You have several possibilities. If you control the XML formats you could unify the data into one XML message. You could modify your Swing app to make two requests. If it needs two separate pieces of info it is more logical to do it as two separate requests. If you really must do it this way, you could use the Zip classes (built in to Java) to put the two XML files together into a Zip file and then send that.

  • Xhtml call to servlet not returning response, not calling servlet

    I have xhtml in a web app making a call to a servlet but the response from the servlet is not displaying. The original xhtml displays after the submit button is pressed. I tried different alternatives for the servlet response, but I get the same result each time. I added logging to the servlet, but it looks like the servlet is not being called at all.
    xhtml:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:ejstreegrid="https://unfccc.int/nais/ejstreegrid"
    xmlns:grid="http://java.sun.com/jsf/composite/gridcomp"
    xmlns:nais="http://java.sun.com/jsf/composite/naiscomp">
    <body>
    <ui:composition template="/templateForm.xhtml">
    <ui:define name="title">Some title</ui:define>
    <ui:param name="currentPage" value="somepage.xhtml" />
    <ui:define name="body">
    name to be added<br/><br/>
    <form action="someServlet" method="post">
    <input type="text" name="someName" />
    <input type="submit" />
    </form>
    </ui:define>
    </ui:composition>
    </body>
    </html>servlet in web app being called:
    package netgui.servlet;
    import java.io.IOException;
    import java.util.Enumeration;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    public class someServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;
    public someServlet() {
    super();
    protected void doGet(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException   {
    processRequest(request, response);
    protected void doPost(HttpServletRequest request,
    HttpServletResponse response) throws ServletException, IOException {
    processRequest(request, response);
    private void processRequest(HttpServletRequest request,
    HttpServletResponse response) throws IOException {
    try {
    response.getWriter().write("some response");
    } catch (Exception e) {
    logger.error(e.getMessage());
    e.printStackTrace();
    response.getWriter().println("Error: " + e.getMessage());
    I also have a menu.xhtml that is calling the xhtml file:
    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:c="http://java.sun.com/jsp/jstl/core"
    xmlns:ui="http://java.sun.com/jsf/facelets">
    <body>
    <script type="text/javascript">
    $(document).ready(function() {
    $("#btn").click(function() {
    $("#upload").click();
    return false;
    </script>  
    <ui:composition>
    <div id="navigation_bar">
    <ul id="topbarleft">
    <c:choose>                 
    <c:when test="${currentPage=='somepage.xhtml'}">
    <li><b>Some Page display</b></li>
    </c:when>
    <c:otherwise>
    <li><h:outputLink value="somepage.jsf">
    <h:outputText value="some page" />
    </h:outputLink></li>
    </c:otherwise>
    </c:choose>
    </ul>
    </div>
    </ui:composition>
    </body>
    </html>Is there some special format for submitting a form to a servlet from xhtml? Any ideas what could be wrong?
    Edited by: Atlas77 on Apr 16, 2012 6:53 AM
    Edited by: Atlas77 on Apr 16, 2012 6:54 AM
    Edited by: Atlas77 on Apr 16, 2012 6:56 AM
    Edited by: Atlas77 on Apr 16, 2012 7:27 AM

    You have a template. That template doesn't have for example a h:form of its own in which the body content is placed right? Nested forms don't work.
    Also for the next time, use \ tags to post code; that makes it actually readable. As you can see, the forum is now trying to interpret some special characters for formatting.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to send response from a servlet to a page in CQ??

    hi.. i have this servlet from where i need to send a string array or list array to the CQ webpage?? and this need's to be populated into a dropdown list on that page??..

    Hi,
    Unless if there is a specific need to use a servlet, you can implement the same logic(to generate dropdown list) inside a java bean. Use a getter that returns dropdown list and use the bean inside jsp and call the getter to populate dropdown list. In case, if you have to use servlet, you can use HttpClient inside bean getter to obtain response from the servlet and return the list or array.
    Regards,
    Sravan.

  • 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.

  • Servlet applet communication

    I'm having a problem getting a servlet to answer a call from an applet...in the applet I do something like:
    String servlet = "http://192.168.123.148/root/MyServlet.class";
    url= new URL(servlet);
    conn = url.openConnection();
    conn.setUseCaches(false);
    in = conn.getContentLength();
    String contype = conn.getContentType();
    And in the servlet:
    java.io.PrintWriter out = response.getWriter();
    response.setContentType("text/html");
    response.setHeader("segment",Integer.toString(99));
    out.flush();
    The problem is I don't get my header back in the applet...and when I look at the content type, its "application/java-vm"...not " text/html"...as I set in the servlet...???

         InputStream urlInput = null;
         HttpURLConnection urlConn =  null;
         URL url = new URL(urlStr);
         urlConn = (HttpURLConnection)url.openConnection();
         urlConn.setDoInput(true);
         urlConn.setDoOutput(true);
         urlConn.setUseCaches(false);
         urlConn.setRequestMethod("POST");
         urlConn.setRequestProperty("Accept-Language", "en");
         urlConn.setRequestProperty("content-type", "text/xml");
         urlInput = urlConn.getInputStream();

  • How can I generate a html page in a servlet-applet connection?

    Hello, I have an applet which contains an ok button, when I click this button, I need that servlet generate an html page and view it in browser. How can I do this?
    Thanks

    But with this method only is possible I think open a page web, and if it is possible call url of the servlet, you generate other request and response object (other call to method doGet or doPost because ShowDocument needs parameter url), so the previously request when I click button ok it's no the same and how I obtain the prinwriter from first request, showDocument don't obtain html page from printwriter.

  • Streaming files through a Servlet to macintosh clients

    Hi,
    I have a servlet which streams diffrent kind of files to the client. I works perfectly with Windows and IE5.0,6.0 and Firefox. But on macintosh (IE5.2) the file name is the name of the servlet. In example if the servlet is named getFile, the file name used by the macintosh client to save the file will be getFile.
    Does anyone know the trick to make macintosh clients corretly resolve the filename/mime type??
    Thanks

    I finally figured out that setting my conent type like this:
    response.setContentType("application/octet-stream");
    works.
    But now I'm stuck with another little problem, Mac does not seem to convert the %20 is filenames to spaces.
    Any suggestions?

  • Servlet applet connection [help desperately needed!]

    i'm sick of this now. every time i fix something, something else goes wrong. this time i can't figure out what's happening.
    the problem is that once the input to the servlet from tha applet has been submitted, the servlet throws an IOException:
    java.io.IOException: Server returned HTTP response code: 500 for URL: http://stuweb3.cmp.uea.ac.uk/y0241725/webapp/EgServlet
    all that should happen is that the following code should take the input and tokenize it to see if its either the email address and password being submitted or an sql string to execute.
    public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException
            String email = "";
            String password = "";
            String name = "";
            String id = "";
            String SQL = "";
            String output = "";
            // Read in the message from the servlet
            StringBuffer msgBuf = new StringBuffer();
            BufferedReader fromApplet = req.getReader();
            String line;
            while ((line=fromApplet.readLine())!=null)
                if (msgBuf.length()>0) msgBuf.append('\n');
                msgBuf.append(line);
            fromApplet.close();
            String input = msgBuf.toString();
            StringTokenizer st = new StringTokenizer(input);
            if(st.hasMoreTokens())
                // email + password
                if(!st.nextToken().equals("UPDATE"))
                    connType = 1;
                    email = st.nextToken();
                    password = st.nextToken();
                    try
                        // DB connection to get name and id  
                        Class.forName("org.postgresql.Driver");
                        Connection Conn =
                            DriverManager.getConnection(strConnectURL,strUserPass,strUserPass);
                        Statement Stmt = Conn.createStatement();
                        SQL = "SELECT mem_id, name FROM member WHERE em_add ='"+email+"' AND password ='"+password+"';";
                        ResultSet RS = Stmt.executeQuery(SQL);
                        while(RS.next())
                           id = RS.getString(1);
                           name = RS.getString(2);
                        if(id.equals(null))
                            id = "0";
                        if(name.equals(null))
                            name = "not connected";
                        RS.close();
                        Stmt.close();
                        Conn.close();
                    catch(Exception e)
                // SQL update string
                else
                    connType = 2;
                    SQL = input;
                    try
                        // DB connection to update points
                        Class.forName("org.postgresql.Driver");
                        Connection Conn =
                        DriverManager.getConnection(strConnectURL,strUserPass,strUserPass);
                        Statement Stmt = Conn.createStatement();
                        Stmt.executeUpdate(SQL);
                        Stmt.close();
                        Conn.close();
                    catch(Exception e)
            if(connType == 1)
                // Send name and id back to the applet
                resp.setContentType("text/plain");
                PrintWriter toApplet = resp.getWriter();
                // OUTPUT ==============================================================
                toApplet.println("name: "+name+" id: "+id);
                // =====================================================================
                toApplet.close();
            if(connType == 2)
                // Send name and id back to the applet
                resp.setContentType("text/plain");
                PrintWriter toApplet = resp.getWriter();
                // OUTPUT ==============================================================
                toApplet.println(SQL);
                // =====================================================================
                toApplet.close();
    }the input for the servlet is either in the format: email password or is an sql update statement
    Any help is very much appriciated!!! Thank you in advance

    the problem is that once the input to the servlet from tha applet has been
    submitted, the servlet throws an IOException:
    java.io.IOException: Server returned HTTP response code: 500 for URL:
    http://stuweb3.cmp.uea.ac.uk/y0241725/webapp/EgServlet
    Which means the servlet failed, and somewhere on the server it showed the exception that it actually threw, and stack trace. You have to go find that information and diagnose it from there.

  • How to start streaming from server side after applet initialized on client

    Hi,
    I am using JSP for on demand streaming server.
    I have included an applet in jsp page which start new player on client side after on streamreceive event.
    But my problem is how to give call to server that applet on client side has been initialized and now streaming can go on.
    Is there any method / way to call class file which will start streaming?

    Oracle is designed to support connection from client to server. The client originates the connection.
    If you want the server to initiate the connection, you need to make the server pretend it is a client. Oracle even does this internally, when they want to use 'External Procedures'
    You may also use Oracle's Message Queue mechanism, called 'Advanced Queueing' to use a 'publish subscribe' model instead of a connection model. That is discussed in the Advanced Queue manual in the documentation at http://docs.oracle.com
    Finally, you can explore the possibility of using RMI from the database, as discussed in the Java related documentation at the same location.

Maybe you are looking for

  • Applescript to trigger a Mail Rule

    I'm trying to do something I thought would be simple ... but I can't figure it out. My goal is to get specific messages from one mailbox and put them into my Inbox. I've used a rule with a MailTags deadline to get the messages into the box, and I hav

  • GL account requires Profit Segment (COPA) mapping Message no. ZA01005

    Hello, Does anyone have additional information on how to resolve this error message in SAP during goods receipt for a production order using MIGO? The system prompts "Document is ok" during check entry but then this error message appears when you cli

  • Issue in population of Ship to party house number in Sales Order

    Hi Experts, I have created a program that creates an IDOC from the input file and then it uses IDOC_INPUT_ORDERS to create sales order from the IDOC. Now, the input file has Ship to party that is different from the Sale to party. So, I created the ID

  • Enterprise Manager Configuration Failed

    Hi everyone, when i install a db using the Assistant Configuartion Database i get no error exept this:      Enterprise manager configuration failed due to the following error -      Listener is not up. Start the listener and run EM configuration agai

  • I am having problems with my email messages with Firefox

    My problem with Firefox ONLY seems to occur with messages in my email (hotmail-outlook). Quite often I open an email to see no message OR I click on a link to a video and no video appears. What does appear is a black screen with the sound of the vide