durandal durandal - 1 year ago 71
Java Question

Jersey Viewable resulting in 404

I am attempting to create a RESTful web service in Java using Jersey and Tomcat. The problem I am having is that after authenticating a user, I try to return a Response with a Viewable containing the path to my file and I receive a 404 resource not found error.

I have tried every possible path I can think of, including adding multiple copies of map.jsp in the root, WEB-INF and in child folders of WEB-INF. I have also tried omitting the .jsp when returning the Response with the Viewable with no luck.

My folder structure looks like this:

  • Web Pages

    • map.jsp

    • META-INF

      • context.xml

    • WEB-INF

      • map.jsp

      • jsp

        • map.jsp

        • web.xml

The method below is called once authorization is complete. I have verified this by returning the String "hello world" which does display. Here is the code I currently have for my Resource class.

public class WebServiceResource
private static final UserDao USER_DAO = new UserDao();
private static final Logger log = Logger.getLogger(WebServiceResource.class.getName());

public Response getJSP()
log.log(Level.ALL, "getJSP() method: ");
return Response.ok(new Viewable("map.jsp")).build();

Here is my web.xml

<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" version="2.5" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

Answer Source

For anyone experiencing this issue, here's the solution, courtesy of the link provided by peeskillet here. My issue was that I was missing the following dependency, though mine was a different version:


After adding that dependency to my pom everything worked.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download