Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-dev] ServletContext.getRealPath("/dir/") returns null


I can't think of a good reason why.  Can you raise a JIRA/bugzilla and we will investigate.

thanks


2011/3/3 Eirik Bjørsnøs <eirbjo@xxxxxxxxx>
Hi,

Is there any reason ServletContext.getRealPath() on a WebAppContext
returns null when a non-existing directory path ends with a "/", but
returns the path where the virtual path "would have beeen" when the
same path does not end with a "/"?

The servlet spec isn't really clear, but only mentions returning null
if the context is served from a war which isn't unpacked.

The following test demonstrates the issue:


   @Test
   public void inconsistentRealPaths() throws Exception {

       // Given
       Server server = new Server(0);
       WebAppContext context = new WebAppContext(".", "/");
       server.setHandler(context);
       server.start();

       // When
       ServletContext ctx = context.getServletContext();


       // Then
       // This passes:
       assertNotNull(ctx.getRealPath("/doesnotexist"));
       // This fails:
       assertNotNull(ctx.getRealPath("/doesnotexist/"));

   }


Thanks,
Eirik.
_______________________________________________
jetty-dev mailing list
jetty-dev@xxxxxxxxxxx
https://dev.eclipse.org/mailman/listinfo/jetty-dev


Back to the top