Should I always use a servlet to work with web applications?

3

I want to create a web application using Java. I have some knowledge of the language, and when searching online tutorials they always mention the creation of a servlet . Is it necessary to learn and use servlets to create these types of applications? Is it possible to create a web application in Java where you do not have to use a servlet at all?

Note: using a framework like Spring , MVC or JSF also requires the use of a servlet, although I do not have to code the servlet on my own. Consider this at the time of the response.

    
asked by Marc 05.12.2015 в 19:21
source

4 answers

4

If you want to avoid the use of Servlets in Java EE, it is impossible, something very different is to develop with Servlets, because although (for example) Spring uses Servlets internally you will no longer need to create servlets.

Along with the new technologies have appeared different frameworks with a more minimalist and less robust approach to what gives Java EE, in this case I can quote Spark Java that is simple framework and similar to what is currently in fashion for development of microservices for web applications, not to be confused with Apache Spark that is related to Big Data.

In theory Spark Java does not need an application server because it uses an embedded one (Jety), something very similar to what SpringBoot does that is supported by all Java EE and uses an embedded tomcat.

link

link

    
answered by 01.09.2016 в 20:19
2

The reason why there are the servlets in the first place is to generate dynamic content to the client.

Initially the client makes a request to the servidor , but this ONLY can provide static content greatly reducing the use of the true web? Servlets are born to help the server provide dynamic content.

The servlet is maintained and lives at the request of contenedor web who is responsible for generating instances of these and to facilitate the use of JSP which are simply servlets that are created by contenedor web . among other things.

Ultimately, a servlet is a program made in java which does not have a main method but contains methods that generate callbacks , and servlets communicate with the server thanks to contenedor web also known as motor de servlets .

    
answered by 05.01.2016 в 03:53
-1

Not necessarily, although your question is too broad, you can use other technologies such as Dukescript , that even if you manage Java for the < em> backend , in the frontend they do not use any class related to the interface Servlet .

In the case of Dukescript , the architecture is essentially client-client, and the binding of the variables is usually done using the knockout API for Java, the frontend implementation being free to any technology and / or framework compatible with Html5 (including css ).

In the case of web applications that use JEE, to use EJB you must have a container server for beans, although you can use template engines instead of Servelets and derivatives for example < a href="http://freemarker.incubator.apache.org/"> Free Marker , Tiles or Velocity .

I also attach an example of with an EntityManager to query a database, in which servlets are obviously not used.

    
answered by 05.12.2015 в 19:35
-1

You can use JSP pages. The JSP pages are like Servlets "backwards", that is, while in the servlets almost everything is in Java and when you want general HTML you print strings with out.println() , in JSP almost everything is HTML and when you want Java logic, you write it inside of special tags.

The JSP pages are compiled, becoming servlets in execution time, but they abstract the programmer from the complications of the servlets.

    
answered by 23.12.2015 в 18:45