を使用して軽量のWebインターフェイスを作成しようとしています
サーバーをホストするための埋め込み桟橋と、メインページを表示するためのJavaスクリプトを含む単純なhtmlコード。条件によってはページが静的ではないため、Javaコードを呼び出す必要があります。サンプルのhtmlコードは次のとおりです。
<body>
<script type="text/javascript">
function myfunction(frm)
{
var opt=frm.option.value;
alert("option is"+frm.option.value);
// call a java method depending on the value of opt
frm.option.value="";
}
</script>
<h1 style="text-align: center;">Agent Management Interface</h1>
<ol>
</ol>
<form name="management_form">
Enter Option: <input type="text" id="optiontb" name="option">
<input type="button" onclick="myfunction(this.form)" value="submit">
</form>
</body>
</html>
この質問が以前に投稿されたかどうかはわかりませんが、変数をユーザー定義のJavaコードに渡し、戻り値を取得してWebインターフェイスに表示する方法があるのでしょうか。
私は外部ツールを使用しておらず、Eclipseを使用して開発しているので、アプレットを使用することはできません。Webインターフェイスをできるだけ軽量にしたいと思います。
編集2:
以下の提案でhtmlファイルを更新しましたが、これはうまくいかないようです。ハンドラーの記述方法が原因だと思います。ログメッセージは次のとおりです。
2012-05-28 16:02:53.753:DBUG:oejs.AsyncHttpConnection:async request (null null)@16471729 org.eclipse.jetty.server.Request@fb56b1
2012-05-28 16:02:53.754:DBUG:oejs.Server:REQUEST / on org.eclipse.jetty.server.nio.SelectChannelConnector$SelectChannelHttpConnection@bc8e1e@127.0.0.1:8080<->127.0.0.1:47830
2012-05-28 16:02:53.756:DBUG:oejs.Server:RESPONSE / 304
2012-05-28 16:02:53.757:DBUG:oejs.AsyncHttpConnection:async request (null null)@16471729 org.eclipse.jetty.server.Request@fb56b1
ハンドラー用に記述されたコードは次のとおりです
System.setProperty("org.eclipse.jetty.util.log.DEBUG","true");
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[]{ "index.html" });
System.out.println("serving " + resource_handler.getBaseResource());
ContextHandler context0 = new ContextHandler();
context0.setContextPath("/senddata");
Handler handler0=new HelloHandler();
context0.setHandler(handler0);
ContextHandlerCollection contexts = new ContextHandlerCollection();
contexts.setHandlers(new Handler[]{context0});
HandlerCollection handlersc = new HandlerCollection();
handlersc.setHandlers(new Handler[]{resource_handler,new DefaultHandler(), contexts});
server.setHandler(handlersc);
server.start();
server.join();