How to do Applet/Servlet permanent interactive connection

Hi, I'm modifying an Instant Messaging Application originally implemented under the Applet client/standalone-server scheme that I'm implementing now under the Applet/Servlet scheme using HTTP Tunneling with Object Serialization. But this yet don't work correctly because the connection's flows are closed ever after a Servlet's response to a client request (in this moment are close the connection's flows). I'm using flows of type ObjectInputStream and ObjectOutputStream using Object Serialization with HTTP Tunneling.
this is part of the connection code in the servlet side:
public void doGet (HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
doPost( request, response);
public void doPost(HttpServletRequest request, HttpServletResponse response) throws
ServletException, IOException{
is = new ObjectInputStream(
new BufferedInputStream(request.getInputStream()));
try{  
response.setStatus(HttpServletResponse.SC_OK);
out = new ObjectOutputStream (
new BufferedOutputStream (response.getOutputStream ()));
out.writeObject("OK");
out.flush();
// Send the input and output flows to the Thread the Handle the client Connection
newUser(is, out);
} catch(Exception ex){
System.err.println("Exc1: "+ex.toString());
ex.printStackTrace();
Run Method to read client request:
public void run() {
SocketData sd;
while ((sd = readObject()) != null) {                               
sd.performAction(this);
close();
After a servlet response in the readObject() method the input flow is closed in the reader request of clients and the connection between the applet (client) and servlet is lost.
How to can implement a smarter HTTP Tunneling with permanent interactive connection beetween the Applet and Servlet such as in the Applet /server Standalone connection using TCP/IP Socket connection.
Is possible the use of TCP/IP Sockets in the implementation of HTTP Tunneling with Object Serialization in the Applet/Servlet permanent interactive communication scheme?
some links or code samples?
Please show me the ligth.
Thanks greatly a smarter help.

I'm not sure that I fully understand your problem, but HTTP is a stateless protocol. That means request-response pairs are completely separated from each other.
You should ask yourself if you really need to use HTTP and a servlet or if a raw TCP/IP communication would be a better approach to your problem.

Similar Messages

  • How to reach Applet- Servlet- OtherApplet comunication?

    I have reach a Applet<->Servlet<->Applet comunication....it is working very well....
    Now...i wish to reach Applet->Servlet->OtherApplet comunication....
    Applet will send a dataX to Servlet and the Servlet will send that dataX to OtherApplet.
    The OtherApplet would be presented in the same window parent....i know that it could be reached using:
    response.setHeader("Refresh","0; URL=http://212.22.31.12/OtherApplet.html");
    But...how indicate the dataX that i wish to send like input to OtherApplet?
    Somebody has a code example, ideas or suggestions that could help me please?
    Thanks,

    A servlet can only send something as a response to a request. So the servlet couldn't send the information to the second applet until the second applet asked for it, and that means you would have to write your applets so they constantly kept asking the servlet if there was anything new.

  • How to configure applet/servlet in Tomcat?

    I'm building a web application which is going to be deployed in Tomcat. I have an applet(called MYAPPLET here) which "calls" a servlet(called MYSERVLET here). I cannot figure out how to configure the whole thing.
    /test is my docbase. In /test I made a directory "applet classes" and a directory "servlet". The applet tag I use in the HTML file looks like this:
    <applet
    code="MYAPPLET.class"
    codebase="http://localhost:8080/test/applet classes/"
    <!-- Tell the applet where its peer is located -->
    <param
    name="servlet"
    value="http://localhost:8080/test/servlet/MYSERVLET" />
    </applet>
    Now, when opening the page, the applet can be found but Tomcat gives an error 404 saying that it can not find the servlet. On the other hand, If I make an entry in my web.xml (with url mapping
    <url-pattern>/test </url-pattern> or <url-pattern>/test/servlet </url-pattern>, depending on where I put MYSERVLET)
    for the servlet mentioned above and I put the MYSERVLET in either the WEB-INF/classes directory or in /test/servlet Tomcat gives an error 403. It refuses to connect to the servlet!
    Please can anyone help me. THanx in advance
    debeumers

    You are configuring Tomcat and if you have further questions then post new questions in the forum "Java Servlet Technology".
    Given that your servlet url is "localhost:8080/test/servlet/MyServlet"
    This assumes -
    1) You have created a web application called "test". You have a directory called "test" under- $CATALINA_HOME/webapps
    2) Your html files, jsp files, and subdirectory "applet-classes" (Note - do Not use spaces when naming directories) exist in this top level directory of your web app. If you choose to place your applet classes in this subdir then the codebase can be "applet-classes" - omitting the "/" means this directory is located relative to the current directory of the html file. (No jar files? No archive param then..)
    3) You have a class file called "MyServlet" located - $CATALINA_HOME/webapps/test/WEB-INF/classes
    Some versions of Tomcat require you to uncomment out the area of the Mapping for the Invoker Servlet element in $CAT_HOME/conf/web.xml.
    <servlet-name>invoker</servlet-name>
    <url-mapping>/servlet/*</url-mapping>
    Once this is done, you need not create a directory called "servlet" anywhere in your structure. It is the url mapping.
    You will want to apply url-patterns and mappings to your application specific web.xml (This is located in - $C_H/webapps/test/WEB-INF) when it comes time to deploy the app, but that is not required for testing and development. You need not make changes to the app specific web.xml at this time just to get the servlet to run.
    And finally I suggest you read a book on this subject...

  • How to Obtain Applet -servlet communication through https protocol

    We are trying to use https protocol.
    First I will explain Our Architecture. We are using JRun 3.0
    as servlet engine. We are using iplanet as a webserver.
    There are two iplanet webservers.
    There is a firewall between two iPlanet servers. i.e, one webserver
    is outside the firewall. JRun is communicating with inside iplannett
    webserver and inside iplannett webserver is communicating with
    outside iplannet server.
    If we are trying to run the application with
    this firewall, our applet is not loading,
    but the servlets and jsp pages are all working fine.
    Without the firewall, everything is working fine.
    The applet is also working fine.
    But, with the firewall, our applet is not loading.
    We are using JRE 1.3 as java plug-in.
    What is the problem so that the applet is not loading.
    and How to resolve this? can anybody give suggestion in this regard?
    Thanks in advance.

    No, I am not getting any security exception for the applet, but I am getting the following exception when working with HTTPS. The same application works fine with the default HTTP protocol
    java.net.UnknownServiceException: Input from HTTPS not expected until OutputStream is closed
         at sun.plugin.protocol.https.BrowserHttpsURLConnection.getInputStream(Unknown Source)
         at JBSchedulerXNew.initReceiveAppointmentData(JBSchedulerXNew.java:122)
         at JBSchedulerXNew.initReceiveAppointmentData(JBSchedulerXNew.java:92)
         at JBSchedulerXNewDemo.init(JBSchedulerXNewDemo.java:110)
         at sun.applet.AppletPanel.run(Unknown Source)
         at java.lang.Thread.run(Unknown Source)

  • Netscape problem with applet servlet communication

    Netscape always seems to get in the way when you use applets, right?
    I have a nice set of code from a book that shows how to do applet->servlet stuff.
    But although I'm doing this all in the privacy of my own localhost Netscape immediately put a spanner in the works with a security exception and wouldn't let the servlet respond.
    Anyone know what to do here.
    The answer is to use Internet Explorer, possibly, but I'm in linux, and I can't get Opera to work with java yet.
    Anyone got any ideas? Thanks.

    I encountered a security exception with Netscape in Linux when attempting applet-servlet stuff but that's prpbably because I haven't got the plugin for that yet...in fact I don't know if a plugin is available for sure...let me know if you do. As a matter of fact I plan on using the HTMLConverter this weekend to find out if it'll download a plugin.
    The applet-servlet thing runs fine in IE and Netscape on my Windows box as long as the plugins are there and I use the appropriate plugin tags in the HTML
    Post what you find out,
    Brad

  • Urgent: how to run applet which connected to the servlet?

    hi frends:
    i have written an applet on the server side and it supposed to pass parameters to my servlet and retrieve some info from the servlet.
    i put both applet and servlet under tomcat../WEB-INF/classes. but when i run the applet from the web browser, there is no response from the servlet.
    could anyone help me to solve this problem?
    one more thing is i know that applet is able to connect to servlet, but how about java application? is it able to do so? if yes, is it also using URLconnection as applet? and how to run it?
    i will be very appreciate if anyone can help me... thanx a million.

    You can connect to the servlet from an application.There's a URL class in java.net that has an openConnection method. Then cast the return to an HttpURLConnection and use setMethod to set up as a post request.This may be the default if you call setDoOutput(true) on the URLConnection. Then you'll need to get an OutputStream and write properly formatted form POST data to it. It's also possible to encode your data on the URL, even when using the POST method, and this may be easier when doing it programmatically from an application. To send a get request you can append the name-value pair at the end of the url.

  • Can anyone help me pls. , I deleted an app on my Ipod Touch, and It was deleted but when I connected my device on my computer and went to iTune "apps" , I saw the app I deleted and it says "install" .  Guys, how will I delete it permanently? Pls help me.

    Can anyone help me pls. , I deleted an app on my Ipod Touch, and It was deleted but when I connected my device on my computer and went to iTunes>"apps" , I still saw the app I deleted and it says "install" .  Guys, how will I delete it permanently? May you Pls help me. Thanks

    Just don't click install

  • How to show progress - Applet - Servlet

    Hi,
    I am new to applet-servlet communication. I have to show the progress at the applet front-end using a JProgressBar for a task being done at the servlet end. I request the gurus on the forum to post any example code for the above situation.

    Hi,
    U will have to use the SwingWorker to popup the JProgressBar, but in here i dont think u will be getting any input from servlet giving the job completed, if u are using jdk1.4.1 u can use
    setIndeterminate(true);
    I am attaching 2 methods below which i use to display the JProgressBar
    Method long task is where i actually call the servlet and in method buildData i create the URLConnection etc
    //appletData must implement Serializable
    public void buildData(Object appletData)throws Exception
    //define servlet name here
    ObjectInputStream inputFromServlet = null;
    URL          studentDBservlet = new URL("MyServlet");
    URLConnection servletConnection = studentDBservlet.openConnection();
    servletConnection.setDoInput(true);
    servletConnection.setDoOutput(true);
    servletConnection.setUseCaches(false);
    servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
    ObjectOutputStream outputToServlet =
              new ObjectOutputStream(servletConnection.getOutputStream());
         // serialize the object
         if (!SwingUtilities.isEventDispatchThread())
              outputToServlet.writeObject(input);
              outputToServlet.flush();
              outputToServlet.close();
              inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
         else
              inputFromServlet = longTask(servletConnection, outputToServlet, appletData);
    private ObjectInputStream longTask(final URLConnection servletConnection,
                        final ObjectOutputStream outputToServlet,
                        final Object appletData)
         final JDialog dialog = new JDialog(PlanApplet.appletFrame, "Please Wait", true);
    isProcess = true;
         MapsPanel panel = new MapsPanel();
         panel.setLayout(new BoxLayout(panel, BoxLayout.Y_AXIS));
         //MapsLabel label = new MapsLabel("Work in process....");
    //label.setFont(Constant.bigFont);
         //label.setPreferredSize(new Dimension(230, 40));
         JProgressBar progressBar = new JProgressBar();
         progressBar.setIndeterminate(true);
         progressBar.setPreferredSize(new Dimension(140, 30));
    // final JugglerLabel jugLabel = new JugglerLabel();
    // jugLabel.startAnimation();
    // panel.setPreferredSize(new Dimension(175, 175));
         MapsPanel progressPanel = new MapsPanel(new FlowLayout(FlowLayout.CENTER, 5, 5));
         progressPanel.setPreferredSize(new Dimension(140, 80));
    progressPanel.add(progressBar);
    //     progressPanel.add(jugLabel);
    //     panel.add(Box.createVerticalStrut(5));
         //panel.add(label);
         panel.add(Box.createVerticalStrut(15));
         panel.add(progressPanel);
         panel.add(Box.createVerticalStrut(15));
         dialog.setSize(150, 115);
         dialog.setResizable(false);
    //     dialog.getContentPane().add(jugLabel);
    dialog.getContentPane().add(panel);
    dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
    dialog.setLocation(ScreenSize.getDialogLocation(dialog));
    //      final javax.swing.Timer popupTimer = new javax.swing.Timer(2000, new TimerListener(dialog));
         final SwingWorker worker = new SwingWorker()
         public Object construct()
              try
              PlanApplet.applet.setCursor(new Cursor(Cursor.WAIT_CURSOR));
              outputToServlet.writeObject(appletData);
              outputToServlet.flush();
              outputToServlet.close();
              return new ObjectInputStream(servletConnection.getInputStream());
              catch (Exception exc)
              return null;
         public void finished()
    // jugLabel.stopAnimation();
              dialog.dispose();
    Toolkit.getDefaultToolkit().beep();
    isProcess = false;
              LogWriter.out("the long process is finished", LogWriter.BASIC);
         worker.start();
    // popupTimer.start();
         //System.out.println("Process complete");
         dialog.show();
    // while(isProcess)
         return (ObjectInputStream) worker.getValue();

  • Is there a good advanced review on applet-servlet communication

    I am working on a web application and unfortunately experiencing a lot of trouble trying to use an applet as front end which interacts with a couple of servlets running on Tomcat. I need to get data from one servlet and send data to another.
    There is a lot of messages posted in this and other forums about how to do this, but none of them got a response pointing to a useful advanced reference on this subject. I have reviewed some of the references given, but couldn't find a thorough detailed advanced reference on applet-servlet communication. For this I mean an exhaustive explanation of the mechanism of communication and when and when is neccesary to use each of the multiple configuration possibilities regarding content-type, message-length, request-method, connection settings, and so on.
    Would anybody be so kind to show me the right direction? As I read the (literally) hundreds of messages posted on this topic, I see this info as widely useful. Most of the topic tracks ends on void or with painful no-way sentences, and maybe many people is avoiding Java technology on web application because of this problem (development delays can abort a project).

    This sample chapter in Java developers' guide to Servlets and Jsp focuses on Applet-Servlet communication, is a pretty good one, and is free :
    http://www.javaranch.com/bunkhouse/samps/2809ch12.pdf
    As to an exhaustive & complete guide that covers absolutely everything, I may be wrong but I doubt you'll find anything like that...unless there is a book somewhere dedicated to the subject.

  • Applet-Servlet or RMI - which is better

    We are in the process of developing a swing-applet based system that requires regular interaction with multiple databases residing on more than one database server.
    The options available before us, as we evaluate are:
    a. Use "signed" applets ( as this is going to be essentially an intra-net application) and use JDBC connection to connect to more than one database ( which reside on servers other than the web server).
    b. Use applet - servlet communication - basically, the servlet would establish connection to the databases, directly or through EJB, retrieve necessary database information and pass on the objects to the applet - the front end GUI would be controlled by the applet.
    c. Use RMI
    We would like to have your perspective of the three options, with your experience in this line.
    The questions that come to us are:
    a. If the system is essentially an intra-net application, is it okay to design with "signed" applet mechanism - how far is this method common in the market and acceptable to the clients? Is it true that the signed applet would be able to establish connection to various "identified servers" that are allowed permissions in the security file?
    b. Between applet-servlet and RMI, which is a better method? What should be the factors that need to be considered? Is RMI being widely used or should we be thinking in terms of EJB, eventhough the current project is purely a Java based solution.
    Your input is highly appreciated - thanking in advance for any suggestions and inputs that you may provide.
    Thanks
    Dixie

    Dixie,
    1) IMHO signed applets are not widely used, but you can use
    ordinary applets, which are accessing other resources through
    redirector servlet on server side - I mean ordinary applets
    are prohibited to establish connect to other than it's own server.
    So you will be forced to have special servlet on your server,
    which have access to other resources on other servers - this is a
    way how to avoid applets limitation.
    2) RMI is a heavy solution, because all parameters/objects should
    be serialized over net and if network connection is unreliable
    working with system will be just a nighmare.
    3) If you think that your network connection is unreliable, you can use HTTP protocol between client and server instead of RMI. In this case
    you will have following benefits:
    i) You can still use all of powerness of thick client
    ii) Network unreliability will be defeated
    iii) Sometime if you would like to port your application to a thin
    client it will be done much more easier than in case of RMI
    4) If you would like to use thin client your only problem will
    be poorness of UI - if you can go with it - go ahead! Otherwise
    use thick client with RMI or HTTP depending on quality of network.
    Paul

  • Applet Servlet communication compiles but does not communicate

    Hi,
    I have a applet which has a button named A. By clicking the button, the applet passes the letter A to the servlet. The servlet in turn accesses an Oracle database and retrieves the name corresponding to letter A from a table (name is Andy in the present case). The servlet interacts with the databse via a simple stored procedure and uses its output parameter to display the name Andy back in the applet.
    Both the applet and servlet codes have compiled fine(servlet code compiled with -classpath option to servlet jar using a TOMCAT). However, on clicking button A in the applet, I do not get the name Andy.
    Any help/suggestion in resolution of this is highly appreciated. Thanks in advance.
    HTML CODE:
    <html>
    <center>
    <applet code = "NameApplet.class" width = "600" height = "400">
    </applet>
    </center>
    </html>
    STORED PROCEDURE CODE:
    procedure get_letter_description(
    ac_letter IN CHAR,
    as_letter_description OUT VARCHAR2) IS
    BEGIN
    SELECT letter_description INTO as_letter_description FROM letter WHERE letter =
    ac_letter;
    EXCEPTION
    WHEN no_data_found THEN as_letter_description := 'No description available';
    END get_letter_description;
    APPLET CODE:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.util.*;
    import java.io.*;
    import java.net.*;
    public class NameApplet extends Applet implements ActionListener
    private TextField text;
    private Button button1;
    private String webServerStr = null;
    private String hostName = "localhost";
         private int port = 8080;
    private String servletPath = "/examples/servlet/NameServlet?letter=";
    private String letter;
    public void init()
         button1 = new Button("A");
    button1.addActionListener(this);
    add(button1);
              text = new TextField(20);
         add(text);
    // get the host name and port of the applet's web server
              URL hostURL = getCodeBase();
         hostName = hostURL.getHost();
    port = hostURL.getPort();
              webServerStr = "http://" + hostName + ":" + port + servletPath;
    public void actionPerformed(ActionEvent e)
         if (e.getSource() == button1)
         letter = "" + 'A';
    private String getName(String letter){
    String name = "" ;
    try {
              URL u = new URL(webServerStr + letter);
              Object content = u.getContent();
    name = content.toString();
         } catch (Exception e) {
         System.err.println("Error in getting name");
    return name;
    SERVLET CODE:
    import javax.servlet.*;
    import javax.servlet.http.*;
    import java.io.*;
    import java.util.*;
    import java.sql.*;
    import java.util.Properties;
    public class NameAppletServlet extends HttpServlet {
    private static Connection conn = null;
    private static final char DEFAULT_CHAR = 'A';
    private static final char MIN_CHAR = 'A';
    private static final char MAX_CHAR = 'G';
    private static final String PROCEDURE_CALL
    = "{call get_letter_description(?, ?)}";
    protected void doGet( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    handleHttpRequest(request, response);
    protected void doPost( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    handleHttpRequest(request, response);
    protected void handleHttpRequest( HttpServletRequest request,
    HttpServletResponse response )
    throws ServletException, IOException
    String phrase = null;
    char letter = getLetter(request, DEFAULT_CHAR);
    if (letter >= MIN_CHAR && letter <= MAX_CHAR) {
    try {
    name = getName(conn, letter);
    } catch (SQLException se) {
    String msg = "Unable to retrieve name from database.";
    name = msg;
    } else {
    String msg = "Invalid letter '" + letter + "' requested.";
    //throw new ServletException(msg);
    phrase = msg;
    response.setContentType("text/plain");
    PrintWriter out = response.getWriter();
    out.println(name);
    private String getName(Connection conn, char letter)
    throws SQLException
    CallableStatement cstmt = conn.prepareCall(PROCEDURE_CALL);
    cstmt.setString(1, String.valueOf(letter));
    cstmt.registerOutParameter(2, Types.VARCHAR);
    cstmt.execute();
    String name = cstmt.getString(2);
    cstmt.close();
    return name;
    private char getLetter(HttpServletRequest request, char defaultLetter) {
    char letter = defaultLetter;
    String letterString = request.getParameter("letter");
    if (letterString!=null) {
    letter = letterString.charAt(0);
    return letter;
    public void init(ServletConfig conf) throws ServletException {
    super.init(conf);
    String dbPropertyFile = getInitParameter("db.property.file");
    try {
    Class.forName("oracle.jdbc.driver.OracleDriver");
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:myserver:1521:CDD",
    "scott",
    "tiger");
    } catch (IOException ioe) {
    throw new ServletException(
    "Unable to init ReinforcementServlet: " + ioe.toString());
    } catch (ClassNotFoundException cnfe) {
    throw new ServletException(
    "Unable to init ReinforcementServlet. Could not find driver: "
    + cnfe.toString());
    } catch (SQLException se) {
    throw new ServletException(
    "Unable to init ReinforcementServlet. Error establishing"
    + " database connection: " + se.toString());
    }

    Hi,
    I am not able to understand by which method you are doing Applet-Servlet commuincation.
    If you want to use Object Serialization method, plz.get the details from following URL.
    http://www.j-nine.com/pubs/applet2servlet/
    Ajay

  • Applet/Servlet communication - StreamCorruptedException

    Hi, I'm having a problem when I try to connect to a servlet. I am using applet/servlet communication. The problem only occurs when I have lauched a crystal report via http in a new window.
    After the report is launched if I try to hit my servlet I get the following error:
    java.io.CorruptedStreamException: invalid stream header
    Not all crystal reports I launch cause this behavior but I can see nothing in the url I use to launch the report that is out of place or different than other reports.
    APPLET-SERVLET CONNECTION
    try {
    StringBuffer path = new StringBuffer();
    path.append(ip);
    path.append("servlet/DatabaseServlet?");
    path.append("option=getRecords&query=").append(URLEncoder.encode(query,"UTF-8"));
    URL url = new URL(path.toString());
    URLConnection servletConnection = url.openConnection();
    servletConnection.setUseCaches(false);
    servletConnection.setDoInput(true);
    servletConnection.setDoOutput(true);
    servletConnection.setRequestProperty("Content-Type", "application/x-java-serialized-object");
    ObjectInputStream inputFromServlet = new ObjectInputStream(servletConnection.getInputStream());
    rc = (RecordCollection) inputFromServlet.readObject();
    inputFromServlet.close();
    } catch (Exception e) {
    e.printStackTrace();
    SERVLET CODE
    Forwards to doPost
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    System.out.println("session id: " + request.getSession().getId());
    this.doPost(request, response);
    LAUNCHING REPORT FROM APPLET
    try {
    String launchURL = host + directory + report + "?promptOnRefresh=0"+ "&" +
    authentication + "&" + key + "&" + startPeriods + "&" + reportYears + "&" + reportTitle + "&" endPeriods "&" + locations + "&" + reportPeriod + "&" + fiscalWeek + "&" + fiscalYear + "&" +time;
    context.showDocument(new URL(launchURL), "_blank");
    } catch (Exception ex) {
    ex.printStackTrace();
    SAMPLE URL THAT CAUSES PROBLEM
    http://localhost:113/Reports/OpenToBuy_3.class?promptOnRefresh=0&user0=rpuser&password0=er34sw1&[email protected]=rpuser&[email protected]=er34sw1&user0@sub2=rpuser&[email protected]=er34sw1&promptex-key="L","L1","ALL"&promptex-start="1"&promptex-years="2004","2004"&promptex-title="Report Title"&promptex-end="1"&promptex-locs="01","03","04","05"&promptex-period="Feb 2004 [04-01]"&promptex-cw="1"&promptex-cy="2004"&promptex-time=-2-52728"
    Everything works fine until I launch this report then I can no longer get data from my servlet. I thought the URL lenght for the report might be the problem but I lauch a report with a URL longer than the problem one and there I don't get the errors after. When I try to connect to the servlet the println statement in the doGet method of my servlet doesn't get printed so it's not even making it inside that method in the servlet.
    Anyone have any idea what could be causing this? Anyone have any ideas what would be causing this? I'm really stumped.

    I've seen this problem before. Because your accessing a complete URL (ie http://<host>:<port>/xxx), you are actually creating a new session. Whenever the applet opens a connection to a servlet it is running on it's own session not the same as the JSP. This is rather obvious since the Page and Applet are separate entities.
    Try sending authentication with the url. I think the syntax is:
    username:password@http://localhost/xxx
    However I'm not sure how well this might work for Tomcat. As for Java it may try and throw a MalformedURLException I would have to test it first - it's been a long time since I used this technique!
    Wish I could be more help,
    Anthony

  • Applet/servlet communication for byte transmission

    Hello all !
    I wrote an applet to transfer binary file from web servlet (running under Tomcat 5.5) to a client (it's a signed applet) but I have a problem of interpretation of byte during transmission.
    the code of the servlet is :
            response.setContentType("application/octet-stream");
            ServletOutputStream sos = response.getOutputStream();
            FileInputStream fis = new FileInputStream(new File(
                    "C:\\WINDOWS\\system32\\setup.bmp"));
            byte[] b = new byte[1024];
            int nbRead = 1;
            while (nbRead > 0) {
                nbRead = fis.read(b);
                System.out.println("octets lus = " + nbRead);
                sos.write(b, 0, nbRead-1);
            fis.close();
            sos.close();et le code de l'applet qui appelle cette servlet est :
            URL selicPortal = null;
            try {
                selicPortal = new URL(
                        "http://localhost:8080/AppletTest/servlet/FileManipulation");
            } catch (MalformedURLException e) {
                e.printStackTrace();
            URLConnection selicConnection = null;
            try {
                selicConnection = selicPortal.openConnection();
            } catch (IOException e) {
                e.printStackTrace();
            selicConnection.setDoInput(true);
            selicConnection.setDoOutput(true);
            selicConnection.setUseCaches(false);
            selicConnection.setRequestProperty("Content-Type",
                    "application/octet-stream");
            try {
                InputStream in = selicConnection.getInputStream();
                FileOutputStream fos = new FileOutputStream(new File(tempDir
                        + "\\toto.bmp"));
                byte[] b = new byte[1024];
                int nbRead = in.read(b);
                while (nbRead > 0) {
                    fos.write(b);
                in.close();
                fos.close();
             } catch (IOException ioe) {
                ioe.printStackTrace();
            }the file dowloaded is broken. it seems that bytes 01 00 or 00 01 are not correctly process.
    Some ideas to help me please ?

    hi,
    have you solved this issue.. please post me the code since i m also doing the applet/servlet communication and can use your code as reference.
    how to read the content placed in the urlConnection stream in the servlet
    Below is my code in applet
    public void upload(byte[] imageByte)
              URL uploadURL=null;
              try
                   uploadURL=new URL("<url>");
                   URLConnection urlConnection=uploadURL.openConnection();
                   urlConnection.setDoInput(true);
                   urlConnection.setDoOutput(true);
                   urlConnection.setUseCaches(false);
                   urlConnection.setRequestProperty("Content-type","application/octet-stream");
                   urlConnection.setRequestProperty("Content-length",""+imageByte.length);
                   OutputStream outStream=urlConnection.getOutputStream();
                   outStream.write(imageByte);
                   outStream.close();
              catch(MalformedURLException ex)
              catch(IOException ex)
    How can i read the byte sent on the outstream (in above code) in the servlet.
    Thanks,
    Mclaren

  • Applet servlet communication under mac os x

    Hi everbody,
    I have an applet that invokes a servlet via url connection and maintain session status using cookies. Everything works fine under linux and windows but I have problems under mac ox 10.2 (with jdk1.4.1):
    I reported an EOFException reading th stream header.
    here is my code
    URLConnection connection = null;
    try{
    connection = getConnection(entity);
    ObjectOutputStream outputToHost = new ObjectOutputStream(connection.getOutputStream());
    outputToHost.writeObject(packet);
    outputToHost.flush();
    outputToHost.close();
    }catch (Exception e) {
    error_tmp = "brokensession";
    e.printStackTrace();
    if (_cookie == null) {
    _cookie = connection.getRequestProperty("set-cookie"); 
    ObjectInputStream inputFromHost = null;
    try {
    inputFromHost = new ObjectInputStream(connection.getInputStream());
    answer = (Hashtable) inputFromHost.readObject();
    if (answer.get("error") != null){
    error_tmp = (String) answer.get("error");
    status.put("nessieStatusApplet" , error_tmp);
    } catch (Exception e) {
    status.put("nessieStatusApplet" , "connection-out");
    e.printStackTrace();
    The first time I execute the servlet call it works ok, the second time the it seems that the headers are lost and I have the excpetion.
    Maybe it is something like sun jdk bug #4325987, now solved in sun jdk.
    Any idea?

    1.4.1 on Mac OS X is under NDA, nobody can discuss this on an open fourm...Some guy was once so much upset by the users' being allowed neither to discuss their experience nor to help each other, that he founded the open source movement. (GCC, Linux are maybe the most prominent fruits.) What is his name?

  • Asynchronous applet-servlet communication

    Hi all,
    I am trying to implement asynchronous applet-servlet communication and need your help. Anything would help(I tried with synchronous applet-servlet communication but doesn't solve my problem).
    Thanks,

    http://java.sun.com/docs/books/tutorial/networking/index.html
    You can open a socket connection. Bother the client and the server
    can have separate threads for reading and writing and that you gives you
    asynchronous communication. Later, if you think the server is generating
    too many threads and not scaling, you can use features of .java.nio to
    make it more scalable:
    java.nio.channels

Maybe you are looking for

  • CBO refuses hint (sometimes)

    Sometimes, the CBO does not take hints. Can anyone explain it? SQL: SELECT * FROM v_osi_child v1 WHERE mainuuid IN (SELECT uuid FROM ot_sys_index_org v2 WHERE mainuuid IN(:p1))v_osi_child is a view which union-alls about 50 tables. ot_sys_index_org i

  • Which API to update supplier site VAT registration number?

    I am using the AP_VENDOR_PUB_PKG.Create_Vendor_SITE API call to populate the VAT_REGISTRATION_NUM field, whcih then appears as the "Default Reporting Registration Number" under the Tax Details page of the supplier screens. Unfortunately the call to A

  • 'Whats App web' email virus trojan sends to all Gmail address book

    My wife received an email on her iPhone 5, which is set up to work with her Gmail Account from a friend. It appeared to be a message from Whats App (it wasn't) and said 'You Have New Messages' and had a clickable '>Play' link. This then directed to a

  • Download pictures to pc lumia 710

    I would like to download pictures taken on my 710 to the pc one at a time.  I have followed the steps and made all the correct checks in the approiate places but no photos are transferred.  Using zune - on the screen with showing the pics on the phon

  • Trying to get rid of banding in an Illustrator CS6 image

    I'm working on a small project in Illustrator CS6, and a gradient within the project is quite visibly displaying banding. I would use Photoshop's dither to fix this, if not for the fact that I'm going to export this as an SVG, rather than a raster im