从 JSP 调用 REST GET 服务

发布于 2024-12-04 14:55:24 字数 174 浏览 1 评论 0原文

我有一个动态设置应用程序页面标题的 JSP。

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

我不想使用 javascript,因为它被用于 extjs 方面。

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.

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

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

发布评论

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

评论(1

≈。彩虹 2024-12-11 14:55:25

为了从 JSP 调用 REST,您可以使用 Apache HTTPClient。完成后,您可以浏览示例以及HTTPClient 教程。 HTTPClient 支持所有 REST API 调用,包括 GET/POST 等。

另请检查以下 HTTPClient 模板以查看如何将 HTTPClient 与 REST 结合使用。您需要从 JSP 中调用类似的代码。

特别是对于 REST GET 服务,您需要从上面链接中的模板中查看以下块


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

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文