I recently learned how to use Java, and as a project I am interested in creating a simple backend for a webapp with java to be hosted on heroku. I am planning on the webpages being written in HTML, or possibly React.js. I have started off using Java servlets and Tomcat and am wondering whether there is a better solution.
-
There are thousands of frameworks for all kinds of needs, but the requirements you have expressed are so few that Tomcat+servlet is probably the easiest way to go for you.– Nicolas Raoul ♦Jun 28, 2020 at 8:14
-
@NicolasRaoul isn't that solution a little outdated?– SomeoneJun 29, 2020 at 16:03
-
Your title does not match the body of your Question. Web-servers is a different topic than web-development frameworks.– Basil BourqueJul 12, 2020 at 7:29
1 Answer
You have not provided enough detail for a definite recommendation. But I can give a couple of suggestions.
Plain servlets
If you want very simple pages, and you are willing to write the HTML & CSS yourself, then writing plain servlets yourself is certainly viable. This would also be educational, as many other web app development frameworks are built on top of Jakarta Servlet technology.
Manually writing out HTML & CSS within Java code gets tedious. For better productivity, look to a variety of frameworks you can leverage. Most of these are templating driven.
Vaadin
A different kind of web app development tool is Vaadin. You write in pure Java, declaring your layouts/forms, adding widgets like buttons, fields, pickers, data grids, and more. An runtime, Vaadin automatically generates the HTML & CSS & JavaScript necessary to render that user-interface remotely in the user's web browser. As the user interacts with the UI, such as clicking a button or typing in a field, user events are automatically raised on the server-side for your Java cod to react.
So pure Java on the server-side, pure Web standards code on the client side (no Java on the user machine).
You can write full-blown business-oriented desktop-style web apps without needing to study or master the Web technologies. All you need is Java skills. It helps to know the basics of Servlets, HTML, CSS, and such, but you will not use them day-to-day as a programmer, if at all ever.