Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

send object TO servlet

  • 18-04-2005 03:46PM
    #1
    Closed Accounts Posts: 133 ✭✭


    HI

    I'm fairly new to servlets and I'm struggeling with my code.

    I want to send an arraylist to a servlet from my J2ME application.

    Here is my servlet:
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
                             InputStream is = request.getInputStream();
    
    		ObjectInputStream ois = new ObjectInputStream(is);
    			
    		try {
    			ArrayList arrayList = (ArrayList) ois.readObject();
    			
    		} catch (IOException e) {
    			e.printStackTrace();
    



    Here is the code for my Client application:
    HttpConnection http = null;
    	String url = "http://localhost:8080/BestBet/LoginServlet";
    
    	try
    		{
    			ArrayList ar = new ArrayList();
    			ar.add(userName);
    			ar.add(password);
    			
    			http = (HttpConnection) Connector.open(url, Connector.READ_WRITE);
    			http.setRequestMethod(HttpConnection.POST);
    		
    			ByteArrayOutputStream baos = new ByteArrayOutputStream();
    			ObjectOutputStream os = new ObjectOutputStream(baos);
    			os = new ObjectOutputStream(baos);
    			os.writeObject(ar);
    			
    			if (http.getResponseCode() == HttpConnection.HTTP_OK) {
    				ObjectInputStream ois = new ObjectInputStream(http.openInputStream());
    				returnList = (ArrayList) ois.readObject();
    				ois.close();
    			}
    			http.close();
    		}
    
    	catch (Exception e) {
    			System.out.println (e);
    		}
    	return returnList;
    	}	
    

    I'm guessing that i'm missing some important code.

    At the min the server and client freeze when the
    ObjectInputStream ois = new ObjectInputStream(is);
    lines tries to execute.

    I'd be greatful for any help at all.

    Cheers
    JK


Comments

  • Registered Users, Registered Users 2 Posts: 9 nolaen


    Try converting the ArrayList to a byte array and pass that. Retrieve and convert back


Advertisement