There are no servlets available on your environment.

Some advice:

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

That is overkill.
The while(true) loop is not needed.  as server.join() will wait on the
current thread (in other words, the main() thread in your case) till the
server stops (typically with a Ctrl+C).
Remove that whole block.
Add server.join() on the line after server.start();

ResourceHandler is the most basic and primitive way to serve static content
only.

Do this instead, drop the whole ResourceHandler + DefaultHandler and create
a WebAppContext instead.
Since you obviously have JSP and Servlet 3.0 concepts, this will be the
best choice for you.
You'll need a web.xml (even if its essentially a stub xml).
Then you'll want to specify the appropriate configurations for annotation
based servlets on the WebAppContext.
Finally, configure the DefaultServlet to serve static content. (configuring
the DefaultServlet can be done in the web.xml or via the override
webdefault.xml)

If you want an example of using servlet 3 concepts, like the annotations,
look at the example project.
https://github.com/jetty-project/embedded-servlet-3.0/

Example of the embedded server start:
https://github.com/jetty-project/embedded-servlet-3.0/blob/master/src/test/java/com/company/foo/EmbedMe.java

The stub web.xml that EmbedMe uses:
https://github.com/jetty-project/embedded-servlet-3.0/blob/master/src/main/webapp/WEB-INF/web.xml


--
Joakim Erdfelt <[email protected]>
webtide.com <http://www.webtide.com/>
Developer advice, services and support
from the Jetty & CometD experts
eclipse.org/jetty - cometd.org


On Tue, May 28, 2013 at 10:22 PM, Ranjith Koduri
<[email protected]>wrote:

> Hi,
>
> I'm get HTTP ERROR: 404
> Problem accessing /MainServlet. Reason: Not Found
>
> on submitting home.jsp which I'm accessing through localhost:8080 url. On
> submit the url changes to localhost:8080/MainServlet and gives me the above
> mentioned error
>
> *This is my project's web.xml*
>
> <?xml version="1.0" encoding="UTF-8"?>
> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
> xmlns="http://java.sun.com/xml/ns/javaee"; xmlns:web="
> http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd";
>  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
> http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd";
>  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>
>
> *I'm running Jetty Server in embedded mode using this class
> ServerConnector*
>
> package com.motorolasolutions.atr.server;
>
> import org.eclipse.jetty.server.Handler;
> import org.eclipse.jetty.server.Server;
> import org.eclipse.jetty.server.handler.DefaultHandler;
> import org.eclipse.jetty.server.handler.HandlerList;
> import org.eclipse.jetty.server.handler.ResourceHandler;
> import org.eclipse.jetty.servlet.ServletHandler;
> import org.eclipse.jetty.webapp.WebAppContext;
>
> import com.motorolasolutions.atr.example.HelloHandler;
>
> public class ServerConnector
> {
>  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[] { "WebContent/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!");
>  }
>  }
> }
> }
>
>
> *JSP Form - 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="MainServlet" method="post">
> <input type="text" id="t1">
> <input type="submit" id="submit">
> </form>
> </body>
> </html>
>
>
> *Servlet - MainServlet*
>
> package com.motorolasolutions.atr.example;
>
> import java.io.IOException;
> import javax.servlet.ServletException;
> import javax.servlet.annotation.WebServlet;
> import javax.servlet.http.HttpServlet;
> import javax.servlet.http.HttpServletRequest;
> import javax.servlet.http.HttpServletResponse;
>
> /**
>  * Servlet implementation class MainServlet
>  */
> @WebServlet("/MainServlet")
> public class MainServlet extends HttpServlet {
>  private static final long serialVersionUID = 1L;
>
>     /**
>      * @see HttpServlet#HttpServlet()
>      */
>     public MainServlet() {
>         super();
>         // TODO Auto-generated constructor stub
>     }
>
>  /**
>  * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
> response)
>  */
> protected void doGet(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
>  // TODO Auto-generated method stub
>  }
>
> /**
>  * @see HttpServlet#doPost(HttpServletRequest request,
> HttpServletResponse response)
>  */
> protected void doPost(HttpServletRequest request, HttpServletResponse
> response) throws ServletException, IOException {
>  System.out.println("In Servlet Post Method");
>  }
>
> }
>
>
>
> On Tue, May 28, 2013 at 6:26 PM, Jan Bartel <[email protected]> wrote:
>
>> Ranjith,
>>
>> There's not really enough info in your post to be able to help you. Can
>> you post again and show your embedding code? Also the html form generated
>> by the jsp. Many times 404 errors are caused by servlets not actually being
>> deployed at the mapping path that you think they are ... try hitting the
>> servlet directly.
>>
>> Jan
>>
>>
>> On 29 May 2013 06:21, Ranjith Koduri <[email protected]> wrote:
>>
>>> I've tried using servlet definition without annotations and I still face
>>> the same issue.
>>>
>>> Thanks & Regards,
>>> *Ranjith*
>>> MS-MIS, Univ Of Illinois at Chicago.
>>>
>>>
>>>
>>>
>>>
>>> On Tue, May 28, 2013 at 2:03 PM, Ranjith Koduri <
>>> [email protected]> wrote:
>>>
>>>> Hi,
>>>> I'm trying to post values from a Jsp form to a servlet using embedded
>>>> jetty. I'm using annotations for configuring servlets, unfortunately I'm
>>>> getting a 404 error once I post jsp form to servlet. Is there any working
>>>> example of posting a jsp form to servlet using embedded jetty ?
>>>>
>>>> Thank you.
>>>>
>>>
>>>
>>> _______________________________________________
>>> jetty-users mailing list
>>> [email protected]
>>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>>
>>>
>>
>>
>> --
>> Jan Bartel <[email protected]>
>> www.webtide.com – Developer advice, services and support
>> from the Jetty & CometD experts.
>>
>> _______________________________________________
>> jetty-users mailing list
>> [email protected]
>> https://dev.eclipse.org/mailman/listinfo/jetty-users
>>
>>
>
> _______________________________________________
> jetty-users mailing list
> [email protected]
> https://dev.eclipse.org/mailman/listinfo/jetty-users
>
>
_______________________________________________
jetty-users mailing list
[email protected]
https://dev.eclipse.org/mailman/listinfo/jetty-users

Reply via email to