You're using a servlet to serve a welcome file instead of serving a static file. There is some ambiguity in the servlet spec around serving of welcome files, and jetty's default mode looks for a static resource. There are other configuration modes that will let you serve from the servlet without any associated static resource - I think it's "exact" mode on the DefaultServlet, but check the jetty doco for the correct setting:
https://www.eclipse.org/jetty/documentation/jetty-9/index.html#default-servlet On Fri, 26 Mar 2021, 06:37 Som Lima, <[email protected]> wrote: > Something rather strange and unexpected just happened. > > I put back the index.html file and now the contents of the java servlet > class is being published to the browser. > > The contents of index.html file is being overridden > > Even a completely empty files called index.html does the trick. > > > > On Thu, 25 Mar 2021, 17:15 Simone Bordet, <[email protected]> wrote: > >> Hi, >> >> On Thu, Mar 25, 2021 at 4:04 PM Som Lima <[email protected]> wrote: >> > >> > >> > If I do not have web.xml in the aforementioned project >> > and I have a java class annotated with @WebServlet and also decorated >> with urlPattern={"/index.html"} >> > I am getting a 500 Errors with localhost:8080/ >> > >> > The java class as servlet is published in browser with the url >> localhost:8080/index.html >> > >> > Is there anyway to get this java class as servlet to be picked up >> > because I feel the servlet should be registered with the servlet >> container and should return >> > on localhost:8080/ same as src/mainwebapp/index.html >> src/mainwebapp/index.jsp files. >> > >> > @WebServlet(name="indexServlet", urlPatterns={"/index.html"}) >> > public class IndexServlet extends HttpServlet { >> > >> > private static final long serialVersionUID = 1L; >> > >> > protected void doGet(HttpServletRequest request, >> HttpServletResponse response) >> > throws ServletException, IOException { >> > >> > response.setContentType("text/html"); >> > PrintWriter out=response.getWriter(); >> > >> > out.print("<html><body>"); >> > out.print("<h3>Hello Index Servlet</h3>"); >> > out.print("</body></html>"); >> > } >> > } >> > >> > >> > HTTP ERROR 500 java.lang.ClassCastException: class [Ljava.lang.Object; >> cannot be cast to class [Ljava.lang.String; ([Ljava.lang.Object; and >> [Ljava.lang.String; are in module java.base of loader 'bootstrap') >> > >> > URI:/ >> > STATUS:500 >> > MESSAGE:java.lang.ClassCastException: class [Ljava.lang.Object; cannot >> be cast to class [Ljava.lang.String; ([Ljava.lang.Object; and >> [Ljava.lang.String; are in module java.base of loader 'bootstrap') >> > SERVLET:default >> > CAUSED BY:java.lang.ClassCastException: class [Ljava.lang.Object; >> cannot be cast to class [Ljava.lang.String; ([Ljava.lang.Object; and >> [Ljava.lang.String; are in module java.base of loader 'bootstrap') >> > >> > Caused by: >> > >> > java.lang.ClassCastException: class [Ljava.lang.Object; cannot be cast >> to class [Ljava.lang.String; ([Ljava.lang.Object; and [Ljava.lang.String; >> are in module java.base of loader 'bootstrap') >> > at >> org.eclipse.jetty.util.resource.ResourceCollection.list(ResourceCollection.java:426) >> > at >> org.eclipse.jetty.util.resource.Resource.getListHTML(Resource.java:479) >> > at >> > >> > >> >> Please open an issue with as much information as possible at >> https://github.com/eclipse/jetty.project/issues. >> >> Thanks! >> >> -- >> Simone Bordet >> ---- >> http://cometd.org >> http://webtide.com >> Developer advice, training, services and support >> from the Jetty & CometD experts. >> _______________________________________________ >> jetty-users mailing list >> [email protected] >> To unsubscribe from this list, visit >> https://www.eclipse.org/mailman/listinfo/jetty-users >> > _______________________________________________ > jetty-users mailing list > [email protected] > To unsubscribe from this list, visit > https://www.eclipse.org/mailman/listinfo/jetty-users >
_______________________________________________ jetty-users mailing list [email protected] To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
