Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to configure Jetty Server v12 ee10 for serving multiple static resources in the same base directory? #11791

Closed
Emilyserap opened this issue May 14, 2024 · 5 comments · Fixed by #11799
Labels
Bug For general bugs on Jetty side

Comments

@Emilyserap
Copy link

Emilyserap commented May 14, 2024

Jetty version(s)
12.0.9

Jetty Environment
ee10

Java Version
JavaSE-17

I am working on a web application using Java, and I have configured servlets to serve static resources using ServletHolder and DefaultServlet. Here is the configuration code:

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ResourceFactory resourceFactory = ResourceFactory.of(context);
context.setBaseResource(resourceFactory.newResource(mainResourceBase));
ServletHolder holderAlt = new ServletHolder("static-alt", DefaultServlet.class);
holderAlt.setInitParameter("dirAllowed", "true");
holderAlt.setInitParameter("acceptRanges", "true");
context.addServlet(holderAlt, "*.js");
ServletHolder holderDef = new ServletHolder("default", DefaultServlet.class);
holderDef.setInitParameter("dirAllowed", "true");
context.addServlet(holderDef, "/");

i'm encountering a 404 Not Found error when trying to access static resources ending with .js.
I would appreciate any insights or suggestions to help resolve the issue of static resources returning 404 errors.

@Emilyserap Emilyserap added the Bug For general bugs on Jetty side label May 14, 2024
@Emilyserap Emilyserap changed the title How to configure Jetty Server v12 ee10 to serve Javascript files? How to configure Jetty Server v12 ee10 for serving multiple static resources from a base directory? May 15, 2024
@Emilyserap Emilyserap changed the title How to configure Jetty Server v12 ee10 for serving multiple static resources from a base directory? How to configure Jetty Server v12 ee10 for serving multiple static resources in the same base directory? May 15, 2024
@Emilyserap
Copy link
Author

Are there any limitations for Jetty 12 PathSpecs?

@janbartel
Copy link
Contributor

I think we have a bug in ee10 handling of suffix-mapped DefaultServlet instances. I believe this works in ee9, can you back down to that version?

I've opened issue #11794.

@Emilyserap
Copy link
Author

Emilyserap commented May 16, 2024

Yes, it works in EE9, but I want to know if this bug will be fixed soon in EE10?

janbartel added a commit that referenced this issue May 23, 2024
…#11799)

* Issue #11791 fix suffix mapping for non default DefaultServlet usage.

Co-authored-by: Greg Wilkins <[email protected]>
@Emilyserap
Copy link
Author

Thanks for fixing this issue, but I want to know why when I refresh the dependencies, I don't see the new modification in the class DefaultServlet.java

@Emilyserap
Copy link
Author

I think we have a bug in ee10 handling of suffix-mapped DefaultServlet instances. I believe this works in ee9, can you back down to that version?

I've opened issue #11794.

I think we have a bug in ee10 handling of suffix-mapped DefaultServlet instances. I believe this works in ee9, can you back down to that version?

I've opened issue #11794.

I'm also having the same problem with static resources index.html. I'm not sure if it's a bug in DefaultServlet or a limitation of PathSpecs, but I'd appreciate it if you could take a look into it.

ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
context.setContextPath("/");
ResourceFactory resourceFactory = ResourceFactory.of(context);
context.setBaseResource(resourceFactory.newResource(mainResourceBase));
ServletHolder holderAlt = new ServletHolder("static-alt", DefaultServlet.class);
holderAlt.setInitParameter("dirAllowed", "true");
 holderAlt.setInitParameter("acceptRanges", "true");
context.addServlet(holderAlt, "*.js");
ServletHolder holderstat = new ServletHolder("static", DefaultServlet.class);
holderstat.setInitParameter("dirAllowed", "true");
holderstat setInitParameter("acceptRanges", "true");
holderstat.setInitParameter("cacheControl", "no-store");
context.addServlet(holderstat , "/index.html");
ServletHolder holderDef = new ServletHolder("default", DefaultServlet.class);
holderDef.setInitParameter("dirAllowed", "true");
context.addServlet(holderDef, "/");

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug For general bugs on Jetty side
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants