Sending different types of data from applet to servlet

Hi,
I am writing an applet that uploads a file to a servlet. I can send the file to the servlet just fine.
Applet Side
1. open a URLConnection
2. open a DataOutputStream
3. write the file to the DataOutputStream
Servlet Side:
1. open a ServletInputStream from the HttpServletRequest
2. write the bytes to a file
This is all fine.
However, I need to upload the filename (a String) with the file. How do I do this? I can't send the filename over as a String from the applet using the same DataOutputStream. right? This would corrupt the file that i am sending as the servlet wouldn't know that the difference between the filename and the actual contents of the file.
Is there some property I can set in the urlconnection that gets passed to the request variable? i.e. URLConnection.setProperty ("filename", foo.txt) and then on the servlet side do this: String filename = eq.getProperty ("filename")
Thank you for the help

If all the additional data you want to send to server are textual or numaric data about the file (which is in the body of the request)
Use those information as additional http headers.
And read those header information from the servlet request object at the server side
ex:-
URL u = new URL("your url");
HttpURLConnection c = (HttpURLConnection)u.openConnection();
c.addRequestProperty("x-application-file-name","name of the file");
c.addRequestProperty("x-application-file-size","size of the file");
//then open the stream and write the data to the request body
//             At server side         //
String name = request.getHeader("x-application-file-name");
long size= Long.parseLong(request.getHeader("x-application-file-size"));

