To answer your question, lets ask first what is a web service?
- In purely abstract terms,
A web service is a method of communication between two electronic
devices over the World Wide Web. (Wikipedia)
Now the accepted industry norm for the two devices to communicate over the internet is using XML messages (which makes it inter-operable)
This brings us to different type of web services, mainly divided into SOAP and RESTful.
A SOAP web services use the XML (which conforms the a specific protocol or xml schema which in other words referred as WSDL ). So a SOAP web servies puts certain rules/regulation on the way the messages are exchanged between the web services and their clients. The messages can be exchanged using any convenient protocol apart from HTTP.
Now in a RESTful scenario, you still exchange messages (xml/json etc) BUT there are no new additional specifications (I know WADL but its invented more for providing tooling support RESTful and has nothing to do the RESTful web services per se)
In RESTful, there are no new protocol definition (for exchanging messages). It uses already established norms of HTTP protocol which are passing parameters in URL as path elements and the HTTP methods to send data (namely GET/POST/PUT/DELETE).
Now coming on to your question of whether Servlets are restful web service are not, lets see what Servlets do
- Accept the GET/POST request
- Return an HTML (well generally) (which essentially is XML)
Now if a servlet is written in such a way, that it can be invoked by following URL
http://www.myrestwebservices/services/getstockquote/GOOG
This servlet
is mapped to the URL pattern /services/getstockquote
gets GOOG as input data in URL path, which it can parse, query some system to get the latest stock quote of Google.
Return the data as text/xml to the clients
Isn't this servlet satisfying the following basic requirements of a RESTful scenario ?
Use HTTP methods explicitly
Be stateless.
Expose directory structure-like URIs.
Transfer XML, JavaScript Object Notation (JSON), (text essentially)
So technically speaking, yes a Servlet is a RESTful web services, but that may not be enough for generic business requirement of a web services per se. So for a full blown RESTful web servies, we need a servlet (nevertheless) written specifically to address those basic business requirements.