0

I want to know whether it is possible to create an Android application to communicate with a session bean and invoke a method. if so can anybody explain how? or else can i invoke that method in the EJB with a JSP/servelet and call the JSP/Servelet with Android clients.. examples are highly appreciate

Thanks !!!

trgraglia
  • 5,083
  • 5
  • 42
  • 74
Keshan
  • 12,589
  • 10
  • 44
  • 71

2 Answers2

2

It is possible to communicate with Servelet in Android using HttpClient, HttpPost and HttpGet classes in android..

Jignesh Dhua
  • 1,431
  • 1
  • 14
  • 30
1

It is in theory relatively simple. Servlets can be configured by web.xml or @WebServlet annotation to get executed on a certain request URL. On a HTTP GET request the doGet() method will be executed. On a HTTP POST request, the doPost() method will be executed. The business logic which the servlet executes can depend/rely on the presence of HTTP request parameters and/or the request URI pathinfo.

All you need to do is to fire a HTTP request with the right URL and/or the right request parameters and/or the right pathinfo to let the servlet execute the desired job.

The basic Java API offers the java.net.URL and java.net.URLConnection for this. A simple HTTP GET request can be executed as follows:

InputStream response = new URL("http://example.com/servleturl?foo=bar&bar=foo").openStream();
// ...

Firing HTTP POST requests is a bit more complex. It can be done with java.net.URLConnection as outlined in this mini-tutorial, but Android also ships with Apache HttpComponents Client which allows firing and handling HTTP requests with less lines of code and more self-explaining code.

On http://androidsnippets.org you can find a lot of examples with HttpClient.

Community
  • 1
  • 1
BalusC
  • 992,635
  • 352
  • 3,478
  • 3,452