Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jetty-users] Embedded Jetty 9 not able to retrieve servlet mapping

Hi,
I am using Jetty 9 in embedded mode (I have installed jetty in lib/jetty folder of my project and added all the jars in lib folder of jetty to build path). I am running my server using main method  which has a resource handler to retrieve a jsp file on server start. This jsp file is a form with method post pointing to a servlet on action submit. I'm using dynamic web module 3.0 and servlet 3.0, the problem is i get 404 error when I click submit on jsp page. I made changes mentioned on jetty website like adding metadata-complete="false" to web app  in web.xml and removed comments for annotations in start.ini of etc/jetty. I understand its a problem with servlet mapping, how to resolve this issue?
Below is code sample : 

web.xml
<?xml version="1.0" encoding="UTF-8"?>
id="WebApp_ID" metadata-complete="false" version="3.0">
<display-name>test_new</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

start.ini

OPTIONS=plus
etc/jetty-plus.xml
OPTIONS=annotations
etc/jetty-annotations.xml

jetty-plus.xml
<Set name="configurationClasses">
              <Array id="plusConfig" type="java.lang.String">
                <Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
                <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
                <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
                 <Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
                <Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
              </Array>
            </Set>

ServerConnector.java

public static void main(String[] args) throws Exception
{
System.out.println("Initializing server...");
final Server server = new Server(8080);
System.out.println("Starting server...");
try
{
ResourceHandler resource_handler = new ResourceHandler();
resource_handler.setDirectoriesListed(true);
resource_handler.setResourceBase(args.length == 2 ? args[1] : ".");
System.out.println(resource_handler.getResourceBase());
resource_handler.setWelcomeFiles(new String[] { "home.jsp" });
System.out.println("serving " + resource_handler.getBaseResource());
HandlerList handlers = new HandlerList();
handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler()});
server.setHandler(handlers);
server.start();
}
catch (Exception e)
{
System.out.println("Failed to start server!");
return;
}

System.out.println("Server running...");
while (true)
{
try
{
server.join();
}
catch (InterruptedException e)
{
System.out.println("Server interrupted!");
}
}
}

home.jsp
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Home Page</title>
</head>
<body>
<form action="" method="post">
<input type="text" id="t1">
<input type="submit" id="submit">
</form>
</body>
</html>

MainServlet.java
@WebServlet("/MainServlet")
public class MainServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
       
      public MainServlet() {
        super();
        // TODO Auto-generated constructor stub
    }

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
}
}

Back to the top