rereceive from Servlet to J2ME Using Sessoin
-
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
-
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
ty very much i solved the problem using a third class with a STATIC variables