Android app getting data from a third-party JSP & Servlet -
i'm writing android app should data web application. web app based on servlets , jsp, , it's not mine; it's public library's service. elegant way of getting data?
i tried writing own servlet handle requests , responses, can't work. servlet forwarding cannot done, due different contexts, , redirection doesn't work either, since it's post method... mean, sure, can write own form access library's servlet enough, result jsp page.. can turn page string or something? somehow don't think can.. i'm stuck.
can in other way? php or whatever? or maybe jsp page on web server, , somehow extract data (with jquery maybe?) , send android? really don't want display jsp page in browser users, take data , create own objects it..
just send http request programmatically. can use android's builtin httpclient api this. or, bit more low level, java's java.net.urlconnection
(see using java.net.urlconnection fire , handle http requests). both capable of sending get/post requests , retrieving response inputstream
, byte[]
or string
.
at simplest, can perform follows:
inputstream responsebody = new url("http://example.com").openstream(); // ...
a post easier performed httpclient:
list<namevaluepair> params = new arraylist<namevaluepair>(2); params.add(new basicnamevaluepair("name1", "value1")); params.add(new basicnamevaluepair("name2", "value2")); httppost post = new httppost("http://example.com"); post.setentity(new urlencodedformentity(params)); httpclient client = new defaulthttpclient(); httpresponse response = client.execute(post); inputstream responsebody = response.getentity().getcontent(); // ...
if need parse response html (i'd wonder if "public library service" (is public?) doesn't offer xml or json services way easier parse), jsoup may life saver traversing , manipulating html jquery way. supports sending post requests way, not fine grained httpclient.
Comments
Post a Comment