从JSP调用REST GET服务 [英] Call REST GET Service from JSP

查看:227
本文介绍了从JSP调用REST GET服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



但是,我希望能够调用REST服务来获取用户详细信息,它基于系统用户。我已拥有系统用户值,但需要调用后端服务以从数据库中获取详细信息。这已经实现,但我不知道如何设置JSP来执行此操作。

我不想使用javascript,因为它被用于extjs方面。 为了从JSP调用REST,你可以利用 /httpclient-3.x/rel =nofollow> Apache HTTPClient 。一旦你有了,你可以浏览示例以及 HTTPClient教程。 HTTPClient支持所有REST API调用,包括GET / POST等。



还请检查以下HTTPClient模板,以了解HTTPClient如何与REST配合使用。您需要从您的JSP调用类似的代码。



特别是对于REST GET Service,您希望从上面的链接中的模板中查找以下块

  
final HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(),10000);
HttpGet httpget = new HttpGet(SERVER_URL + url);
HttpResponse response = httpClient.execute(httpget);


I have a JSP that dynamically sets the page header of my application.

However, I want to be able to call the REST Service that gets user details based on the system user. I already have the system user value but need to call the backend service to get the details from the database. This is already implemented but I don't know how to setup the JSP to do this.

I do not want to use javascript as this is being used for the extjs side of things.

解决方案

In order to call REST from JSP, you could utilize Apache HTTPClient. Once you have that you could walk through the samples as well as the HTTPClient Tutorial. HTTPClient supports all REST API Call including GET/POST and others.

Check also this following HTTPClient template to see how HTTPClient can be used with REST. You need to call a similar code from your JSP.

In particular to REST GET Service, you want to look the following block from the template in the above link


final HttpClient httpClient = new DefaultHttpClient();
HttpConnectionParams.setConnectionTimeout(httpClient.getParams(), 10000);
HttpGet httpget = new HttpGet(SERVER_URL + url);
HttpResponse response = httpClient.execute(httpget);

这篇关于从JSP调用REST GET服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