Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Either OR but not Both.


IF I have the web.xml then localhost:8080/myresource  works fine
BUT the index.jsp is not picked  with localhost:8080 or http://localhost/index.jsp
I got an 404.
URI:/
STATUS:404

IF I remove the web.xml then the index.jsp is picked up which is what is meant to happen with jetty because it's built in functionality
assumes an index.jsp file is there and will pick it and publish it.
But the I get a 404 with localhost:8080/myresource  now.
I want both index.jsp to be picked up and have the jersey functionality localhost:8080/myresource with the web.xml
but I can only have one or the other.

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
        version="5.0">

    <servlet>
        <servlet-name>Jersey Web Application</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.example</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
   
   <!-- no effect  -->
    <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    </welcome-file-list>
   
</web-app>


import jakarta.ws.rs.GET;
import jakarta.ws.rs.Path;
import jakarta.ws.rs.Produces;
import jakarta.ws.rs.core.MediaType;

/**
 * Root resource (exposed at "myresource" path)
 */
@Path("myresource")
public class MyResource {

    /**
     * Method handling HTTP GET requests. The returned object will be sent
     * to the client as "text/plain" media type.
     *
     * @return String that will be returned as a text/plain response.
     */
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getIt() {
        return "got, it!";
    }
}



Preferably I also want the Rest API Config to work as well as the index.jsp so that I can call the resource localhost:8080/v1/myresource

import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("v1")
public class RestAppConfig extends Application{
}



Back to the top