[urgent[ Passing object from server to the midlet

I am building a search function for my mobile application..
I created a servlet "SearchServlet.java" that basically send a query to the dbase to retrieve the values in the database.
In this servlet, I store the results in an arraylist..
The servlet works just fine *I've tested it in the browser and accessed it through the local host"..
The concern now is, what if I need to call the servlet from the midlet application..
How to pass the object from the server to the midlet?
Could someone explain to me the mechanism to pass the object?
What object should be the return value in SearchServlet.java?
Thank you very much..

First of all use sober language on forums, its not
your private forum where you can use your abusive
language.And even if it is than its not good manners
to speak in public.Well, quite honestly, my language was not that abusive... I aleady told you that that it's wrong several times... No response on those (at least nothing showing that i would be wrong). And if you keep linking to that code, I find that very anoying.
Second of all. the try catch block sends response
back to J2me app request.Its upto developer whatever
response he wants to send back. There is nothing
wrong in that.No, all it does it declare a string, nothing more, nothing less. No need to catch any exception!
third of all if you think that writeUTF method is
totally wrong, then why dont you show me the
improved solution or correct solution. After all its
forum site, if you know the better solution please
show me rather than always criticising and using
abusive languages.I told you several times that you should read the api docs! It's all in there and you see why you should not read data with readline() when you write that data with writeUTF(). If you fail to do that, and are not capable to learn from that, then that's your own problem. Sure I could show you what it should be (and I beleive I did more than ones), but what does that teach you? Not a lot! Only to keep coming back here and ask more questions that can be found if you take two minutes of time and read docs or search the internet using google or whatever search engine you like (or even the forum search enigne, since that is also rarely used). I'm not talking about you in particular, but about the general level of the questions asked here. 75% of the answers can be found with a little more effort, and in less time than it would take to wait for someone else to come up with an answer.
So please, read what writeUTF() does, and you'll understand what's wrong.
Let me show you:
Writes a string to the underlying output stream using UTF-8 encoding in a machine-independent manner.
First, two bytes are written to the output stream as if by the writeShort method giving the number of bytes to follow. This value is the number of bytes actually written out, not the length of the string. Following the length, each character of the string is output, in sequence, using the UTF-8 encoding for the character. If no exception is thrown, the counter written is incremented by the total number of bytes written to the output stream. This will be at least two plus the length of str, and at most two plus thrice the length of str. What does readline() do? It reads UTF-8 text until some endline character. So it will also read the two length bytes of the wirteUTF method. Is this good? No, it's not. If the lengt is to long, it could even insert extra text characters in the line that should not be there, since readline doesn't know anything about the length bytes, and theats them as normal UTF-8 text.
If you think I dont understand API properly than make
me explain, thats what forums are for...You never said you didn't understand the api docs... I think they are very clear
To end it I really doubt that you are developer/
coder. If you think yourself too perfect please guide
me.I'm not perfect, I'm just putting effort into finding solution myself.
If you are going to continue such an attitude I have
to report to Java forums administrator.I realy don't mind.
Note to original user who posted this message: I am
sorry to write such a comment in your thread, but
"deepspace" user really needs some help.Please, if you want to make a comment, be constuctive. Talking about abusive language... This might be subtle, but it still is abusive! Tell that to all the users I helped already... I bet I'm the most active user here at the moment and I think I helped a whole lot of them very well. Some didn't like my method at first, but in the end, most wil apriciate what I did. I like to let user find out stuff for themselfs, and not give them what they want. They learn much more thay way for sure!

Similar Messages

  • Passing Information From Server to GUI

    Hi, I'm making a chat client, but I'm having trouble passing information from server's input stream to my GUI. I made two threads, one for sending and one for receiving, and I start them both when I click "connect" after I log in to the server. So what happens is I run my program, the frame appears as I want it to, and then I click connect, and after a little wait the button "unclicks" (or w/e) and nothing happens. I don't know why I am not receiving the messages from the server. If I make the program "GUI-less" it works, I can both send and receive messages via the console. But in the GUI, where I am sending/receiving via my two TextAreas, it doesn't work. Here's my code:
    (I apologize ahead of time for posting so much code in a thread, I tried to cut it down as best as I could.)
    actionPerformed method for connect and disconnect buttons (in BotWindow class)
    public void actionPerformed(ActionEvent evt) {
            JButton src = (JButton)evt.getSource();
            if(src == connect) {
                try {
                    bnet = new BattleNet("useast.battle.net");
                    bnet.logIn("dynobot1", "test");
                catch(Exception error) {
                    System.out.println(error);
            if(src == disc) {
                try {
                    BattleNet bnet = new BattleNet("useast.battle.net");
                    bnet.logOut();
                catch(Exception error) {
                    System.out.println(error);
    BattleNet class
    import java.io.*;
    import java.net.*;
    public class BattleNet extends SendAndReceive {
        Socket sock;
        InputStream in;
        OutputStream out;
        Send send;
        Receive receive;
        public BattleNet(String server) {
            try {
                sock = new Socket(server, 6112);
                in = sock.getInputStream();
                out = sock.getOutputStream();
                send = new Send(this.out);
                receive = new Receive(this.in);
            catch(Exception error) {
                System.out.println(error);
        public void logIn(String username, String password) {
            byte[] u = username.getBytes();
            byte[] p = password.getBytes();
            try {
                out.write((byte) 0x03);
                out.write((byte) 0x04);
                out.write(u);
                out.write((byte) 0x0a);
                out.write(p);
                out.write((byte) 0x0a);
                receive.start();
                send.start();
            catch(IOException e) {
                System.out.println(e);
        public void logOut() {
            try {
                sock.close();
                in.close();
                out.close();
            catch(Exception error) {
                System.out.println(error);
    SendAndReceive class (with Threads as subclasses)
    import java.io.*;
    import java.net.*;
    import java.awt.event.*;
    import javax.swing.*;
    public class SendAndReceive implements ActionListener {
        JButton src = null; 
        public SendAndReceive() {} 
        public void actionPerformed(ActionEvent evt) {
            src = (JButton)evt.getSource();
    class Send extends Thread {
        OutputStream out;
        SendAndReceive sr = new SendAndReceive();
        BotWindow bw = new BotWindow();
        public Send(OutputStream inputOut) {
            out = inputOut;
        public void run() {
            if(sr.src == bw.submit) {
                String newLine = "\n";
                String messageOut = bw.inText.getText();
                bw.outText.setText(bw.outText.getText() + newLine + messageOut);
                byte[] m = messageOut.getBytes();
                try {
                    out.write((byte) 0x05);
                    out.write(m);
                catch(IOException e) {
                    System.out.println(e);
                String blank = "";
                bw.inText.setText(blank);
                sr.src = null;
    class Receive extends Thread {
        InputStream in;
        SendAndReceive sr = new SendAndReceive();
        BotWindow bw;
        public Receive(InputStream inputIn) {
            in = inputIn;
            bw = new BotWindow();
        public void run() {
            while(true) {
                try {
                    bw.outText.setText(bw.outText.getText() + (char)in.read());
                catch(IOException e) {
                    System.out.println(e);
    }So, to repeat my questions, SendAndReceive class, but I'm not sure if this is the right approach.why isn't my TextArea (BotWindow.outText) not receiving and setting it's text to the information from the server? Is my threading correct? Also, with the way I set up the threads, will the Send function be able to send in the midst of the receive function? I tried to set it up so that it could by implementing ActionListener in my SendAndReceive class, but I am not sure if this is the correct approach.
    P.S. The reason I put this in Swing is because it works without a GUI/Swing components! If it will help, I will post the GUI-less program I made that works.

    Multi-post. Reply to this posting: http://forum.java.sun.com/thread.jspa?threadID=656211

  • Is it possible to pass variables from Tidal to the Peoplesoft run controls?

    Does anyoen know
    •1) Is it possible to pass variables from Tidal to the Peoplesoft run control page such as current date?
    An example would be updating run control parameters for a PSQUERY.
    •a) From date
    •b) To date
    •c) Business units
    Thanks,
    Jay

    Edit the job - go to Run Controls Parameters tab - select the param you want in the Override column then click on the Variables button on the bottom and select the variable you want

  • How to pass arguments from PAPI to the process

    Can any one tell me How to pass arguments from PAPI to the process.

    The link Creating a new work item instance in a process using PAPI shows how to create instances on PAPI and pass in the variable information as they are being created.
    Provide some additional detail if you're interested in seeing how to pass in variable information using PAPI for scenarios other than instance creation.
    Dan

  • Mail suddenly not being received from server. The ISP tells me there's nothing wrong at his end. I can see emails on the server if I look up WebMail; they don't come into Mail. I haven't changed anything lately.

    Mail suddenly not being received from server. The ISP tells me there's nothing wrong at his end. I can see emails on the server if I look up WebMail; they don't come into Mail. I haven't changed anything lately. The incoming server details haven't changed; the Connection Doctor shows the accounts are connected; I've turned everything off including the modern. Have exhausted my limited knowledge. Anyone with something similar?

    I have decided to dedicate this thread to the wonderful errors of Lion OSX. Each time I find a huge problem with Lion I will make note of it here.
    Today I discovered a new treasure of doggie poop in Lion. No Save As......
    I repeat. No Save As. In text editor I couldn't save the file with a new extension. I finally accomplished this oh so majorly difficult task (because we all know how difficult it should be to save a file with a new extension) by pressing duplicate and then saving a copy of the file with a new extension. Yet then I had to delete the first copy and send it to trash. And of course then I have to secure empty trash because if I have to do this the rest of my mac's life I will be taking up a quarter of percentage of space with duplicate files. So this is the real reason they got rid of Save As: so that it would garble up some extra GB on the ole hard disk.
    So about 20 minutes of my time were wasted while doing my homework and studying for an exam because I had to look up "how to save a file with a new extension in  mac Lion" and then wasted time sitting here and ranting on this forum until someone over at Apple wakes up from their OSX-coma.
    are you freaking kidding me Apple? I mean REALLY?!!!! who the heck designed this?!!! I want to know. I want his or her name and I want to sit down with them and have a long chat. and then I'd probably splash cold water on their face to wake them up.
    I am starting to believe that Apple is Satan.

  • Client unable to get the javax.activation.DataHandler object from Server

    Hi All,
    I am trying to download the file from the server to the client using Javax.Activation.Data Handler object with IBM web services. But server always returning the Data Handler object is null. I am wondering why it is behaving like this.
    My requirement is add the file to the Data Handler object from the server and read the same from the client. But I am always getting Data Handler object is  null at the client place.
    Please see the client side code and server side code below.
    Server side Code:
    This is the simple web service method, its creating the Data Handler object and adding it to the Hash Map and returning the Hash Map object to the client.
    public Hashtable download()
              DataHandler dh = null;
              HashMap hashMap =new HashMap();
              try{
                   //Sample test files contains data
                   String downLoadFName="C:/ADP/downLoadData.txt";
                   //Creating the DataHandler Object with sample file
                   dh      =      new DataHandler(new FileDataSource(new File(downLoadFName)));
                   //Keeping the DataHandler object in the HashMap.
                   hashMap.put("DATAHANDLER",dh);
                   //keeping the sample test message object in the HashMap
                   hashMap.put("TEST","Keeping the DataHandler and test messages in the hashTable");                         
              }catch(Exception e){
                   logger.error("Error :while sending the data:"+e.getMessage(), e);
              //retrun the HashMap object to the client.
              return hashMap;
    Client Side Code:
    This is the simple client code, and connecting to the server and invoking the web service method
    //This is the client code,Just invoking the webservice method from the Webspehre server.
    public class WebserviceClient {
         static DocumentTransfer controller     =     null;
         public static void main(String args[]){     
                DocumentTransferService service          =     null;
              try{
                   //Creating the service Object
                   service               =     new DocumentTransferServiceLocator();
                   //Getting the Server connection
                    controller          =      (DocumentTransfer)service.getDocumentTransfer(new java.net.URL("http://localhost:9081/eNetsRuntimeEngine/services/DocumentTransfer"));
                    //Calling the download method from the server and it returns HashMap object.
                   HashMap hashMap     = controller.download();
                   //Getting the DataHandler Object from the HashMap
                    DataHandler dh=(DataHandler)hashMap.get("DATAHANDLER");
                   System.out.println("DATAHANDLER: :"+dh);
                   //Getting the String object from the HashMap.
                   String message=(String)hashMap.get("TEST");
                   System.out.println(": :"+message);
               }catch(Exception e){
                    System.out.println("Exception :Not able to get the file :"+e.getMessage());
    Could you please give me some inputs on this?
    Thanks in advance,
    Sreeni.

    Hi Stif,
    Thanks for your response.I did debug from server side,it has printing content of Data Handler properly.
    Also i have debug request and response messages using TCP/IP monitor(RAD environment has this feature).The response from the server is going proplery.
    But the client side Data Handler is coming null.
    Any advice or solution would be greatly appreciated.
    Thanks,
    Sreeni.

  • ClassCastException while passing object from one context to another

    I am hoping that someone will bear with me as I think it is my knowledge of classloaders that is tripping me up. I am using Spring and have a SecurityContextImpl object that I want to pass from one web app (WA2) to another web app (WA1). In WA2 I do the following:
    ServletContext wa1Context = getServletContext().getContext("WA1");
    wa1Context.setAttribute("SPRING_SECURITY_CONTEXT" , SecurityContextImpl);WA1 then tries to get the SPRING_SECURITY_CONTEXT and cast it to a SecurityContext object. This is where I get the ClassCastException. I have:
    crossContext="true"in my context.xml fragment. My reading tells me that I may be able to get around this by copying all the spring jars into my Tomcat lib folder but I seem to have to copy so much in there (Spring, hibernate, atomikos etc.) that it does not seem to be a good solution; I gave up before copying all the dependencies it asked for. Is there another way around this problem?
    What I really want to do is find an easy way to copy this one object from WA2 into WA1.

    Thanks for taking the time to test this. I also tried with a String and was successful but still cannot get it to work with my SecurityContextImpl. I also tried passing a String wrapped in a custom bean with a single string property. I get the same ClassCastException. I think that using a String works because it is native to the JVM and somehow bypasses the class loading issue but as I say, my knowledge of classloaders is null.
    Here is the exact code I am running in WA1 and WA2:
    In WA2 (context is /forum):
    ServletContext servletContext = httpRequest.getSession().getServletContext().getContext("/");
    servletContext.setAttribute("SPRING_SECURITY_CONTEXT", httpRequest.getSession().getAttribute("SPRING_SECURITY_CONTEXT"));
    logger.debug("It was of type [" + httpRequest.getSession().getAttribute("SPRING_SECURITY_CONTEXT").getClass().getName() + "]");In WA1 (A JSP sitemesh decorator with context "/"):
    Object object = getServletContext().getAttribute("SPRING_SECURITY_CONTEXT");
    System.out.println("IN DECORATOR, OBJECT IS OF TYPE [" + object.getClass().getName() + "]");
    SecurityContext securityContext = (SecurityContext) object;The log output is:
    DEBUG uk.co.prodia.prosoc.security.spring.cas.login.CheckDecoratorKnowsAboutLogin  - It was of type [org.springframework.security.context.SecurityContextImpl]
    IN DECORATOR, OBJECT2 IS OF TYPE [org.springframework.security.context.SecurityContextImpl]

  • Exception when instantiating Context Object from Server Faces

    Hi guys,
    I am creating a Webproject whereby I uses Java Server Faces (with Sun Creator) to call a Session bean on my business logic layer located on a local weblogic server. The codes I use to look up JNDI is as follows:
    InitialContext initialContext;
    Properties prop = new Properties();
    prop.put(javax.naming.Context.INITIAL_CONTEXT_FACTORY,
              "weblogic.jndi.WLInitialContextFactory");
    prop.put(javax.naming.Context.PROVIDER_URL, "t3://localhost:7001");
    initialContext = new InitialContext(prop);This piece of code works fine when I call from a console application, however, once I shift the codes to the managed bean of my server faces, I get the following exception :
    Description:  An unhandled exception occurred during the execution of the web application. Please review the following stack trace for more information regarding the error.
    Exception Details: javax.faces.FacesException
      #{Login.btn_login_action}: javax.faces.el.EvaluationException: org.omg.CORBA.DATA_CONVERSION: vmcid: SUN minor code: 214 completed: No
    Possible Source of Error:
       Class Name: com.sun.faces.application.ActionListenerImpl
       File Name: ActionListenerImpl.java
       Method Name: processAction
       Line Number: 78 If I comment away this code:
    ' initialContext = new InitialContext(prop);'
    The code will run fine, but of course I will need to instantiate my Context object to look up JNDI. I am not sure if it is because I cannot initiate the Context object within the managed bean of server faces. A search in google does not yield any results too.
    Any inputs are welcome, thnks a lot [:)]

    Hi Bharathwaj,
    I tried using the sharing references:
    PORTAL:sap.com/com.sap.portal.ivs.api_iviewf and
    PORTAL:sap.com/com.sap.portal.pcd.glservice
    both didn't help
    I have 'com.sap.portal.ivs.api_iview_api.jar' under the 'lib' folder.
    Omri

  • Passing Objects from Servlet to Servlet

    Hei,
    how do I pass an object from one servlet to another.. or back to the same again?
    I have my servlet and there I want
    first create an object, then pass that object for processing and manipulating and then pass it for output of the final result..
    How can I send and get the object in a servlet?
    Big thx,
    LoCal

    Hei,
    sorry.. maybe I gave to less informations. In fact it's only one servlet...
    I can't post the original code but something that makes it clear :)
    I wrote the whole project without using Servlet-Technique but normal Java-App. But I designed it so, that I only had to rewrite one class.. and least I thought so.. but now I stuck at this Object-passing problem.
    Sorry.. but I'm pretty new to Servlets
    Thank you very much in advance for your help.
    public class Logger extends HttpServlet {
      private Templates templ = new Templates();
      private Person pers;
      public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
        String uname = req.getParameter("user");
        String pwd = req.getParameter("pwd");
        String sts = req.getStatus
        PrintWriter out = res.getWriter();
        switch(sts) {
          case 1: out.println(templ.getXHTMLEditPers(pers));
          break;
          case 2: out.println(templ.getXHTMLViewPers(pers));
          break;
          case 3: out.println(templ.getXHTMLView(pers));
          break;
          default: out.println(tmpl.getXHTMLLogin());
      public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
      doGet(req, res);     
    }

  • Copy a file from server to the client - URLConnection to a Portal page

    Hello:
    I have an application running on the client side. When the app startup it must open a file which is at the server side, to be more specific, the file is at KM content of the portal.
    I try to read it with URLConnection to copy the file from the server to the client, the app will do it, but "Server returned HTTP response code: 401 for URL:"
    If you copy&paste the url's file directly on the browser (http://host:port/irj/servlet/prt/portal/prtroot/com.sap.km.cm.docs/ImagenesIM/file.txt) a login popup (look and feel windows) is display. After entering the user and psw the file is open without problem.
    Any idea what can I use or how do it ?.
    I think that probably I have to move the app to a was directory instead of portal directory.
    The app is execute via *.jnlp with a link at a portal page.
    Thanks a lot for your time.

    Javier,
    401 means authentication error, i.e. your application is not authenticated to KM.
    What you can do? Actually, it depends. Check current cookies in your application, probably there are SSO coockie or J2EE authentication cookie. You may try to set this cookies in URLConnection (via addHeader). Otherwise you have to supply authentication creadentials to URLConnection (also via addHeader, most probably, via Basic HTTP authentication scheme).
    Valery Silaev
    EPAM Systems
    http://www.NetWeaverTeam.com

  • Oracle BPM 10.3: Pass Object from Presentation to JSP

    Hi,
    I am using Oracle BPM 10.3 . Can anybody tell me that in the presentation when a user clicks a button
    then i call a method. This method have an object. How i can pass this object to a JSP Page so that
    jsp can access this object.
    Thanks
    Edited by: user9293762 on Sep 3, 2010 2:33 AM

    Hi user9293762,
    To pass the BPM object to the JSP page, please follow the below steps:
    1) Place an interactive activity after the method execution.
    2) Right click on the Interactive activity and select Main Task
    3) In the Main Task wizard select Implementation Type as BPM Object Interactive Call
    4) Select the BPM Object Variable, here you can pass your BPM object to the jsp page but make sure that the object you want to pass is an instance variable of type your BPM object
    5) Click on the Use JSP Presentation and choose for your jsp page you want to attach with the interactive activity.
    6) Finally click on OK
    Now you can access the BPM object in your jsp page.
    Bibhu

  • URGENT: Passing Array from JSP to a Stored Procedure

    Hi,
    Can some one please help me understanding how can I pass array from JSP page to a stored procedure in database.
    Thanks in advance.
    Jatinder

    Thanks.
    I tried ArrayExampla.java and was successful in passing array values to the stored database procedure.
    How can I use this class in JSP? Like I have first JSP where in I will collect input from the user and then submit it to the second JSP - that needs to call the ArrayExample.java to pass the values as array to the database.
    How should I call this java code in my second JSP?
    Thanks in advance.

  • Use HTTP Session to pass Object from Web Dynpro for Java to JSP page

    Is it possible to get a handle on the HTTP Session object from within a Web Dynpro application? I want to place a Java object in there that can be retrieved by a JSP page.
    Thanks in advance.

    Hi Tom Cole,
       You can try this. i am not sure if this will work or not.
    HttpServletRequest request = ((IWebContextAdapter) WDWebContextAdapter.getWebContextAdapter()).getHttpServletRequest();
    You can also try this.
    IWDRequest mm_request = WDProtocolAdapter.getProtocolAdapter().getRequestObject();
    HttpServletRequest request = (HttpServletRequest)mm_request.getProtocolRequest();
    IWDRequest basically wraps the HttpServletRequest. if you are using NW04s then the getProtocolRequest() may not be available.
    Regards,
    Sanyev

  • Passing objects from two servlets residing in  two  servers

    Suppose i need to pass an object from one servlet to another servlet ,that are residing in two servers(Tomcat).How can i achieve this.
    Plz help me in this regard.
    Thanks in Advance......

    Serialize them to XML and send as POST parameter

  • Passing reference from server to server

    I have a situation where several distributed servers (RMI servers)need to register themselves with another (one) RMI Server (centralized). How can the centralized server get the reference to the distributed servers without using the naming service. Ideally when the distributed server call some register method on the centralized server at the point the server should be able to find the reference to the distributed server .... somehow .... how ? Can the distributed servers in some way export thier references to the centralized servers ?
    thanks in advance !

    For this to work, the distributed servers need to already have a stub for the central server. At this point, think of them as clients. The stub allows the clients to send messages to the server. One message (or method call, whatever you like), can allow the client to send a stub of itself to the server so long as it extends the UnicastRemoteObject. This way the client can talk to the server and server can talk to the client.
    All you need is an rmiregistry on each client machine and when you launch the client process, part of the startup routine is to export it's stub to the server.

Maybe you are looking for

  • Problem with JSR188 and Application Server 8.2

    Hi there, I'm trying to integrate a CC/PP profile in the SOAP's Header in order to apply adaptation logic in a Web Service. An error occurs when the service tries to validate the client's Profile. To be more specific, when the line: ProfileFactory pf

  • Opening a word doc from HTML in IE

    Hi Guys, In my portal, i have one html page, where there is a link to open a word document, if i click on that link, it is directly showing the content on the html page, rather than asking for whether you want to save that word file or open a file or

  • How to search XML file for specific attributes ...

    Hi, Im trying to design a XML driven billboard. Is there an easy way to seach attributes of all elements using DOM parser and return the element with attribute that matched search criteria?

  • Rollover images not properly aligning in design view

    Hello, I am a self taught Web design teacher and I have seemed to run into an issue with roll-over images as links. I am teaching my students to use photoshop to create two images for rollover buttons. When the students insert the images, everything

  • Reciver JDBC  SAX Error

    Hi All, I am using XSLT mapping to Post Invoices to DB2 using Reciver JDBC Adapter  , I am getting following error : Message processing failed. Cause: com.sap.aii.af.ra.ms.api.RecoverableException: Error processing request in sax parser: Error when e