Removing Html Extensions on a Dock

I would like to be able to switch to

https://localhost:8080/users/pages/profile (without server failure) instead of https://localhost:8080/users/pages/profile.html

So i tried

 ServletContextHandler pagesContext = new ServletContextHandler(); pagesContext.setContextPath("/users/pages"); ResourceHandler resourceHandler = new ResourceHandler(); resourceHandler.setResourceBase("./src/main/webapp/pages"); resourceHandler.setDirectoriesListed(true); pagesContext.setHandler(resourceHandler); pagesContext.addServlet(new ServletHolder("default", DefaultServlet.class), "*.html"); // TODO this is not working currently jettyServer.addHandler(pagesContext); 

But it does not work! He complains that the profile page does not exist, but profile.html works fine

+8
java jetty embedded-jetty
source share
3 answers

You can do this by routing the URL. Here is a similar question explaining how to do this: Jetty '{servlet} / {parameter}' URL routing

In a nutshell, you define only a new servlet. (without or with parameter)

+1
source share

From a technical point of view, after packaging the application, there will no longer be a src folder. Usually in eclipse all source files will be compiled and transferred to classes or to the build folder, so change the path from ./src/main/webapp/pages to help you solve the problem.

0
source share

Jetty will not handle this exception. its completely up to the servlet to handle such a url mapping. Why don't you take a look at Spring web mvc, which will make things a lot easier to do what you requested.

Here is a good place to start. Documentation.

0
source share

All Articles