Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

send object TO servlet

Options
  • 18-04-2005 4: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 Posts: 9 nolaen


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


Advertisement