通过 iPhone 发送文本到 servlet

发布于 2024-12-28 20:24:34 字数 574 浏览 1 评论 0原文


我想做的是,我正在创建一个非常简单的iPhone应用程序、文本字段和一个按钮,当按下它时,它应该将文本字段中的文本发送到本地托管的servlet(glassfish 3.1.1),并且只是为了确保请求已完成,我输入一个简单的

system.out.println("收到请求");

每次我按下按钮并检查服务器日志时,它都是空的! 我在浏览器中尝试了相同的网址,然后检查日志,日志中显示“收到请求”。

连接到按钮的方法是:
<代码> -(IBAction) connectToServer:(id)sender{ NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]]; NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self]; 我

真的不知道我是否在这里遗漏了任何东西,有什么帮助吗?

what i am trying to do is, i am creating a very simple iphone app, textfield and a button that when pressed it should send the text in the text field to a servlet hosted locally (glass fish 3.1.1) and just to make sure the request is done i type a simple

system.out.println("Request received");

and each time i hit the button and i go to check the server log, it empty !
i tried the same url in the browser then check the log,"Request received" is in the log.

the method connected to the button is:

-(IBAction) connectToServer:(id)sender{
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
}

i really dont know if i am missing any thing here, any help ??

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

情痴 2025-01-04 20:24:34

您尚未启动连接

因此,您的操作方法应如下所示:

- (IBAction)connectToServer:(id)sender {
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    [theConnection start];
}

或者,您可以使用不同的初始值设定项:

- (IBAction)connectToServer:(id)sender {
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
    [NSURLConnection connectionWithRequest:theRequest delegate:self];
}

或者

- (IBAction)connectToServer:(id)sender {
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
    [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
}

You haven't started the connection

So, your action's method should look like:

- (IBAction)connectToServer:(id)sender {
    NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
    NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
    [theConnection start];
}

Or, you may use a different initializer:

- (IBAction)connectToServer:(id)sender {
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
    [NSURLConnection connectionWithRequest:theRequest delegate:self];
}

Or

- (IBAction)connectToServer:(id)sender {
    NSURLRequest *theRequest = [NSURLRequest requestWithURL:[NSURL URLWithString:@"http://localhost:8080/Test/Home"]];
    [[NSURLConnection alloc] initWithRequest:theRequest delegate:self startImmediately:YES];
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文