从JSP调用REST GET服务 [英] Call REST GET Service from JSP
问题描述
但是,我希望能够调用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屋!