java - How to make a servlet interact with the API of a website and also store the XML response? -


protected void doget(httpservletrequest request, httpservletresponse response) throws servletexception, ioexception {     string text = "some text";      response.setcontenttype("text/plain");  // set content type of response jquery knows can expect.     response.setcharacterencoding("utf-8"); // want world domination, huh?     response.getwriter().write(text);       // write response body. } 

if use servlet , request variable have url of api of website . how capture response ? want know code , , right way go when trying build jsp page deals interacting api of website , showing data ?

you're confusing things. httpservletrequest http request client (the webbrowser) has made reach servlet. httpservletresponse response should use send result client (the webbrowser).

if want fire http request programmatically, should use java.net.urlconnection.

urlconnection connection = new url("http://example.com").openconnection(); inputstream input = connection.getinputstream(); // contains response. need convert string or bean , display in jsp. 

see also:


Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -