Call REST GET Service from JSP

半世苍凉 提交于 2019-12-21 17:37:00

问题


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.


回答1:


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);


来源:https://stackoverflow.com/questions/7386058/call-rest-get-service-from-jsp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!