Skip to content
Advertisement

How to response with JSP file using JAX-RS?

I’ve just started learning Java. I’m trying to create a simple CRUD web application using JAX-RS. I’d like to have a few pages with forms that will be sending data to my API resources. Unfortunately, I don’t understand how I can render an html page using JAX-RS. Perhaps there is another way to do that?

pom.xml

JavaScript

web.xml

JavaScript

UserResource.java

JavaScript

Advertisement

Answer

I think you are confused with different technologies. If you want to render HTML page then you should use either Servlet JSP or other rendering mechanism, for example, Thymeleaf. JAX-RS is used for REST.

For example, you can render your HTML page on server using JSP/Thymeleaf, when page is loaded in browser, JavaScript will make a REST call to JAX-RS and after getting answer from REST resource it (js) will add data to HTML page.

A full JSP example is here. A full example Spring Boot + Thymeleaf is here. I would suggest to use Thymeleaf.

User contributions licensed under: CC BY-SA
4 People found this is helpful
Advertisement