Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Mobile Development
  3. Mobile
  4. rereceive from Servlet to J2ME Using Sessoin

rereceive from Servlet to J2ME Using Sessoin

Scheduled Pinned Locked Moved Mobile
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    williamroma
    wrote on last edited by
    #1

    hi for all (SORRY FOR MY BAD ENGLISH) i am trying to rereceive a number from a Servlet i send the request from J2ME using HttpConnection to a servlet , then a servlet make a session to count the number of times i send the requests and the servlet send back to me that number but in HttpConnection i can send just one times terminated after that third states so every time i send the request the number i received is 1 this is the code in J2ME

    HttpConnection hc = null;
    DataInputStream in = null;
    DataOutputStream out = null;
    String UrlServer = "http://localhost:8080/DeleteWebApplication/RomaServlet";
    StringBuffer sb = new StringBuffer();

    private void sendGetContactsRequest() {
    try {
    UrlServer = "http://localhost:8080/Server2/SessionServlet";
    sb = new StringBuffer();
    hc = (HttpConnection) Connector.open(UrlServer, Connector.READ_WRITE);
    hc.setRequestMethod(HttpConnection.POST);
    out = hc.openDataOutputStream();
    String getContacts = "getContacts";
    byte[] getContactsBytes = getContacts.getBytes();
    for (int i = 0; i < getContactsBytes.length; i++) {
    out.writeByte(getContactsBytes[i]);
    }

            in = hc.openDataInputStream();
            long len = hc.getLength();
            int ch;
            if (len != -1) {
                for (int i = 0; i < len; i++) {
                    if ((ch = in.read()) != -1) {
                        sb.append((char) ch);
                    }
                }
                
                in.close();
                hc.close();
                out.flush();
                out.close();
            } else {
                sb.append("ERRORR R ");
            }
            System.out.println(sb.toString());
        } catch (IOException ex) {
            ex.printStackTrace();
        }
    }
    

    don't care about all the code just about send and receive this is the code in my servlet

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
        System.out.println("he totti asdf asdf asdf asdf ");
        HttpSession session=request.getSession(false);
        if(session==null){
            session=request.getSession(true);
            Integer times=new Integer(0);
            session.setAttribute("count", times);
        }
        Integer times=(Integer) session.getAttri
    
    W 1 Reply Last reply
    0
    • W williamroma

      hi for all (SORRY FOR MY BAD ENGLISH) i am trying to rereceive a number from a Servlet i send the request from J2ME using HttpConnection to a servlet , then a servlet make a session to count the number of times i send the requests and the servlet send back to me that number but in HttpConnection i can send just one times terminated after that third states so every time i send the request the number i received is 1 this is the code in J2ME

      HttpConnection hc = null;
      DataInputStream in = null;
      DataOutputStream out = null;
      String UrlServer = "http://localhost:8080/DeleteWebApplication/RomaServlet";
      StringBuffer sb = new StringBuffer();

      private void sendGetContactsRequest() {
      try {
      UrlServer = "http://localhost:8080/Server2/SessionServlet";
      sb = new StringBuffer();
      hc = (HttpConnection) Connector.open(UrlServer, Connector.READ_WRITE);
      hc.setRequestMethod(HttpConnection.POST);
      out = hc.openDataOutputStream();
      String getContacts = "getContacts";
      byte[] getContactsBytes = getContacts.getBytes();
      for (int i = 0; i < getContactsBytes.length; i++) {
      out.writeByte(getContactsBytes[i]);
      }

              in = hc.openDataInputStream();
              long len = hc.getLength();
              int ch;
              if (len != -1) {
                  for (int i = 0; i < len; i++) {
                      if ((ch = in.read()) != -1) {
                          sb.append((char) ch);
                      }
                  }
                  
                  in.close();
                  hc.close();
                  out.flush();
                  out.close();
              } else {
                  sb.append("ERRORR R ");
              }
              System.out.println(sb.toString());
          } catch (IOException ex) {
              ex.printStackTrace();
          }
      }
      

      don't care about all the code just about send and receive this is the code in my servlet

      protected void processRequest(HttpServletRequest request, HttpServletResponse response)
      throws ServletException, IOException {
          System.out.println("he totti asdf asdf asdf asdf ");
          HttpSession session=request.getSession(false);
          if(session==null){
              session=request.getSession(true);
              Integer times=new Integer(0);
              session.setAttribute("count", times);
          }
          Integer times=(Integer) session.getAttri
      
      W Offline
      W Offline
      williamroma
      wrote on last edited by
      #2

      ty very much i solved the problem using a third class with a STATIC variables

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups