有一个简单(棘手)的方法来实现这一点:
将 Main 类设为您的切入点。
<module rename-to='gwt'>
<inherits name='com.google.gwt.user.User'/>
<entry-point class='com.example.client.Main'/>
<source path='client'/>
<source path='shared'/>
</module>;<br/>
创建此 Main.java 以像调度程序一样工作:
package com.example.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.ui.RootPanel;
public class Main implements EntryPoint {
public void onModuleLoad() {
String url = Window.Location.getHref();
if ( url.indexOf("?install")>-1 ) {
Install install = Install.getInstance();
RootPanel.get().add(install);
else if ( url.indexOf("?admin")>-1 ) {
Admin admin = Admin.getInstance();
RootPanel.get().add(admin);
} else {
Application app = Application.getInstance();
RootPanel.get().add(app);
}
}
}
现在,不同的类 Application、Admin 和 Install 像单独的单元一样工作。
这是一个简单的安装示例:
package comexample.client;
import com.google.gwt.user.client.ui.FlowPanel;
import com.google.gwt.user.client.ui.HTML;
public class Install extends FlowPanel {
/** Singleton stuff - to access Main from all subclasses! */
private static Install singelton;
public static Install getInstance() {
if (singelton == null) {singelton = new Install();}
return singelton;
}
/** Constructor - called by Main.onModuleLoad() */
private Install() {
this.add(new HTML("<h1>Do whatever You have to do!</h1>"));
}
}
您不需要 Singleton 的东西 (getInstance),但它在大型应用程序中非常方便。
现在在 /war-directory 中创建名为 install 和 admin 的目录,并在其中创建一个 HTML 页面,如下所示:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="refresh" content="0; URL=/index.html?install">
</head>
<body></body>
</html>
因此,当用户将他的浏览器指向http://www.example.com/install时,他将被重定向到http://www.example.com/index?install并且 index.html 绑定到将调度的 Main.java请求并加载 Install.java