• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

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

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!