Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jersey to jsp different welcome file served on different platform

I have just noticed the contents of an archetype  file called Procfile belonging to heroku.
web: java -cp target/classes:target/dependency/* com.example.heroku.Main

I presumed by using an archetype I can focus on the jersey API,
but it appears I will have to do more work than I wanted to if I want to upload my projects. 





On Thu, 25 Mar 2021, 22:05 Jan Bartel, <janb@xxxxxxxxxxx> wrote:
The other thing to consider, if your annotated servlet isn't serving your page was expected when running with jetty configured by your main class, is that you don't have annotation support turned on at all. Have a read of the section of the documentation about annotations.


Jan

On Fri, 26 Mar 2021, 08:47 Som Lima, <somplasticllc@xxxxxxxxx> wrote:
Thank you I will check the documentation.

In the meantime I have found that on the heroku website,
following the git commands in the documentation for uploading, 
The contents of the index.html file  is served.

meanwhile   
mvn jetty:run
localhost:8080
the contents of the servlet are served.
That is very strange !

Previously on the heroku website when I served index.jsp
there was an error message saying JSP is not configured.
Could this behaviour be an indication that somehow  two different versions of jetty are running on different platforms. 


<!--  index.html -->
<html><body>
<h2>Jersey RESTful Web Application!</h2>
<p><a href="" resource</a>
<p>Visit <a href="" href="http://jersey.java.net/" style="text-decoration-line:none;color:rgb(66,133,244)" rel="noreferrer noreferrer" target="_blank">http://jersey.java.net> Project Jersey website</a> more information on Jersey! </p>
<p>contents of index.html </p>
</body></html>


@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("<h2>Jersey RESTful Web Application!</h2>");
        out.print("<p><a href="" resource</a>");
        out.print("<p>Visit <a href="" href="http://jersey.java.net/" style="text-decoration-line:none;color:rgb(66,133,244)" rel="noreferrer noreferrer" target="_blank">http://jersey.java.net> Project Jersey website</a> </p>");
        out.print("more information on Jersey!");
        out.print("<p> contents of servlet Indexservlet </p>");
        out.print("</body></html>");
    }
}


On Thu, 25 Mar 2021, 21:28 Jan Bartel, <janb@xxxxxxxxxxx> wrote:

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:


On Fri, 26 Mar 2021, 06:37 Som Lima, <somplasticllc@xxxxxxxxx> 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, <sbordet@xxxxxxxxxxx> wrote:
Hi,

On Thu, Mar 25, 2021 at 4:04 PM Som Lima <somplasticllc@xxxxxxxxx> 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
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users
_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users

Back to the top