Similar Messages

  • How to send different type of data

    Hello, everyone,
    I am trying to send different types of data between client and server.
    For example, from server to client, I need to send some String data, using PrintWriter.println(String n); and send some other stuff using OutputStream.write(byte[] b, int x, int y). What I did is setting up a socket, then send them one by one. But it didn't work.
    I am just wondering if there is anything I need to do right after I finished sending the String data and before I start sending other stuff using OutputStream. (Because if I only send one of them, then it works; but when I send them together, then the error always happened to the second one no matter I use PrintWriter first or the OutputStream first)

    To send mixed type of data by hand allways using the same output/input stream, you could do:
    on server side
            ServerSocket serverSocket = null;
            Socket clientSocket = null;
            OutputStream out = null;
            try
                /*setup a socket*/
                serverSocket = new ServerSocket(4444);
                clientSocket = clientSocket = serverSocket.accept();
                out = new BufferedOutputStream(clientSocket.getOutputStream());
                /*send a byte*/
                int send1 = 3;
                out.write(send1);
                /*send a string with a line termination*/
                String send2 = "a string sample";
                out.write(send2.getBytes("ISO-8859-1"));
                out.write('\n');
            finally
                try { out.close(); }
                catch (Exception e) {}
                try { clientSocket.close(); }
                catch (Exception e) {}
                try { serverSocket.close(); }
                catch (Exception e) {}
    on client side
            Socket clientSocket = null;
            InputStream in = null;
            try
                clientSocket = new Socket("localhost", 4444);
                in = new BufferedInputStream(clientSocket.getInputStream());
                /*receive the byte*/
                int receive1 = in.read();
                System.out.println("The received message #1 is: " + receive1);
                /*receive the string up to the line termination*/
                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                int c;
                while (((c = in.read()) != '\n') && (c != -1))
                    baos.write(c);
                String receive2 = baos.toString("ISO-8859-1");
                System.out.println("the received message #2 is: " + receive2);
            finally
                try { in.close(); }
                catch (Exception e) {}
                try { clientSocket.close(); }
                catch (Exception e) {}

  • Problem in sending image from applet to servlet

    dear friends,
    i have a need to send an image from applet to servlet via HttpConnection and getting back that image from applet.
    i am struggling with this sice many hours and got tired by searching any post that would help me but haven't got yet.
    i tried using this code but it dosent make any execution sit right. i got NPE at ImageIcon.getDescription() line;
    at applet side
          jf.setContentPane(getJContentPane());
                     FileDialog fd=new FileDialog(jf,"hi");
                     fd.setMode(FileDialog.LOAD);
                     fd.setVisible(true);   
                     v=new Vector();
                     try{                                                
                               FileInputStream fis=new FileInputStream(new File(fd.getDirectory()+fd.getFile()));      
                               byte[] imgbuffer=new byte[fis.available()];
                               fis.read(imgbuffer);
                               ImageIcon imgdata=new ImageIcon(imgbuffer);
                               v.add(0,imgicon);
                                String strwp ="/UASProject/Storeimage";              
                                URL servletURL = new URL(getCodeBase(),strwp);             
                                HttpURLConnection servletCon = (HttpURLConnection)servletURL.openConnection();       
                                servletCon.setDoInput(true); 
                                servletCon.setDoOutput(true);
                                servletCon.setUseCaches(false);
                                servletCon.setDefaultUseCaches(false);   
                                servletCon.setRequestMethod("POST");     
                                servletCon.setRequestProperty("Content-Type", "application/octet-stream");   
                                servletCon.connect();            
                                ObjectOutputStream oboutStream = new ObjectOutputStream(servletCon.getOutputStream());                     
                                oboutStream.writeObject(v);
                                v.remove(0);
                                oboutStream.flush();      
                                oboutStream.close();  
                                //read back from servlet
                                ObjectInputStream inputStream = new ObjectInputStream(servletCon.getInputStream());
                                 v= (Vector)inputStream.readObject();                     
                                 imgicon=(ImageIcon)v.get(1);
                                 showimg.setIcon(imgicon);
                                 this.getContentPane().validate();
                                 this.validate();  
                                inputStream.close();                                                        
                             //  repaint();
                     }catch(Exception e){e.printStackTrace();}  and this is at servlet side
            try {       
                         Vector v=new Vector();                    
                         ObjectInputStream inputFromjsp = new ObjectInputStream(request.getInputStream());                                      
                          v = (Vector)inputFromjsp.readObject();                                                                                                          
                          imgicon=(ImageIcon)v.get(0);                     
                          inputFromjsp.close();            
                          System.out.println(imgicon.getDescription());                                      
                          v.remove(0);
                          v.add(1,imgicon);
    //sending back to applet
                           response.setContentType("application/octet-stream");
                          ObjectOutputStream oboutstream=new ObjectOutputStream(response.getOutputStream());            
                          oboutstream.writeObject(v);
                          oboutstream.flush();
                          oboutstream.close();
                   } catch (Exception e) {e.printStackTrace();}  i really need your help. please let me out of this headche
    thanks
    Edited by: san_4u on Nov 24, 2007 1:00 PM

    BalusC wrote:
    san_4u wrote:
    how can i made a HttpClient PostMethod using java applets? as i have experience making request using HttpURLConnection.POST method. ok first of all i am going make a search of this only after i will tell. please be onlineOnce again, see link [3] in my first reply of your former topic.
    yeah! i got the related topic at http://www.theserverside.com/tt/articles/article.tss?l=HttpClient_FileUpload. please look it, i am reading it right now and expecting to be reliable for me.
    well what i got, when request made by html code(stated above) then all the form fields and file data mixed as binary data and available in HttpServletRequest.getinputstream. and at servlet side we have to use a mutipart parser of DiskFileItemFactory class that automatically parse the file data and return a FileItem object cotaing the actual file data,right?.You can also setup the MultipartFilter in your environment and don't >care about it further. Uploaded files will be available as request attributes in the servlet.is the multipartfilter class file available in jar files(that u suggested to add in yours article) so that i can use it directly? one more thing the import org.apache.commons.httpclient package is not available in these jar files, so where can got it from?
    one mere question..
    i looked somewhere that when we request for a file from webserver using web browser then there is a server that process our request and after retrieving that file from database it sends back as response.
    now i confused that, wheather these webservers are like apache tomcat, IBM's webspher etc those processes these request or there is a unique server that always turned on and process all the request?
    because, suppose in an orgnisation made it's website using its own server then, in fact, all the time it will not turned on its server or yes it will? and a user can make a search for kind of information about this orgnisation at any time.
    hopes, you will have understand my quary, then please let me know the actual process
    thanks
    Edited by: san_4u on Nov 25, 2007 11:25 AM

  • How to Send the material master data from sap4.6c to ECC6.0

    Hi
        Friends this is shalini Shah, i got one requirement that is
    how to send the materail master data  from SAP 4.6C to ECC6.0 using XI.
    i  know the file to idoc and idoc to file scenarios but i don't know this one.
    please help me friends, Thanks in advance.
    Regards
    Shalini Shah

    Hi Shalini,
    To trigger IDoc these configurations should be done in the SAP 4.6, XI and ECC 6.0.
    SAP XI
    1) RFC Destination (SM59)
    a) Choose create.
    b) Specify the name of the RFC destination
    c) Select connection type as 3 and save
    d) In the technical settings tab enter the details SAP SID/URL and system number#.
    e) Enter the Gateway host as same details above SID/URL.
    f) Gateway service is 3300+system number#.
    g) In the Logon /Security tab, enter the client user & Password details of Destination system.
    h) Test the connection and remote logon.
    2) Create Port (IDX1)
    a) Select create new button
    b) Enter the port name as SAP+SID (The starting char should be SAP)
    c) Enter the destination client.
    d) Enter the RFC Destination created in SAP R/3 towards other system.
    e) Save
    3) Load Meta Data for IDOC (IDX2)
    a) Create new
    b) IDOC Message Type
    c) Enter port created in IDX1.
    SAP R/3 (4.6 and ECC 6.0)
    1) RFC Destination (SM59)
    a) Choose create.
    b) Specify the name of the RFC destination
    c) Select connection type as 3 and save
    d) In the technical settings tab enter the details SAP SID/URL and system number#.
    e) Enter the Gateway host as same details above SID/URL.
    f) Gateway service is 3300+system number#.
    g) In the Logon /Security tab, enter the client user & Password details of Destination system.
    h) Test the connection and remote logon.
    2) Create Port (We21)
    a) First Select Transactional RFC and then click create button
    b) Enter the destination port name as SAP+SID (The starting char should be SAP)
    c) Enter the destination client.
    d) Enter the RFC Destination created in SAP R/3 towards other system.
    e) Save
    3) Create Partner Profile (WE20)
    a) Create New
    b) Create the Partner no. name as same the logical system name of the destination system.
    c) Select Partner type LS
    d) Enter details for Type: US/USER, Agent, and Lang.
    e) Click on the + button to select the message type.
    f) Select Partner no. and LS which ever create above.
    g) Select Message type
    h) Select Process code related to the Message type.
    I) save.
    Also go ther the Blog <a href="/people/swaroopa.vishwanath/blog/2007/01/22/ale-configuration-for-pushing-idocs-from-sap-to-xi Configuration for Pushing IDOC's from SAP to XI</a> By Swaroopa Vishwanath
    U need to import the IDoc types both inbound and outbound to XI.
    1. Create Inbound and Outbound Message interface.
    2. Do one to one message mapping.
    3. Define an Interface mapping.
    ID:
    1. Create 1 Sender aggrement.
    2. Create 1 Receiver aggrement.
    3. Define 1 RD and ID.
    4. Only create an receiver IDoc CC.
    Regards
    San
    <a href="Remember to set the thread to solved when you have received a solution to set the thread to solved when you have received a solution</a>
    Where There is a <a href="https://www.sdn.sap.comhttp://www.sdn.sap.comhttp://www.sdn.sap.com/irj/sdn/weblogs?blog=/weblogs/topic/16">blog</a> there is a Way.

  • Send data from doPost() in servlet to AJAX

    Hi
    I need to send data from my servlet to my html(which contains AJAX), so as per the motivation of the AJAX, this should be done without my webpage reloading / refresh.
    my code on the ajax side is something like this:
    var xmlHttp = false;
    function getXMLHttpRequest(val) {
        try{
             xmlHttp = new XMLHttpRequest();
        }catch(err1){
            try{
                 xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            catch(err2){
                try { xmlHttp = new ActiveXObject("Msxml2.XMLHTTP");}
                catch(err3){ request = null;}
        if (xmlHttp == false) {
            alert("Error creating request object !!");
        else if(xmlHttp != false){
            return xmlHttp;
    var xmlhttp = new getXMLObject();
    function ajaxFunction() {
           if(xmlHttp) {
            var value1 = document.getElementById("value1");
            xmlHttp.open("POST","ajax_controlller",true); //getname will be the servlet name
            xmlHttp.onreadystatechange  = handleServerResponse;
            xmlHttp.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
            xmlHttp.send("value1=" + value1.value); //Posting txtname to Servlet
    function handleServerResponse() {
         if (xmlHttp.readyState == 4) {
              if(xmlHttp.status == 200) {
    //            document.myForm.message.innerHTML=xmlHttp.responseText;
                alert(xmlHttp.responseText); //Update the HTML Form element
              else {
                 alert("Error during AJAX call. Please try again");
         }and the servlet (doPost()) looks like this :
                  if(request.getParameter("value1") != null){
                   value = request.getParameter("value1");
              else 
                   value = "";
              response.setContentType("text/html");
              response.getWriter().write("helllo");I however, do not understand what is wrong, do I need to specify the name of the html file just like we do in case of RequestDispatcher() methods. I dont think that is the case here ?

    The problem is: My value is passed correctly from my HTML(ajax) file to the servlet but I am not able to send the result(or data) from the servlet to the HTML (ajax) file, I know I can do this easily by session management but I need to establish this without the session management , In the servlet I use
    response.setContentType("text/html");          
    response.getWriter().write("helllo");
    and in the HTML file I use
    function handleServerResponse() {
         if (xmlHttp.readyState == 4) {
              if(xmlHttp.status == 200) {
                alert(xmlHttp.responseText); //Update the HTML Form element
              else {
                 alert("Error during AJAX call. Please try again");
            }so as per the logic I should get the alert as the result sent by the servlet on the same html page, but instead the servlet writes the hello on the new page, the URL of this page is the address of the servlet itself, so I conclude that I am not able to establish the connection between the servlet and the html file. Could you clarify this please ?

  • " writing  data from  applet  to desktop "

    dear friends,
    plz help me on how to " write data from applet to desktop ".

    http://java.sun.com/developer/technicalArticles/Security/Signed/

  • Pass byte[] from applet to servlet

    I have an application that allows users to copy an image from the system clipboard into a frame. What I would like to be able to do, is save that image into a database (db2 on as/400). In order to do that, I try to send the image, which I turned into a byte[] in order to easily insert into the database, from the applet to the servlet using streams (no actual file io), but the image always comes up null when I pass it to the servlet. What am I doing wrong? The image gets copied and drawn from the clipboard just fine, but I can't send it to the servlet. I only included the part of the servlet that tries to retreive the byte array. I know the applet code is a little long, but I figured it might be of interest to someone. Please help!
    Here's the code for the applet:
    import java.awt.*;
    import java.awt.event.*;
    import java.applet.*;
    import java.awt.datatransfer.*;
    import java.net.*;
    import java.io.*;
    import javax.swing.ImageIcon;
    import java.util.*;
    import java.awt.image.*;
    public class PicApp extends Applet implements ClipboardOwner
    PrintWriter opWriter = null;
    private Button cmdPaste = new Button();
    private ImageControl destinationImage = new ImageControl ();
    private BorderLayout defaultLayout = new BorderLayout ();
    public Image tempImage = null;
    public ImageIcon transferImage = null;
    private String webServerStr = "";
    private String hostName = null;
    private int port = 80;
    private String servletPath = null;
    Clipboard clipboard;
    //the byte array I try to pass
    public byte[] passed = null;
    public String passedAction = null;
    public void init()
    try
    opWriter = new PrintWriter( new BufferedWriter( new FileWriter( "pictureDetails.txt" ) ) );
    catch(Exception e)
    e.printStackTrace();
    hostName = getParameter("HostName");
    servletPath = getParameter("ServletPath");
    passedAction = getParameter("Action");
    //setLayout
    this.setLayout (defaultLayout);
    this.setBackground(java.awt.Color.gray);
    cmdPaste.setLabel("Paste Image from Clipboard");
    this.add (cmdPaste, BorderLayout.SOUTH);
    this.add (destinationImage, BorderLayout.NORTH);
    //add action listener
    cmdPaste.addActionListener (new cmdPasteActionListener ());
    //initialize the clipboard
    clipboard = getToolkit().getSystemClipboard();
    // get the host name and port of the applet's web server
    try
    opWriter.println("Picutre Applet Details\n");
    URL hostURL = getCodeBase();
    opWriter.println("hostURL = " + hostURL.toString() + "\n");
    hostName = hostURL.getHost();
    opWriter.println("hostIP = " + hostName + "\n");
    port = hostURL.getPort();
    opWriter.println("port = " + port + "\n");
    if (port == -1)
    port = 80;
    if(passedAction == "" || passedAction == null)
    webServerStr = "http://" + hostName + ":" + port + servletPath;
    opWriter.println("Web String full = " + webServerStr);
    else
    webServerStr = "http://" + hostName + ":" + port + servletPath + "?act=" + passedAction;
    opWriter.println("Web String full = " + webServerStr);
    opWriter.close();
    catch(Exception e)
    e.printStackTrace();
    // INNER CLASSES
    class cmdPasteActionListener implements ActionListener
    public void actionPerformed (ActionEvent event)
    Transferable clipboardContent = clipboard.getContents(this);
    //Transferable clipboardContent = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null);
    if ((clipboardContent != null) && (clipboardContent.isDataFlavorSupported(DataFlavor.imageFlavor)))
    try
    //display Image
    tempImage = (Image)clipboardContent.getTransferData(DataFlavor.imageFlavor);
    destinationImage.setImage(tempImage);
    int width = (new ImageIcon(tempImage).getIconWidth());
    int height = (new ImageIcon(tempImage).getIconHeight());
    PixelGrabber pg = new PixelGrabber(tempImage, 0, 0, width, height, true);
    passed = new byte[width*height];
    passed = (byte[])pg.getPixels();
    //send Image
    ProcessPicture();
    catch (UnsupportedFlavorException e)
    catch (IOException e)
    }//end of if
    else if(clipboardContent == null)
    }//end of method
    }//end of inner class
    public PicApp()
    public void lostOwnership (Clipboard parClipboard, Transferable parTransferable)
    System.out.println("Lost ownership of clipboard");
    protected void ProcessPicture()
    try
    // connect to the servlet
    URL servletURL = new URL( webServerStr );
    //URLConnection servletConnection = servletURL.openConnection();
    HttpURLConnection servletConnection =(HttpURLConnection)servletURL.openConnection();
    // inform the connection that we will send output and accept input
    servletConnection.setDoInput(true);
    servletConnection.setDoOutput(true);
    // Don't used a cached version of URL connection.
    servletConnection.setUseCaches (false);
    // Specify the content type that we will send binary data
    servletConnection.setRequestProperty("Content-Type", "application/octet-stream");
    // send the image object to the servlet using serialization
    sendImageToServlet(servletConnection);
    // now, let's read the response from the servlet.
    // this is simply a confirmation string
    readServletResponse(servletConnection);
    catch (Exception e)
    System.out.println(e.toString());
    protected void readServletResponse(URLConnection servletConnection)
    BufferedReader inFromServlet = null;
    try
    // now, let's read the response from the servlet.
    // this is simply a confirmation string
    inFromServlet = new BufferedReader(new InputStreamReader(servletConnection.getInputStream()));
    String str;
    while (null != ((str = inFromServlet.readLine())))
    System.out.println("Reading servlet response: " + str);
    inFromServlet.close();
    catch (IOException e)
    System.out.println(e.toString());
    protected void sendImageToServlet(URLConnection servletConnection)
    ObjectOutputStream outputToServlet = null;
    try
    // send the image object to the servlet using serialization
    outputToServlet = new ObjectOutputStream(servletConnection.getOutputStream());
    //check size of image
    System.out.println(passed.length);
    // write objectt
    outputToServlet.writeObject(passed);
    outputToServlet.flush();
    outputToServlet.close();
    catch (IOException e)
    System.out.println(e.toString());
    servlet:
    public void performTask(HttpServletRequest request, HttpServletResponse response)
    ObjectInputStream inputFromApplet = null;
    byte[] ImageFromApplet = null;
    PrintWriter out = null;
    BufferedReader inTest = null;
    try
    // get an input stream from the applet
    inputFromApplet = new ObjectInputStream(request.getInputStream());
    // read the serialized imageIcon data from applet
    ImageFromApplet = (byte[])inputFromApplet.readObject();
    inputFromApplet.close();
    catch(Exception e)
    // handle exception
    byte[] transferImage = ImageFromApplet;
    if(transferImage == null)
    System.out.println("Image passed is empty!");

    D,
    I read your code. I believe you are trying to send the byte array with the wrong outputStream.write method. For a byte[] I have successfully used the form, servletOut.write(byteArray, 0, byteArray.length). You have to tell the receiver how much data will be sent to it so it knows when to stop read in the data.
    Example:
    _url = new java.net.URL(serverURL);
    //Attempt to connect to the host
    java.net.URLConnection connection = _url.openConnection();
    // Initialize the connection
    connection.setUseCaches(false);
    connection.setDoOutput(true);
    connection.setDoInput(true);
    connection.setRequestProperty("Content-type", "application/octet-stream");
    BufferedInputStream fileInputStream = new BufferedInputStream(fIS);
    int nBytesAvailable = fileInputStream.available();
    byte byteArray[] = new byte[nBytesAvailable];
    fileInputStream.read(byteArray, 0, nBytesAvailable);
    fileInputStream.close();
    fIS.close();
    // send data to servlet, get outstream, write data, flush, close.
    DataOutputStream outStream = new DataOutputStream(connection.getOutputStream());
    outStream.write(byteArray, 0, nBytesAvailable);
    outStream.flush();
    outStream.close();

  • Sending a file from Applet to servlet HELP me Please

    Sorry, i have the problem this is my code Applet & Servlet but it seems working asynchronously if you have some ideas please reply me i send bytes on outputstream but the inputstream of servlet receive nothing bytes but write my system.out.print on screen server:
    Applet:
    URL servletURL = new URL(codebase, "/InviaFile/servlet/Ricevi");
    HttpURLConnection urlConnection = (HttpURLConnection) servletURL.openConnection();
    urlConnection.setRequestMethod("POST");
    urlConnection.setUseCaches(false);
    urlConnection.setDoOutput(true);
    urlConnection.setDoInput(true);
    urlConnection.setAllowUserInteraction(false);
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
    urlConnection.setRequestProperty("Content-length", String.valueOf(100));
    urlConnection.connect();
    if(urlConnection.HTTP_BAD_REQUEST == HttpURLConnection.HTTP_BAD_REQUEST){
    /*System.out.println("Cattiva Richiesta: "+urlConnection.getContentEncoding());
    System.out.println("Tipo di metodo: "+urlConnection.getRequestMethod());
    System.out.println("Tipo di Risposta: "+urlConnection.getResponseCode());
    System.out.println("Tipo di messaggio: "+urlConnection.getResponseMessage());
    System.out.println("Tipo di contenuto: "+urlConnection.getContentType());
    System.out.println("Tipo di lunghezza contenuto: "+urlConnection.getContentLength());
    System.out.println("Tipo di doinput: "+urlConnection.getDoInput());
    System.out.println("Tipo di doouput: "+urlConnection.getDoOutput());
    System.out.println("Tipo di URL: "+urlConnection.getURL());
    System.out.println("Tipo di propriet� richiesta: "+urlConnection.getRequestProperty("Content-Type"));
    System.out.println("Entra if");
    DataOutputStream dout = new DataOutputStream(urlConnection.getOutputStream());
    InputStream is = urlConnection.getInputStream();
    if(ritornaFile("C:/Ms.tif", dout))System.out.println("Finita lettura");
    dout.close();
    urlConnection.disconnect();
    System.out.println("Fine Applet");
    }catch(Exception e) { System.err.println(e.getMessage());e.printStackTrace();}
    public boolean ritornaFile(String file, OutputStream ots)throws Exception{
    FileInputStream f = null;
    try{
    f = new FileInputStream(file);
    byte[] buf = new byte[4 * 1024];
    int byteLetti;
    while((byteLetti = f.read()) != -1){ots.writeByte(buf, 0, byteLetti);ots.flush();
    while((byteLetti = f.read()) != -1){ots.write(byteLetti);ots.flush();
    System.out.println("byteLetti= "+byteLetti);
    return true;
    }catch(Exception ex){
    System.err.println(ex.getMessage());
    return false;
    }finally{
    if(f != null)f.close();
    Servlet:
    HttpSession ses = request.getSession(true);
    System.out.println("Passa servlet "+request.getMethod());
    System.out.println("Passa servlet "+ses.getId());
    ServletInputStream servletinputstream = request.getInputStream();
    DataInputStream dis = new DataInputStream(request.getInputStream());
    int c = dis.available();
    System.out.println("c="+c);
    //ServletOutputStream servletoutputstream
    //response.getOutputStream();
    response.setContentType("application/octet-stream");
    System.out.println("URI= "+request.getRequestURI());
    System.out.println("pathTranslated: "+request.getPathTranslated());
    System.out.println("RemoteUser: "+request.getRemoteUser());
    System.out.println("UserInRole: "+String.valueOf(request.isUserInRole("")));
    System.out.println("pathInfo: "+request.getPathInfo());
    System.out.println("Protocollo: "+request.getProtocol());
    System.out.println("RemoteAddr:"+request.getRemoteAddr());
    System.out.println("RemoteHost:"+request.getRemoteHost());
    System.out.println("SessionID:"+request.getRequestedSessionId());
    System.out.println("Schema:"+request.getScheme());
    System.out.println("SeesionValido:"+String.valueOf(request.isRequestedSessionIdValid()));
    System.out.println("FromURL:"+String.valueOf(request.isRequestedSessionIdFromURL()));
    int i = request.getContentLength();
    System.out.println("i: "+i);
    ritornaFile(servletinputstream, "C:"+File.separator+"Pluto.tif");
    System.out.println("GetMimeType= "+getServletContext().getMimeType("Ms.tif"));
    InputStream is = request.getInputStream();
    int in = is.available();
    System.out.println("Legge dallo stream in="+in);
    DataInputStream diss = new DataInputStream(servletinputstream);
    int ins = diss.read();
    System.out.println("Legge dallo stream ins="+ins);
    int disins = diss.available();
    System.out.println("Legge dallo stream disins="+disins);
    is.close();
    System.out.println("Fine Servlet");
    catch(Exception exception) {
    System.out.println("IOException occured in the Server: " + exception.getMessage());exception.printStackTrace();
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    public void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, java.io.IOException {
    processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo() {
    return "Short description";
    public void ritornaFile(InputStream its, String fileDest )throws Exception{
    FileOutputStream f = null;
    try{
    f = new FileOutputStream(fileDest);
    byte[] buf = new byte[2 * 1024];
    int byteLetti;
    while((byteLetti = its.read()) != -1){
    f.write(buf, 0, byteLetti);
    f.flush();
    System.out.println("Byteletti="+byteLetti);
    }catch(Exception ex){
    System.err.println(ex.getMessage());
    }finally{
    if(f != null)f.close();

    Hi all,
    Can anyone help me.I am trying to send an audio file from a applet to servlet with HTTP method(no raw sockets), also the servlet shld be able to save the file on the server.Any suggestions welcome.USing audiostream class from javax.sound.sampled.
    The part of applet code which calls servlet is :
    URL url = new URL("http://" + host + "/" + context + "/servlet/UserUpdateWorkLogAudio?userid=" + userId.replace(' ', '+') + "&FileName=" + filename.replace(' ', '+'));
    URLConnection myConnection = url.openConnection();
    myConnection.setUseCaches(false);
    myConnection.setDoOutput(true);
    urlConnection.setRequestProperty("Content-Type", "application/octet-stream");
    myConnection.connect();
    out = new BufferedOutputStream(myConnection.getOutputStream());
    AudioSystem.write(audioInputStream, fileType,out); // IS THIS RIGHT APPROACH?
    ************************end of applet code**********************
    ************************servlet code******************************
    try
    {BufferedInputStream in = new BufferedInputStream(request.getInputStream());
    ????????What code shld i write here to get the audio file stream
    BufferedOutputStream out = new BufferedOutputStream(new FileOutputStream(filename));
    *********************************************end***********************
    Thanks
    Joe.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • Problem while sending seriailized  object from applet to servlet

    Hi I m having Object communication between Applet and Servlet.
    I m getting error stack trace as
    java.io.EOFException
         at java.io.ObjectInputStream$PeekInputStream.readFully(Unknown Source)
         at java.io.ObjectInputStream$BlockDataInputStream.readShort(Unknown Source)
    at java.io.ObjectInputStream.readStreamHeader(Unknown Source)
         at java.io.ObjectInputStream.<init>(Unknown Source)
         at com.chat.client.ObjectClient.write(ObjectClient.java:56)
    at the line
    ObjectInputStream ois = new ObjectInputStream(conn.getInputStream());
    thanks in advance
    Ravi
    the whole code is as follows....
    public Serializable write(Serializable obj) throws IOException,ClassNotFoundException{
              URLConnection conn = serverURL.openConnection();
              conn.setDoOutput(true);
              conn.setDoInput(true);
              conn.setUseCaches(false);
              conn.setRequestProperty("Content-Type", "java-internal/"+obj.getClass().getName());
              conn.connect();
              ObjectOutputStream oos= null;
              try{
              oos = new ObjectOutputStream(
                   conn.getOutputStream());
                        oos.writeObject(obj);
                   catch(Exception ee){
                                       ee.printStackTrace();
                   finally{
                        if(oos!=null){
                             oos.flush();
                             oos.close();
                        return the reponse to the client
                   ObjectInputStream ois=null;
                   try{
    \\this is the line where i m getting the error               
    ois = new ObjectInputStream(conn.getInputStream());
                             return (Serializable)ois.readObject();
                        catch(Exception ee){
                                            System.out.println("Error in Object Client inputstream ");
                                            ee.printStackTrace();
                                            return null;
                        finally{
                             if(ois!=null){
                                  ois.close();

    Did anyone find a fix to this problem. I am having a similiar problem. Sometimes I receive an EOFException and othertimes I don't. When I do receive an EOFException I check for available() in the stream and it appears 0 bytes were sent to the Servlet from the Applet.
    I am always open to produce this problem when I use File->New in IE my applet loads on the new page.. and then I navigate to a JSP sitting on the same application server. When I go to the Applet on the initial page and try to send an object to the server I get an EOFException. No idea!

  • Mini-DVI to DVI Adapter issues (2 different types, no info from Apple)

    as you can see below, I have an iBook G4 1.2GHz
    three weeks ago I got a Mini-DVI to Video Adapter
    there were two different types in the Apple Store because there are two generations of Mini-DVI outputs, therefore some close inspection and it was easy to get the right part.
    Now, three weeks later, all that stuff is off the shelf so it looks like they only have up the more recent size plug. Thus, I cannot find the slightly smaller Mini-DVI to DVI Adapter. (typical Apple, probably just wants me to spend more money on a new machine)
    Anyone have a line on where to buy the older type of adapter?
    be very careful out there. They are pimping the heck out of the newer generations. I'm looking for the older one.
    (if not, I'll probably just stop buying Apple stuff. No need for the headache any more since they are no longer really different products. Just fashion)

    I have both an iBook G4 and a MacBook, which use each of the adaptors you have described. I found the information on the Apple site by identifying the Model iBook I had, Dual USB, and looking at he detailed views of each model to identify the type of 'video output port'. I obtained a '2 input' VGA switch from Tiger Direct to be able to switch my monitor from iBook to MacBook.
    Hope this helps!

  • RFC call to a different system returns data from local system,

    Hi:
    I defined a RFC function and execute against a different system, the data returned is from the local system. The rfc_destination in SM59 works fine. The function works fine in the target system. No errors appear, just the data is not from the remote system.
    Any input will be appreciated.
    Thanks.
    Kamaraj

    Hi,
    For now, it seems u haven't specified the destination properly. the call function statement must be suffixed with the 'destination' addition to make sure that the function call is an RFC and the particular function be executed at the desired destination.

  • Partner Profile type : Receiving Data from an 3rd party sys & Posting IDoc

    Hi all,
    My scenario is Receiving Data from a third party system and sending it to a R3 system as an IDoc...
    It is a B2B scenario.....
    So please tell me what should be my Scheme for the indentifier that i will be mentioning in the sender party...
    Should it be ALE#KU or ALE#LS.........
    it is working fine with ALE#KU...i m getting an error if i define it as ALE#LS......
    Is there an extra setting that should be done for configuring it as ALE#LS or , it is not possible configuring using ALE#LS
    Thanks in Advance,
    Sushil H.

    Hi Sushil,
    I have a similar problem and opened a thread: Unable to convert the sender service ABC_Service to an ALE logical system
    i was able to do it without specifying any identifier ...and mapping the sender information in the message mapping,,,,
    Can you please tell me:
    1) What value you specified in the mapping for sender (was it 3rd party/ PI/ R3)? Did you disable the other fields like RCVPRN/ RCVPOR etc?
    2) Did you make any change in the receiver channel for IDOC (in identifier section)?
    It will be very helpful to me if you reply.
    Thank you,
    Pankaj.

  • Good design choice, different types of customers, from webservice

    Hi, I have thoughts about good design pattern, when doing this:
    You have a webservice where customers coming into your system. The customers are private ones, business ones, and big business types.
    These 3 customer types has different needs, and must have different values like companyname, social security number, etc etc.
    The customer also has some shared types, like customerid, created, updated, etc.
    So what you want to do is to have an interface or an abstract class containing common methods for the customer, then you will create subclasses for the different types.
    I was thinking about creating a factory class and pass in the customer object retreived from the webservice, and in the factory process method create objects on the different subclasses based on what kind of object you get in (private, business, etc).
    So, webservice gets a private customer object, you serialize it and then you pass it into your factory class. And back you get a customer object.
    Now you want to do business logic on the object, storing it to a database, etc.
    So you might still have to create different scenarios based on if its customer type.
    The basic idea is that you want to get the object from webservice, pass it to a factory and get back a customer object which you want to do things with.
    What do you think, what is a good design solution to the problem described?

    To be clear "pattern" has a specific meaning. Your description is a design not a pattern.
    Is the small business one never going to become a big business one?
    Is a big business one never going to become a small business one?
    If the answer to either is yes, then you have one entity with different attributes, not two.
    I have no idea why serialization would matter in this. And your description doesn't explain that either. If you are talking about communication between different boxes then you need a communication layer (and it doesn't appear you are at the level yet where you need to decide the specifics of how that is handled.)
    It is unclear why you would want a factory. But if you just want the experience then you could probably use it.
    Your description isn't nearly complete enough to define how the overall system should behave which is what you seem to be also describing. You need to seperate what the system will do for how it will do it (the design.)

  • What is the different to load date from SBIW and LO(lbwe)

    Hi all experts,
    I am wondering if i need to data to generate reports(infostructure S001) in BW. Can i just only load data in "business content datasources"(SBIW) ->select S001 OR I have to load data from LO.
    What is the different between two (SBIW,LBWE)
    Thank you
    Koala

    Hi Koala,
    After SBIW tcode execution you have a screen where another tcodes are accesible. Including LBWE. Namely, in SBIW screen
    'Data transfer to the SAP Business Information Warehouse/Settings for Application-Specific Datasources (PI)/Logistics/Managing Extract structures/Logistics Extraction Structures Customizing Cockpit' is LBWE tcode!
    As I already have answered to you
    anyone  experienced data load for S001?
    You need to choose between LIS extraction and LO extraction, not between SBIW and LBWE.
    BTW, managing LIS setup is situated in SBIW also:
    ...Logistics/Managing transfer information structures/Application-Specific setup of statistical data.
    Best regards,
    Eugene

  • Send a purchase requisition data From APO to SNC

    Hi ,
    Is it possible to send requisition data from APO  to SNC and any  internal integration is there.
    Any Standard way or method or FM  to send the Purchase requisition details from APO to SNC.
    Thanks.

    Hi ,
    Is it possible to send requisition data from APO  to SNC and any  internal integration is there.
    Any Standard way or method or FM  to send the Purchase requisition details from APO to SNC.
    Thanks.

Maybe you are looking for