Servlets are the only way to write a Java web application

Are servlets the only way to write web applications in Java?

+4
source share
2 answers

Not. Servlets are the most convenient way to write a web application in Java. If you think about it: what is a web application? This is just an application that can receive an HTTP request and send an HTTP response. Common models for achieving this are:

  • Use some kind of shell that invokes a script for each request. It was the first model and has a standard called CGI (Common Gateway Interface). The wrapper in this case is the web server; or
  • To have a constant code inside such a shell that can serve HTTP requests (and not be temporary, like CGI scripts).

There are variations on this topic (e.g. FastCGI for (1)). Servlets are an example (2). The reason 99% of all Java web applications and frameworks use servlets is because servlets are standard (they have a Sun-approved specification and a reference implementation ) and they are so low-level that almost everything you want can be built on top of them.

+11
source

Servlets are the most convenient way to write Java web applications. They, of course, have been around for a long time, but there are alternatives; look, for example, on restlets: http://www.restlet.org/

0
source

All Articles