I am new to Web Development and JAVA , so sorry if the answer to the questions seems pretty obvious.I am building a website using JAVA backend. For the frontend part I want to work with HTML,CSS and JavaScript and for the backend part I have read that I can build that using something called Spring Boot.Now, I want to know is there anyway I can serve the frontend pages(HTML/CSS/Javascript) using JAVA ? I used to do the same using express in NodeJS but I am pretty clueless on how to do this in JAVA ?
-
2here's a decent example: zetcode.com/springboot/staticKamil Janowski– Kamil Janowski2020-05-10 18:50:20 +00:00Commented May 10, 2020 at 18:50
-
2There are thousands of basic tutorial available on internet e.g. dzone.com/articles/creating-a-web-application-with-spring-bootArvind Kumar Avinash– Arvind Kumar Avinash2020-05-10 18:52:40 +00:00Commented May 10, 2020 at 18:52
3 Answers
for plain html/css/js, just paste all contents under src/main/resources/static folder of spring boot app eg: if you create index.html, keep it in static folder, start springboot app, access http://localhost:8080/index.html, app will be running.
for angular/react apps, you need to use node in development phase, once its prod ready use ng build --prod, paste all contents of dist folder in static folder, it will work.
Hope it helps. sample project https://github.com/souvikbachhar/HotelBooking_Hackerearth
Comments
You can use the classes available in java EE platform to build an back application that handles http request (that kind of class is called controller). Then you can invoke your model classes, and connection to a database thanks to java JPA API. Java EE is usually implemented following the MVC pattern. That patter is a bit old an have a series of disadvantages. Nowadays people use a java framework called spring (Spring boot is a utility that allows you to setup your spring project more easily). This one is usually used with Hibernate (helps you handling O/R mapping and DB connections) and template engine (Like thymeleaf) that allows you to render dinamic html.