Using the built-in jetty to create a web interface

I am new to web development and using the built-in jetty. The source code below is developed using the eclipse IDE. I have to start the berth server programmatically, I have no way to start it through the command line. It should be a very lightweight web interface since it will be launched from a system with a low memory / processing speed.

I developed the following directory structure in ECLIPSE

  JettyExample <Project>
    src 
     sample_package
        HelloWorld.java
     WEB-INF
      index.html
      web.xml

Source Code HelloWorld.java

 public static void main(String[] args) throws Exception
{

    Server server = new Server(8080);
    ResourceHandler resource_handler = new ResourceHandler();
    resource_handler.setDirectoriesListed(true);
    resource_handler.setResourceBase(args.length == 2?args[1]:".");
    resource_handler.setWelcomeFiles(new String[]{ "WEB-INF/index.html" });


    System.out.println("serving " + resource_handler.getBaseResource());

    HandlerList handlers = new HandlerList();
    handlers.setHandlers(new Handler[] { resource_handler, new DefaultHandler() });
    server.setHandler(handlers);
    server.start();
    server.join();

}

index.html

 <html>
<head>
    <title>HTML Generator Sample Page</title>
</head>
<body>
    <h1 style="text-align: center;">
        Agent Management Interface</h1>
    <ol>
        <li>
            Start Platform</li>
        <li>
            Show Agent Status</li>
        <li>
            Create Dummy Agent</li>
        <li>
            Intiate Request Message</li>
        <li>
            Stop agent</li>
        <li>
            Stop Platform</li>
    </ol>
    <p>
        Enter option :</p>
    <p>
        <textarea cols="10" name="myTextBox" rows="1" style="width: 104px; height: 25px;"></textarea></p>
    <p>
        <input name="option_selector" type="submit" value="option_selector" /></p>
</body>

The web.xml file is a regular welcome file list. when I start the server and run localhost: 8080 in a web browser, I get a 404 error. I'm not sure if I need to add to the web.xml file or the link to the web.xml file is incorrect in the HelloWorld.java main method.

/ EDIT 1:

server-api.jar jetty.jar Maven eclipse.

EDIT2:

2012-05-25 14:40:39.253:DBUG:oejs.AsyncHttpConnection:async request (null null)@17160330 org.eclipse.jetty.server.Request@105d88a
2012-05-25 14:40:39.260:DBUG:oejs.Server:REQUEST / on   org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection@1db05b2@127.0.0.1:8080<->127.0.0.1:55062
2012-05-25 14:40:39.264:DBUG:oejs.Server:RESPONSE /  200
2012-05-25 14:40:39.267:DBUG:oejs.AsyncHttpConnection:async request (null null)@17160330 org.eclipse.jetty.server.Request@105d88a
2012-05-25 14:40:39.272:DBUG:oejs.AsyncHttpConnection:async request (null null)@17160330 org.eclipse.jetty.server.Request@105d88a
2012-05-25 14:40:39.273:DBUG:oejs.Server:REQUEST /jetty-dir.css on org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection@1db05b2@127.0.0.1:8080<->127.0.0.1:55062
2012-05-25 14:40:39.275:DBUG:oejs.Server:RESPONSE /jetty-dir.css  404
+5
1

WEB-INF/index.html. , WEB-INF, .

, index.html WEB-INF. , WEB-INF , /WEB -INF/file.html:

resource_handler.setWelcomeFiles(new String[]{ "WEB-INF/index.html" });

index.html , , index.html , Jetty Server :

resource_handler.setWelcomeFiles(new String[]{ "index.html" });

Jetty , .

, - , , . , ; , - localhost: 8080 .

, ResourceHandler.setWelcomeFiles Java , web.xml Jetty, XML:

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

"Eclipse Wiki" Embedding Jetty , .

Jetty 6:

Jetty, . , index.html , src:

build.properties*  index.html*  README.textile*  src/   war/
build.xml*         licenses/    server/          test/  WEB-INF/
+2

All Articles