Reputation: 5
I have a web service with a simple method:
public String action(String name){
return name;
}
And a java application which is the client to the service.
I want to know if it's possible to call the web service from an HTML page (instead of calling it from the client) but having the application listening and receive the result.
I understand when you call a method, it runs from start to finish, I just want to know if something like this is possible.
Some context: I've already done this with a servlet which received a string from an HTML page (AJAX) and sent it through an UDP socket to the listening java application, but I want to do it through HTTP transport.
Any help would be greatly appreciated.
Upvotes: 0
Views: 3492
Reputation: 1336
Ok since you have said "I've already done this with a servlet... " I will assume it is a RESTFul webservice. (SOAP based web service you need to use SOAP Protocol)
To call it from ONLY HTML (No Javascript) you could have a HTML FORM, Make the form method as "GET" action URL as "http://your-server:port/yourService" pass the name as a parameter like /action?name="somename" or a part of URL like /yourService/action/somename and submit it. (This is REST architecture)
For calling it from a JAVASCRIPT read this URL: http://srikanthtechnologies.com/blog/java/rest_service_client.aspx
Upvotes: 0
Reputation: 878
If you use restful it is like this
@GET
@Path("/{name}")
public String action(@PathParam("name") String name){
return "Hello "+name+" !!!";
}
Upvotes: 1