Return HTML file from JAX-RS service

I am building a web application using the following tools:

  • Jersey 2.14 as a RESTful web service
  • Maven for dependency management
  • Spring 4.1.3 for integrating Redis and MySQL (JDBCTemplate and Spring -data-redis).
  • Tomcat 8 for the server.

Integration with various databases works well, and I managed to create a JAX-RS service that returns simple text or json objects.

For some reason, I cannot return the HTML file from the JAX-RS service. This is the file web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" version="3.1">
    <display-name>insider</display-name>

    <servlet>
        <servlet-name>Jersey REST Service</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.insider</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey REST Service</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
</web-app>

This is my JAX-RS service (which I mistakenly called a “servlet” in the class name):

@Path("/")
public class RoutesServlet {
    @GET
    @Produces("text/html")
    public String index() {
       ...
    }
}

Where should I put static html files? Am I missing something with the configuration?

+4
source share

Source: https://habr.com/ru/post/1569216/


All Articles