Communication between servlet & applet

Hello everybody,
Well, I have a problem with my applet/servlet system.
I Would like my applet to send some queries to the servlet.
However, I don't know how to link the applet with the servlet (the only way I know is to use "openConnection()", but I don't see how to incorporate my query in the URLConnection (in order to have one, I need openCOnnection, and once it's done, well, the doGet method has already be laucnh, without any parameter to read). In my case, the DoGet methods of the servlet is launched, and of course, the HTTPRequest is almost empty, seeing thath I don't see how to specify the differnets parameters.
Is thereany simple meaning to make the applet communicate this the servlet, sending strings, and receiving objects (I have already solve the problem of the sending of an object from the servlet to the applet, in the doGet method).
Thank you very much
C U

In the applet html include a servlet parameter.
<param
name="servlet"
value="/SqlServlet" />
In your applet open a connection to servlet.
InputStream in = null;
URLConnection conn = null;
URL url = null;
String servlet = getParameter("servlet");
url = new URL(servlet + "?sql=" + URLEncoder.encode(sql));
conn = url.openConnection();
in = conn.getInputStream();

Similar Messages

  • Communication between servlet & rich client - ObjectStream or OutputStream?

    Hi,
    I need to send a text file from a servlet to a rich client. Is it better to send it over OutpputStream or wrap it up as an Object(eg: StringBuffer) and send it over OutputStream?
    Will the performance be significantly be affected if I try to wrap the file into an object at the Servlet's end and send it over ObjectStream? We are planning to wrap all responses from the servlet into a generic response object (containing data, exceptions and error codes if any) and send it to the client
    Please advice. Thanks in advance!

    Using object streams will create some protocole overhead. But you can minimize the effect by using compression.
    Ex:- java.util.zip.GZIPOutputStream & GZIPInputStream
    If you have already decided to use a genaric responce object then it will be good to have a generic request object too that will make your communication more flexible.
    But remember when you are doing serialization you might get problems when having different java versions in different ends if your object structures use data structures provided by java API (Ex:- Collections). You can work arround this problem (In most cases) by implementing custom serialization using writeReplace and readResolve methods.

  • ObjectStream communication between servlet and rich client

    Hi,
    I need to send multiple objects from a servlet to a rich client.
    Is it possible to send 2 objects of different types at the same time - ie, a hashtable and a custom object by writing them one after another into the response's ObjectOutputStream?
    Also, if I have two vectors containing different object types, say a Vector of Strings and a Vector of custom objects, how do I read the ObjectStream at the client end to get these two objects? Do I read two Vectors from the ObjectInputStream and then check the contained object using instanceOf?
    In the above scenarios, is it better to wrap the entire set of objects with a serialized wrapper class and send that single object from the server to the client?
    Please advice. Thanks in advance!

    You can send any number of objects in a stream one after other. If they are in different types/classes then you have to be carefull when casting to the specific types at the other end becouse if you try to cast to wrong type you get a runtime exception.
    Normally when you receive the objects you will know in advande (programming time) which vector comes first in the stream so you can treat them acordingly.
    Since both of them are vectors you can cast them to vector references at the read end and can tread the elements of the first vectors as strings and the elements of the other vectors as something else provided that the client always send the string vector first.
    Whether to make it a single object or ot is a design decision that you have to make. It it make sence to put those two vectors together(logically related) then its better to do so.

  • Communication between servlet(client behavior) and stand alone java program

    Hello all:
    I need to send a message (ascii characters sequence) from a servlet to a java program, but I'm not sure what is the best way to get it: socket, JMS or other mechanism that I don't know.
    Is the servlet who is operating how client behavior.
    Please, any comment will be appreciated, regards,
    Ulises.

    You can always start a ServerSocket on the client (kinda sounds funny, doesn't it) which will accept connections. You then open a plain old Socket on the server to connect to the client's listener. (Note, this is the reverse of a normal set-up). Once you have the connection established, you will call getOutputStream() to get a stream to write to. Likewise, you will call getInputStream() to read the data sent. You will want to investigate the java.net.* and java.io.* libraries.
    - Saish

  • Communication between servlets with data

    I have a servlet that creates a HTML table (a report) with some data. The data used is a vector of some java objects. Now, I want to add a hyperlink to each row in the table and when clicked, open a new browser window and show the record info in detail. I know how to add a hyperlink and open a new window, but I do not know how to pass the data associated with that (user-clicked) row to a new browser window. The Java object for that row contains 20 items and I do not want to pass them in name-value pair to another servlet. Is there a smarter way to do this ? Can someone please help me?
    This is a rough sketch of how I want to put a hyperlink in a row: The following method creates rows in my table:-
    private void loadTableData(Vector data, PrintWriter out, int col)
            throws IOException {
            MyRecordObject myRec = null;
            if (data != null) {
                Object[] myArray = null;
                myArray = new Object[data.size()];
                for (int k = 0; k < data.size(); k++) {
                    myArray[k] = data.get(k);
                Arrays.sort(myArray, new MySorterClass(col));
                for (int i = 0; i < myArray.length; i++) {
                    myRec = (MyRecordObject) myArray;
    out.println("<TR bgcolor= \"E5E5E5\"> ");
    // When the following hyper link
    //is clicked, pass "myRec" object to some servlet/JSP
    //and create a new HTML page with that data
    out.println("<TD> <a href=\"myDetailInfoServlet_with_data\" target =\"_blank\"> " + myRec.getName() + " </a> </TD>"); // <==
    out.println("<TD>" + myRec.getFathersName() + "</TD>");
    out.println("<TD>" + myRec.getMothersName() + "</TD>");
    out.println("<TD>" + myRec.getPetName() + "</TD>");
    out.println("<TD>" + myRec.getSpouseName() + "</TD>");
    out.println("</TR>");
    out.println("</TBODY>");
    out.println("</TABLE>");
    out.println("</div>");
    out.println("</html>");

    My approach would be to just pass along an id with the hyperlink. Something you use to identify which record you want to display. This can be the recordId, or maybe the index of it in the data vector if that is still available and hasn't changed.
    eg
    out.println("...<a href=\"myDetailInfoServlet_with_data\?id= " + i + " ...
    Also, I would recommend using JSPs for this sort of stuff.
    For sure, retrieve your data in a servlet, but then just put it into request/session variables, and forward to a JSP to display.
    using out.println for table code is a real pain in the butt.
    Cheers,
    evnafets

  • COMMUNICATION BETWEEN JAVASCRIPT AND JAVA APPLET: US$20 AWARD FOR SOLUTION!

    COMMUNICATION BETWEEN JAVASCRIPT AND JAVA APPLET PROBLEM (Easy Filter Java Applet) -
    US$20 TO ANYONE WHO CAN RESOLVE THE PROBLEM
    To forum visitors:
    I am prepared to pay a standard shareware fee of US$20 to a user who can resolve this technical problem.
    If your advice resolves the problem, I'll forward the payment to your postal address (include your
    address with your reply, and also your email address)
    I am attempting to enable a HTML button (using Javascript's onClick command) to directly input a number into one of the parameter text boxes in the Easy Filter Java applet (ie, enter a new color value number in the text field of the standard Colors Multiplicator Filter interface).
    The applet is Freeware and can be downloaded at: http://www.javazoom.net/applets/easyfilter10/EasyFilter10.html
    (It is a very effective bitmap display and editing utility)
    To achieve this, I am trying to access the part of the applet that defines and sets the textbox. The text box is defined in the .class file by accessing the parameter details in the genericfilter.txt file (accompanies the .class files). I need to access 'private String appletInitialize()' and then one of the 'textFieldParameters' which sets the textbox.
    I understand the basic syntax for referencing the applet:
    document.appletname.setString("An example"). However, accessing the text fields in this applet is more complex!!
    Please can you recommend the correct Javascript syntax to achieve communication with the applet.
    Thank you for your kind assistance.
    JM Graham
    [email protected]
    The Java source code for the applet: EasyFilter.class
    # Easy Filter - E.B/JavaZOOM 1999 #
    # Contact: [email protected] #
    # http://javazoom.hypermart.net #
    /* Originally compiled from EasyFilter.java */
    import java.awt.*;
    import java.io.*;
    import java.net.*;
    import java.applet.Applet;
    import java.awt.event.KeyEvent;
    import java.awt.event.KeyListener;
    import java.awt.image.MemoryImageSource;
    import java.awt.image.PixelGrabber;
    import java.util.Vector;
    public synchronized class EasyFilter extends Applet implements KeyListener
    private String paramFileName;
    private Color bgColor;
    private Color fgColor;
    private Color parColor;
    private Color sepColor;
    private Color titleColor;
    private Color helpColor;
    private int WinWidth;
    private int WinHeight;
    private String title;
    private String logoFileName;
    private String originalImageFileName;
    private String filteredCaption;
    private String originalCaption;
    private Vector paramsName;
    private Vector paramsValue;
    private Vector paramsComment;
    private Panel panelParameters[];
    private Label labelParameters[];
    private TextField textFieldParameters[];
    private Label labelComments[];
    private int nbParameters;
    private ScrollPane scrollPaneParams;
    private Panel panelParams;
    private Image theLogo;
    private Image theOriginalImage;
    private Image theFilteredImage;
    private int theOriginalPixelArray[];
    private int logoWidth;
    private int logoHeight;
    private int imageWidth;
    private int imageHeight;
    private drawCanvas canvasTitle;
    private Panel panelTitle;
    private Label labelTitle;
    private Panel panelImages;
    private Panel panelOriginalImage;
    private drawCanvas canvasOriginalImage;
    private Label labelOriginalImage;
    private Panel panelFilteredImage;
    private drawCanvas canvasFilteredImage;
    private Label labelFilteredImage;
    private Panel panelHelp;
    private Label labelHelp;
    private int Yspc;
    private FilterImplementation theFilter;
    public void init()
    String string = null;
    string = appletInitialize();
    setBackground(bgColor);
    if (string != null)
    removeAll();
    setBackground(Color.white);
    setForeground(Color.black);
    Label label = new Label(new StringBuffer("Error: ").append(string).toString(), 1);
    Panel panel = new Panel();
    panel.add(label);
    add(panel);
    setLayout(new FlowLayout(1, 5, Yspc));
    public void keyPressed(KeyEvent keyEvent)
    panelHelp.removeAll();
    boolean flag = true;
    if (KeyEvent.getKeyText(keyEvent.getKeyCode()).equals("Enter"))
    for (int i = 0; i < nbParameters; )
    try
    paramsValue.setElementAt(new Double(textFieldParameters.getText()), i);
    i++;
    catch (NumberFormatException e)
    labelHelp.setText(labelParameters[i].getText() + ": Not a Number");
    flag = false;
    break;
    if (flag == 1)
    labelHelp.setText(" .... Running, please wait .... ");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    panelHelp.doLayout();
    theFilter.updateParameters(paramsValue);
    theFilter.computeFilter();
    theFilteredImage = createImage(new MemoryImageSource(theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight(), theFilter.getFinalImageBuffer(), 0, theFilter.getFinalImageWidth()));
    canvasFilteredImage.setImage(theFilteredImage);
    canvasFilteredImage.setBounds(0, 0, theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight());
    canvasFilteredImage.repaint();
    panelHelp.removeAll();
    labelHelp.setText("- Done -");
    else
    labelHelp.setText("- Press Enter to run the Filter -");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    panelHelp.doLayout();
    public void keyReleased(KeyEvent keyEvent)
    public void keyTyped(KeyEvent keyEvent)
    private String appletInitialize()
    WinWidth = size().width;
    WinHeight = size().height;
    if (getParameter("bgcolor") == null)
    bgColor = new Color(0, 0, 40);
    else
    bgColor = new Color(Integer.parseInt(getParameter("bgcolor"), 16));
    if (getParameter("fgcolor") == null)
    fgColor = new Color(255, 255, 255);
    else
    fgColor = new Color(Integer.parseInt(getParameter("fgcolor"), 16));
    if (getParameter("sepcolor") == null)
    sepColor = new Color(158, 128, 128);
    else
    sepColor = new Color(Integer.parseInt(getParameter("sepcolor"), 16));
    if (getParameter("parcolor") == null)
    parColor = new Color(24, 24, 24);
    else
    parColor = new Color(Integer.parseInt(getParameter("parcolor"), 16));
    if (getParameter("titlecolor") == null)
    titleColor = new Color(255, 255, 0);
    else
    titleColor = new Color(Integer.parseInt(getParameter("titlecolor"), 16));
    if (getParameter("helpcolor") == null)
    helpColor = new Color(0, 255, 255);
    else
    helpColor = new Color(Integer.parseInt(getParameter("helpcolor"), 16));
    paramsName = new Vector();
    paramsValue = new Vector();
    paramsComment = new Vector();
    paramFileName = getParameter("paramfile");
    String string = readParams(paramFileName);
    if (string != null)
    return string;
    MediaTracker mediaTracker = new MediaTracker(this);
    theOriginalImage = getImage(getDocumentBase(), originalImageFileName);
    mediaTracker.addImage(theOriginalImage, 0);
    if (logoFileName != null)
    theLogo = getImage(getDocumentBase(), logoFileName);
    mediaTracker.addImage(theLogo, 1);
    try
    mediaTracker.waitForAll();
    catch (InterruptedException e1)
    return "Error while loading image";
    if (mediaTracker.isErrorAny())
    return "Error while loading image";
    if (logoFileName != null)
    logoWidth = theLogo.getWidth(this);
    logoHeight = theLogo.getHeight(this);
    imageWidth = theOriginalImage.getWidth(this);
    imageHeight = theOriginalImage.getHeight(this);
    theOriginalPixelArray = new int[imageWidth * imageHeight];
    PixelGrabber pixelGrabber = new PixelGrabber(theOriginalImage, 0, 0, imageWidth, imageHeight, theOriginalPixelArray, 0, imageWidth);
    try
    pixelGrabber.grabPixels();
    panelTitle = new Panel();
    canvasTitle = new drawCanvas();
    labelTitle = new Label();
    panelTitle.setLayout(new FlowLayout(1, 10, Yspc));
    add(panelTitle);
    panelTitle.setBackground(bgColor);
    panelTitle.add(canvasTitle);
    canvasTitle.setImage(theLogo);
    canvasTitle.setBounds(0, 0, logoWidth, logoHeight);
    labelTitle.setText(title);
    catch (InterruptedException e2)
    return "Internal Error, Try RELOAD !";
    if (title != null)
    panelTitle.add(labelTitle);
    labelTitle.setForeground(titleColor);
    labelTitle.setFont(new Font("Dialog", 1, 14));
    panelImages = new Panel();
    panelOriginalImage = new Panel();
    canvasOriginalImage = new drawCanvas();
    labelOriginalImage = new Label();
    panelFilteredImage = new Panel();
    canvasFilteredImage = new drawCanvas();
    labelFilteredImage = new Label();
    panelImages.setLayout(new FlowLayout(1, 10, Yspc));
    add(panelImages);
    panelImages.setBackground(bgColor);
    panelOriginalImage.setLayout(new BorderLayout(0, 2));
    panelImages.add(panelOriginalImage);
    panelOriginalImage.setBackground(Color.black);
    panelOriginalImage.add("Center", canvasOriginalImage);
    canvasOriginalImage.setImage(theOriginalImage);
    canvasOriginalImage.setBounds(0, 0, imageWidth, imageHeight);
    labelOriginalImage.setText(originalCaption);
    labelOriginalImage.setAlignment(1);
    panelOriginalImage.add("South", labelOriginalImage);
    labelOriginalImage.setBackground(Color.lightGray);
    labelOriginalImage.setForeground(Color.black);
    labelOriginalImage.setFont(new Font("SansSerif", 0, 10));
    panelFilteredImage.setLayout(new BorderLayout(0, 2));
    panelImages.add(panelFilteredImage);
    panelFilteredImage.setBackground(Color.black);
    panelFilteredImage.add("Center", canvasFilteredImage);
    theFilter = new FilterImplementation(paramsValue, theOriginalPixelArray, imageWidth, imageHeight);
    theFilter.computeFilter();
    theFilteredImage = createImage(new MemoryImageSource(theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight(), theFilter.getFinalImageBuffer(), 0, theFilter.getFinalImageWidth()));
    canvasFilteredImage.setImage(theFilteredImage);
    canvasFilteredImage.setBounds(0, 0, theFilter.getFinalImageWidth(), theFilter.getFinalImageHeight());
    labelFilteredImage.setText(filteredCaption);
    labelFilteredImage.setAlignment(1);
    panelFilteredImage.add("South", labelFilteredImage);
    labelFilteredImage.setBackground(Color.lightGray);
    labelFilteredImage.setFont(new Font("SansSerif", 0, 10));
    scrollPaneParams = new ScrollPane(0);
    panelParams = new Panel();
    nbParameters = paramsName.size();
    int i = WinHeight - (33 + 7 * Yspc + logoHeight + imageHeight + 23);
    if (i < Yspc + 2 + 24)
    i = Yspc + 2 + 24;
    scrollPaneParams.setBounds(0, 0, WinWidth - 10, i);
    panelParams.setLayout(new GridLayout(nbParameters, 1, 5, Yspc / 2));
    scrollPaneParams.add(panelParams);
    panelParams.setBackground(sepColor);
    panelParameters = new Panel[nbParameters];
    labelParameters = new Label[nbParameters];
    textFieldParameters = new TextField[nbParameters];
    labelComments = new Label[nbParameters];
    for (int j = 0; j < nbParameters; j++)
    panelParameters[j] = new Panel();
    panelParameters[j].setLayout(new FlowLayout(0, 5, 1));
    panelParams.add(panelParameters[j]);
    panelParameters[j].setBackground(parColor);
    labelParameters[j] = new Label();
    labelParameters[j].setText((String)paramsName.elementAt(j));
    panelParameters[j].add(labelParameters[j]);
    labelParameters[j].setForeground(fgColor);
    labelParameters[j].setFont(new Font("Dialog", 1, 12));
    textFieldParameters[j] = new TextField(8);
    textFieldParameters[j].setText(paramsValue.elementAt(j).toString());
    panelParameters[j].add(textFieldParameters[j]);
    textFieldParameters[j].setBackground(fgColor);
    textFieldParameters[j].addKeyListener(this);
    labelComments[j] = new Label();
    labelComments[j].setText((String)paramsComment.elementAt(j));
    panelParameters[j].add(labelComments[j]);
    labelComments[j].setForeground(fgColor);
    add(scrollPaneParams);
    panelHelp = new Panel();
    labelHelp = new Label();
    panelHelp.setLayout(new FlowLayout(1, 5, 0));
    add(panelHelp);
    panelHelp.setBackground(bgColor);
    labelHelp.setText(" Change colour values and press enter ");
    labelHelp.setAlignment(1);
    panelHelp.add(labelHelp);
    labelHelp.setForeground(helpColor);
    return null;
    private String readParams(String string1)
    Object object1;
    String string2;
    if (string1 == null)
    return "Filename of filter's parameters needed";
    try
    URL uRL = new URL(getDocumentBase(), string1);
    URLConnection uRLConnection = uRL.openConnection();
    uRLConnection.setDoInput(true);
    uRLConnection.setUseCaches(false);
    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(uRLConnection.getInputStream()));
    string2 = null;
    catch ()
    return object1.getMessage();
    catch ()
    return object1.getMessage();
    catch ()
    return object1.getMessage();
    if (bufferedReader != null)
    Object object2;
    try
    for (object2 = bufferedReader.readLine(); object2 != null && string2 == null; object2 = bufferedReader.readLine())
    string2 = extractFormat(object2);
    catch ()
    string2 = object2.getMessage();
    finally
    bufferedReader.close();
    if (string2 != null)
    return string2;
    else
    return null;
    private String extractFormat(String string1)
    if (string1.length() == 0)
    return null;
    int i = 0;
    int j = string1.indexOf(" ", i);
    if (j == -1)
    return "Bad format error (space missing)";
    String string2 = string1.substring(i, j);
    if (string2.equals("TITLE"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in TITLE missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in TITLE missing)";
    title = string1.substring(i, j);
    return null;
    if (string2.equals("ORIGINALCAPTION"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in ORIGINALCAPTION missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in ORIGINALCAPTION missing)";
    originalCaption = string1.substring(i, j);
    return null;
    if (string2.equals("FILTEREDCAPTION"))
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in FILTEREDCAPTION missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in FILTEREDCAPTION missing)";
    filteredCaption = string1.substring(i, j);
    return null;
    if (string2.equals("LOGO"))
    i = j + 1;
    j = string1.length();
    logoFileName = string1.substring(i, j);
    return null;
    if (string2.equals("ORIGINALIMAGE"))
    i = j + 1;
    j = string1.length();
    originalImageFileName = string1.substring(i, j);
    return null;
    if (!string2.equals("PARAM"))
    return null;
    i = j;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    paramsName.addElement(string1.substring(i, j));
    i = j + 2;
    j = string1.indexOf(32, i);
    if (j == -1)
    return "Bad format in a PARAM line";
    try
    paramsValue.addElement(new Double(string1.substring(i, j)));
    j = string1.indexOf(34, i);
    catch (NumberFormatException e)
    return "Bad format in a PARAM line";
    if (j == -1)
    return "Bad format (Double quote in PARAM comment missing)";
    i = j + 1;
    j = string1.indexOf(34, i);
    if (j == -1)
    return "Bad format (Double quote in PARAM comment missing)";
    paramsComment.addElement(string1.substring(i, j));
    return null;
    public EasyFilter()
    logoHeight = 33;
    Yspc = 5;

    Addition to my above submission
    To clarify, I'll offer the US$20 to the FIRST person who offers me a workable solution to the problem, not to everyone!!!
    JMGRAHAM

  • 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 not communicating with servlet when given ip address (not localhost)

    I have a strange problem with my applet -
    I have a java applet and a Tomcat server running. I am able to communicate between the applet
    and a servlet on the server (sending strings from applet to servlet, for example..) when the
    URL that I write in the applet is -
    "http://localhost:8080/ProjectName/ServletName "
    BUT - when instead of that "localhost" I insert my ip address, it throws the exception:
    java.net.ConnectException: Connection refused: connect
    in the line -
    urlConn.getOutputStream(); (urlConn is the HttpURLConnection that I created with the URL)
    also, I did port forwarding (I have a router)
    so that 8080 port will be directed to my computer, and tested the forwarding, and it does work.
    Does anybody know why there is a problem?
    Thank you.. :)

    >
    well, in the final version of the project the applet will be signed.. >Uh-huh..
    >
    but, I got tired of signing it every time I edited the code, so now I just simply run it as a "java applet" project
    from the eclipse.. NOT as a signed jar..>Eclipse has Ant built in. Write a script that will compile/build/sign the jar for you, then build it to the point of being signed for every test run. (Just today I was making some changes to a signed applet project that does just that - I probably built it 25 times before I was happy with the changed code - not a problem.)
    >
    you think that's the problem ?>Yep. Not that I provide support for Eclipse, nor know how it goes about launching applets (trusted or sandboxed).

  • 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 to Applet communication between two seperate threads and jsp pages

    Hi,
    have two java applets running on two separate jsp pages. I am trying to have one applet talk to the other applet. I have tried putting the applets in a static hashtable, but I found out (through trial and error) that the memory is not shared between the applets. Needless to say the appletcontext object will not work as well. I have also tried to put the applet threads into a thread group, but it seems that the second applet can't find the first applet's threads. Is there a funky way that I need to create the threads for the threadgroup? Is there a way or type of object that I can use that will share the static memory between plugins? I am using 1.6 in IE. Or am I looking at this wrong and there is an easy way to do this and I am not seeing it.
    Thanks,
    Marc

    Hi Mylene,
    I hope I have understood your problem correctly. I can try to give you a tip. The times I've had to do a pop-up, for instance to show details or a part of the data in a table, I call a javascript function with the required parameters (an ID for details or an array of rows) when the button is pressed or a link is clicked. The function then builds a URL with all the paremeters and uses it to call the standard window.open function. After that the request is handled "as usual", ie as if you didn't actually do a pop-up but simply displayed a new page. The content of the pop-up is a jsp with all the required code to build the table and/or display the data. The contents of the table or data are retrieved with the help of the parameters sent.
    I'm not sure if the portal kit provides some kind of standard functionality for this, but in the cases I've worked with J2EE solutions this has been the most common way of solving the problem.
    I hope this helps.
    kind regards,
    Dionisios

  • Communicating between Applets on same web browser page.

    I one wishes to do variable/function calls between seperate applets on one page,
    -is there a simple way to do this (i.e. a global context object as a go between)?
    Could I have/be pointed to an example?

    Global context indeed. Your Applet will have a getAppletContext() method which returns an... AppletContext! And that has a getApplet(String) method which gets a reference to some other applet in the same context. The API documentation for that method contains more information than what I've posted here.

  • Servlet-Applet project. Architectural problem.

    Hello, everybody!
    I'm to make client-server web project, client works with different databases via server (using servlet). The protocol of the project is as follows:
    - Client requests to �erver and gets applet.
    - All communications between client and server are to be made via applet-servlet. So, client makes some operations using applet, then sends data to server. After the data being processed on the server side, client gets the possibilities to make further operations.
    The problem is choosing the proper architecture. Having sigle applet and processing communications with single applet-servlet is not good, because I need to get client the possibility to choose database, then choose table, edit records and so on. I want to have applets for every type of operations. I mean, after client gets start applet, he sends the request to server, which processes it and gets another applet for database choosing and so on.
    The question is: is it possible to build such architecture with many applets and data transfers between them?

    Why does it need to be through applet?
    Why can't the same applet take care of most (all?) your database chores?

  • Communication between two Macs Server

    Communication between two Macs Server:
    Can they work together and communicate and interact normally in a PowerMac network, OS X 10.5.8 Server installed, and a MacPro computer that is running Server 4.0.3 on Yosemite? Had to do some additional implementation?
    Regards

    from the JavaDocs:
    http://java.sun.com/j2ee/1.4/docs/api/javax/servlet/ServletContext.html
    getContext
    public ServletContext getContext(java.lang.String uripath)
    Returns a ServletContext object that corresponds to a specified URL on the server.
    This method allows servlets to gain access to the context for various parts of the server, and as needed obtain RequestDispatcher objects from the context. The given path must be begin with "/", is interpreted relative to the server's document root and is matched against the context roots of other web applications hosted on this container.
    In a security conscious environment, the servlet container may return null for a given URL.
    Parameters:
    uripath - a String specifying the context path of another web application in the container.
    Returns:
    the ServletContext object that corresponds to the named URL, or null if either none exists or the container wishes to restrict this access.
    See Also:
    RequestDispatcher

  • Communication between SAP and 3rd Party Systems using IDOC HTTP XML Interfa

    Hi
    i am try do
    Communication between SAP and 3rd Party Systems using IDOC HTTP XML Interface
    With The help of SDN Contribution
    link----
    ( have look on it)
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/4943f2b7-0a01-0010-37af-faff35b2f08c
    I am getting error in
    Partner system as HTTPLOG and "Execute" to check the results
    Error is --  Port could not be created
    RFC destination HTTPLOG Not specified for system HTTPLOG
    any 1 have any idea  if plzzzzzzzz...........
    Thank u
    Ram

    Hello .
      we are also in  process of implementing the same
    could you share the knowledge pl?
    1)is it a separate add on with ALE to saphr
       or using ECC ??
    2)can u share the configuration part ??
    we are trying it on webas as addon 3.0 .

  • Diagram with communications between all XI components

    Is there a diagram on help.sap.com or somewhere that along with specifying the communication connectivity between all of the XI components it also has the URLs and RFC destinations that correspond to the cache refreshes, etc.
    This would really help troubleshoot some intermittent problems I am having.  Much appreciated.

    Hi George Hamilton ,
    The following web-sites give u step-by-step solution for communications between all XI components :
    SAP XI Infrastructure : Demo Example configuration
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/605c8e2f-d611-2a10-5187-abd511fa339b
    SAP Security Guide XI
    http://help.sap.com/saphelp_nw04/helpdata/en/14/ef2940cbf2195de10000000a1550b0/frameset.htm
    XI Configuration guide
    http://help.sap.com/saphelp_nw04/helpdata/en/d7/f01a403233dd5fe10000000a155106/frameset.htm
    Technical Communication between configuration tools, Integration Builder tools and monitoring tools
    http://help.sap.com/saphelp_nw04/helpdata/en/5e/f85141196ff423e10000000a155106/content.htm
    Monitoring Set Up guide for SAP Netweaver 04
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/df1a6313-0a01-0010-c9a2-d76d3f115d42
    Process Integration : Demo Example configuration
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/80da7e60-d511-2a10-8885-f9ee5b36d63b
    Troubleshooting the File Adapter
    https://www.sdn.sap.com/irj/sdn/wiki?path=/display/xi/troubleshootingtheFile+Adapter&
    Xi message processing monitoring & troubleshooting
    https://www.sdn.sap.com/irj/servlet/prt/portal/prtroot/docs/library/uuid/2f2a9fa2-0a01-0010-32ac-d281db722b86
    SAP XI- New possibilities in SAP Integration
    http://www.english.bcc.com.pl/pad_files/aw_files/260_EN_AW_096_DB21_SAPXI_ENG.pdf
    Interoperability between Microsoft BizTalk Server 2004 and SAP XI 3.0
    http://download.microsoft.com/download/5/7/f/57f1490e-8a8d-497b-bbae-ec2a44b3799f/BizTalkSAPXIInterop.pdf
    Supportability Set up guide : SAP Netweaver 04
    https://www.sdn.sap.com/irj/sdn/go/portal/prtroot/docs/library/uuid/cc1ec146-0a01-0010-90a9-b1df1d2f346f
    *******Pls reward points if u find this useful
    cheers!
    gyanaraj

Maybe you are looking for

  • Changing document size ?

    How can I change the size of my page in Illustrator? I'm working with a PDF. I've followed the directions here: http://help.adobe.com/en_US/Illustrator/14.0/WS714a382cdf7d304e7e07d0100196cbc5f-64bea.htm l They say to go to the print menu and do it th

  • How to create a hyperlink in iPad mail client?

    I've been searching for ways to add hyperlinks to my e-mail messages, but can't seem to find any help. Anyone know how to do this?

  • CMP and Stored Procedures

    Is it possible to invoke a stored procedure from within a method in the home interface of an entity bean using CMP 2.0? The entity bean has been deployed to OC4J.

  • Importing Still Images - Stuck on one step

    I've never imported a still image into FCP before but I'm following some Ken Stone articles on doing it but I'm stuck on one bit. I've pasted in the directions below and its the third one, "paste in photgraphs". I've never used Photoshop (im using el

  • Ifsconfig : IFS 1.1.9 & RedHat 7.1 problem

    Hi, I'm currently trying to install a new development platform using the latest goodies (RedHat 7.1, ifs 1.1.9, latest IBM 1.3 JVM and so on). Using the official RedHat workaround (+ unset LANG) Oracle and IFS both install fine. However when I try to