Home Jersey Welcome page not working
Reply: 1

Jersey Welcome page not working

EarlyDev
1#
EarlyDev Published in 2017-12-07 11:17:54Z

I'm having some trouble getting my welcome(index.html) page to display using Jersey. No matter what I try I get a 404.

my App.java

System.out.println( "Hello World!" );
    ResourceConfig config = new ResourceConfig();
    config.packages("co.java.jersey");

    ServletHolder servlet = new ServletHolder(new ServletContainer(config));

    Server server = new Server(2222);
    ServletContextHandler context = new ServletContextHandler(server,"/rest/*");
    context.addServlet(servlet,"/rest/*");

    try{
        server.start();
        server.join();
    }catch (Exception e){

    }
    finally {
        server.destroy();
    }

My web.xml

    <?xml version="1.0" encoding="ISO-8859-1"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
  <display-name>Jersey</display-name>

  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
    <init-param>
      <param-name>com.sun.jersey.config.property.packages</param-name>
      <param-value>co.twoic.licensing.App</param-value>
        <!--<param-value>co.twoic.licensing.EmbeddedServer</param-value>-->
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>

  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

</web-app>

I have tried following this: Welcome page in REST with Java (JAX-RS) using Jersey

My index.html contains more than just basic html so I definitely want my index page used rather than just writing out html.

But when I try localhost:2222 or localhost:2222/index.html I only get a 403 error

Note:very new to java/jetty/jersey Thanks in advance.

EarlyDev
2#
EarlyDev Reply to 2017-12-11 13:33:47Z

Removed welcome file from web.xml and added it in code

ResourceHandler resourceHandler = new ResourceHandler();
        resourceHandler.setWelcomeFiles(new String[] { "index.html" });
        resourceHandler.setResourceBase("src/Web");

setResourceBase was the key to making it work

You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.337244 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO