• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Problem while building session with doPost method (at server side)

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,
I'm implementing Session Handling in MIDP for this i've build application using following reference,

http://developers.sun.com/techtopics/mobility/midp/articles/sessions/

This code work fine for doGet method at server side .But as i want send large data i've change the doGet tp doPost .
With following changes at Client side:

void invokeServlet(String url) throws IOException {
HttpConnection c = null;
InputStream is = null;
OutputStream os = null;
StringBuffer b = new StringBuffer();
TextBox t = null;
try {
c = (HttpConnection)Connector.open(url);
c.setRequestMethod(HttpConnection.POST);
c.setRequestProperty("IF-Modified-Since", "20 Jan 2001 16:19:14 GMT");
c.setRequestProperty("User-Agent","Profile/MIDP-1.0 Configuration/CLDC-1.0");
c.setRequestProperty("Content-Language", "en-CA");

os = c.openOutputStream();
String str = "name="+user;
byte postmsg[] = str.getBytes();
System.out.println("Length: "+str.getBytes());
for(int i=0;i<postmsg.length;i++) {
os.write(postmsg[i]);
}
// or you can easily do:
// os.write(("name="+user).getBytes());
os.flush();

is = c.openDataInputStream();
// sendRequest(url,hc);
if (mSessionIDCookie != null)
c.setRequestProperty("Cookie", mSessionIDCookie);

String cookie = c.getHeaderField("Set-Cookie");
System.out.println("cookie : "+cookie);
if (cookie != null) {
int semicolon = cookie.indexOf(';');
mSessionIDCookie = cookie.substring(0, semicolon);
System.out.println("mSessionIDCookie : "+mSessionIDCookie);
}




int ch;
while ((ch = is.read()) != -1) {
b.append((char) ch);
System.out.print((char)ch);
}
t = new TextBox("Second Servlet", b.toString(), 1024, 0);
t.addCommand(backCommand);
t.setCommandListener(this);
} finally {
if(is!= null) {
is.close();
}
if(os != null) {
os.close();
}
if(c != null) {
c.close();
}
}
display.setCurrent(t);
}

But that doesn't help me?
For doPost method it always created new session id at server side and at Client side it throws IOException ,how could i resolve this issue?
How could i resolve this issue?

Regards,
Sachin Warang.
 
sachin warang
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi friends,

Check out the discussion on this issue,

http://forum.java.sun.com/thread.jspa?messageID=4233772

Regards,
Sachin Warang.
 
You get good luck from rubbing the belly of a tiny ad:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic