1

I've recently got into Java EE which seems a bit confusing to me so I've tried to figure out how some of the components involved in developing web through Java EE work.

I've noticed that unlike a servlet you don't need to add a tag in web.xml for a WebSocket, instead u use the @ServerEndpoint annotation to map the socket to a URI. Now I see that there is the @Servlet annotation that does kinda the same thing.

So I am curios, those two annotation are doing the same thing, and if so, is it any difference, in the case of a servlet, between using the annotaton or the xml tags ?

Adi Pascu
  • 33
  • 1
  • 7
  • If you're just getting into server-side Java, if possible it's best to skip the low-level pieces and move to a comprehensive environment like Spring MVC or Dropwizard. I haven't set up a new servlet configuration in about 5 years. – chrylis -cautiouslyoptimistic- Apr 23 '18 at 18:04
  • I am aware of that,but thanks for the advice. I've start reading about the server side while learning other stuff and then jumped from tutorial to tutorial :D – Adi Pascu Apr 23 '18 at 18:09
  • The place I suggest to start is the Spring Boot Getting Started Guides. They help focus on the pieces you need to manage to write an application, and then you can explore outwards from there to the infrastructure that you want to understand better. – chrylis -cautiouslyoptimistic- Apr 23 '18 at 19:30
  • You're ultimately asking for the difference between a Websocket and a normal HTTP request. Take a look at [this post](https://stackoverflow.com/questions/14703627/websockets-protocol-vs-http) for a bit more detail there. And yes, you no longer need to have web.xml for most servlet configuration. There are times where it's useful but it isn't required. Websocket support came far after the original servlet support and so it was annotations only. – stdunbar Apr 24 '18 at 19:19

0 Answers0