I am a newbie at web development, and at using embedded jetty. The source code presented below is developed using eclipse IDE. I have to start the jetty server programmtically, I do not have an option of starting it via the command line. It needs to be an extremely light weight web interface as it will be launched from a system with low memory/processing speed.
我在ECLIPSE中制定了以下目录结构:
JettyExample <Project>
src
sample_package
HelloWorld.java
WEB-INF
index.html
web.xml
Hello World.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();
}
索引.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 the usual one with a list of welcome files. when i run the server and launch localhost:8080 in the web browser, I am getting a 404 error I am not sure what is it that I need to add to the web.xml file or the referncing of the web.xml file is not correct in the HelloWorld.java main method.
Any hints/suggestions will be helpful EDIT 1:
我将服务器- api. jar 文件和喷气器. jar 文档纳入类路径, 而不是使用 Maven 插件来日食 。
内容2:
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@[email protected]: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@[email protected]:8080<->127.0.0.1:55062
2012-05-25 14:40:39.275:DBUG:oejs.Server:RESPONSE /jetty-dir.css 404