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