Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [jetty-users] jersey to jsp: error 500 on index


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 

Regards 




On Thu, 25 Mar 2021, 01:23 Jan Bartel, <janb@xxxxxxxxxxx> wrote:
You do not need to add the welcome files clause to your web.xml. Jetty has a default web.xml file that sets up jsp for you.

I think the issue is that your web.xml file is not targetted at jetty-11, which uses the jakarta.* namespace as Olivier pointed out in a previous post.

Jan

On Thu, 25 Mar 2021 at 11:57, Som Lima <somplasticllc@xxxxxxxxx> wrote:
Sorry you are right. I got confused.
There is a main  class which  came with the archetype. That works when I ran as java application in eclipse IDE with my hack. I think the main class is
invoked for unit tests.

So I just ran mvn exec:java I got an error because I don't have a main class declared in the pom.xml. I have no issue with the error. 

I am running the archetype as 
mvn jetty:run 

I tried adding welcome-file tags  ( see below) in the existing archetype 's web.xml for index.html to be picked up but I am getting a 404.

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
 http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>com.example</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>

On Thu, 25 Mar 2021, 00:15 Jan Bartel, <janb@xxxxxxxxxxx> wrote:
Now I'm confused. You say you're using mvn jetty:run BUT you have posted a java main class where you are configuring and running jetty in embedded mode. Which is it? 

Using mvn jetty:run will run jetty inside maven, and deploy the webapp that is your maven project.  It does not run your main class.

Alternatively, you can write a main class to startup up jetty and deploy your webapp. You then need to ensure that all of the required jetty jars and other dependencies are on the execution classpath. You'd need to use something like the maven exec plugin to run it, or run it manually at the command line in the usual java fashion.

On Thu, 25 Mar 2021 at 10:46, Som Lima <somplasticllc@xxxxxxxxx> wrote:
I used this archetype.

mvn archetype:generate -DarchetypeArtifactId=jersey-heroku-webapp \
                -DarchetypeGroupId=org.glassfish.jersey.archetypes -DinteractiveMode=false \
                -DgroupId=com.example -DartifactId=simple-heroku-webapp -Dpackage=com.example \
                -DarchetypeVersion=3.0.1



running   as  mvn jetty:run


I made this hack by adding a new class
HelloHandler and commenting out the  line server.setHandler(root)
 , which has worked so far but it is just a hack in the existing Main class. I was hoping I can just an index.html but seems to be too good to be true.  I guess I will have to rework the existing Main class. 

//        server.setHandler(root);
          server.setHandler(new HelloHandler());        

public class HelloHandler extends AbstractHandler
{
    public void handle(String target,Request baseRequest,HttpServletRequest request,HttpServletResponse response)
        throws IOException, ServletException
    {
        response.setContentType("text/html;charset=utf-8");
        response.setStatus(HttpServletResponse.SC_OK);
        baseRequest.setHandled(true);
        response.getWriter().println("<h1>Hello World</h1>");
    }
}


public class Main {

    public static void main(String[] args) throws Exception{
        // The port that we should run on can be set into an environment variable
        // Look for that variable and default to 8080 if it isn't there.
        String webPort = System.getenv("PORT");
        if (webPort == null || webPort.isEmpty()) {
            webPort = "8080";
        }

        final Server server = new Server(Integer.valueOf(webPort));
       
        final WebAppContext root = new WebAppContext();

        root.setContextPath("/");
        // Parent loader priority is a class loader setting that Jetty accepts.
        // By default Jetty will behave like most web containers in that it will
        // allow your application to replace non-server libraries that are part of the
        // container. Setting parent loader priority to true changes this behaviour.
        // Read more here: http://wiki.eclipse.org/Jetty/Reference/Jetty_Classloading
        root.setParentLoaderPriority(true);

        final String webappDirLocation = "src/main/webapp/";
        root.setDescriptor(webappDirLocation + "/WEB-INF/web.xml");
        root.setResourceBase(webappDirLocation);

//        server.setHandler(root);
          server.setHandler(new HelloHandler());        
        server.start();
        server.join();
    }
}







On Wed, 24 Mar 2021, 23:13 Jan Bartel, <janb@xxxxxxxxxxx> wrote:
Hi,

How are you running jetty? Are you running in the distribution/embedded/maven plugin? Do you have jsp and it's dependencies enabled?

Making a very simple webapp that is a directory that looks like:

/test
  index.jsp

deploys and runs just fine on the jetty-11 distro, so there must be something else going on with your setup.

Firstly, I would make sure you're using the latest full release version of jetty-11, which is 11.0.1. Then build up from a simple webapp like the one above gradually adding more of your app in until you can see where the problem lies.

regards
Jan

On Thu, 25 Mar 2021 at 09:19, Som Lima <somplasticllc@xxxxxxxxx> wrote:
Hi,

I am using  working on the heroku  archetype   webapp  for  jersey jax-rs
 section 5.1


It is publishing   jax-rs resources.


The archetype seem to have everything 
to be a webapp also , so I thought I just need to drop jsp in the src/main/webapp/index.jsp

Adding welcome-file-list tag and 
welcome-file  tag with index.jsp.
in the web.xml file.

That didn't do the trick.

I got a 404.
running jetty  11.0.0.beta3.

Can you please tell me what  more is needed for the index.jsp to be published 
.

Regards



_______________________________________________
jetty-users mailing list
jetty-users@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/jetty-users


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
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


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
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


--
Jan Bartel <janb@xxxxxxxxxxx>
www.webtide.com
Expert assistance from the creators of Jetty and CometD

_______________________________________________
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