2

Sorry for posting basic question but please give me your advise.

I have to write iOS application which communicates with web application deployed on Tomcat server. The web application requires client-app to call the "logon" servlet with username and password to get JSESSIONID. Once client get JSESSIONID, the web application allows to invoke other servlets. But I couldn't figure out how to manage the session to invoke these servlets.

Would you please introduce me the examples/tutorials to learn how to invoke these kind of servlets?

Thank you in advance.

Matty970
  • 21
  • 1
  • 2

2 Answers2

2

Here's a decent example of making an http request from iOS: iOS: How to make a secure HTTPS connection to pass credentials?

There's nothing magic about making the call to a j2ee tomcat server - it's just an HTTP request, so any way you can make an HTTP request will work for you.

Maybe this one too: Can I make POST or GET requests from an iphone application?

edit: ahh, looks like this is the one you want: http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/URLLoadingSystem/Tasks/UsingNSURLConnection.html

Community
  • 1
  • 1
xaxxon
  • 19,189
  • 5
  • 50
  • 80
  • Hi xaxxon, thank you for your quick response! I'll check them. – Matty970 Jan 24 '11 at 05:29
  • Remember, the way you make the call is an HTTP request. The parameters needed are particular to your application - there can't be any documentation telling you how to call your particular service. – xaxxon Jan 24 '11 at 05:47
  • Thank you. I'm still check the documents which you mentioned. As far as I understood, iOS SDK does not provide APIs which treats JSESSIONID issued from webapp, so we have to write code by ourselves, right? – Matty970 Jan 24 '11 at 12:52
  • Yeah, I don't think anything is going to magically take care of your session ID for you. If you found my answer sufficiently helpful and would accept it, I would appreciate it. – xaxxon Jan 24 '11 at 21:02
0

The JSESSIONID is nothing special. If your application is set up to handle cookies coming back from your HTTP request then the JSESSIONID will come back as a cookie in the header. Otherwise you will be issued a redirect to a URL with the JSESSIONID in it. From there, if you handle cookies, the JSESSIONID will be passed automatically with each request with all of the other cookies. Otherwise you'll have to put it into the URL of each request manually.

Download the liveheaders plugin for Firefox and try hitting your servlet with the webbrowser and you can see how the JSESSIONID gets passed around. Next, turn off cookies in Firefox and you can see how it's passed around in the URL and you can see the redirect that Tomcat issues if you watch the headers in liveheaders.

Mason
  • 8,767
  • 10
  • 33
  • 34