Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

sagarshivam

macrumors member
Original poster
May 24, 2011
51
0
Dear All,

I am trying to pass some values (like username and password) from my application to some jsp file lying on some server. And code for this is:
Code:
NSString *post = [NSString stringWithFormat:@"username=%@&password=%@",username, password];	
	NSData *postdata = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
	request= [[[NSMutableURLRequest alloc] init] autorelease];
	[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"http://128.9.45.182:8080/DV_DEMO/jsp/test.jsp"]]];
	[request setHTTPMethod:@"POST"];
	[request setHTTPBody:postdata];
NSURLConnection *conn = [[NSURLConnection alloc] initWithRequest:request delegate:self];

I am also using all the NSURLConnection delegate in the program
And in the jsp file,
Code:
<% 
String username = request.getParameter("username") ;
String password = request.getParameter("password");
out.println(username + password);
%>
And I am getting proper value in the jsp.
But now I want to return back some string to the application.Say after username and password verification, some string should be returned back to the application. How this can be done?
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
Have a look at the overview in the documentation for NSURLConnection. You'll need to implement connection:didReceiveResponse: and connection:didReceiveData: in your NSConnection's delegate.

Alternatively use sendSynchronousRequest:returningResponse:error: on a secondary thread. Grand Central Dispatch is a good mechanism for this.
 

sagarshivam

macrumors member
Original poster
May 24, 2011
51
0
I added further to my code:
Code:
NSURLResponse *response;
	NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:nil];
	NSString *serveroutput= [[NSString alloc]initWithData:data encoding:NSASCIIStringEncoding];
	NSLog(@"serve response is %@", serveroutput);

But in this case I am getting the whole jsp code.
I want some variable's value (say String var defined in jsp).
How is that possible.May ne using httpheaderfield or anything else, I am not aware of it.


Thanks
 

jiminaus

macrumors 65816
Dec 16, 2010
1,449
1
Sydney
If you're getting the JSP code back, then that's what your server is sending back. You can confirm by trying to go the same URL with a browser. This sounds like a configuration error on your server.
 

sagarshivam

macrumors member
Original poster
May 24, 2011
51
0
Thanks a lot!

Actually it was the data, server is sending back. Now I am getting what really I want.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.