Tomcat 显示空白页 - GWT devmode 工作正常
Posted
技术标签:
【中文标题】Tomcat 显示空白页 - GWT devmode 工作正常【英文标题】:Tomcat shows blank page - GWT devmode works fine 【发布时间】:2013-09-07 20:21:12 【问题描述】:我正在 Eclipse 上开发一个 GWT 项目,当我运行开发模式时,一切正常。但是当我在我的 tomcat 服务器上部署 WAR 文件(根据本指南 click 生成)时,http://localhost:8080/myproj/
只显示一个空白页。
我尝试将Window.alert("..")
添加为onModuleLoad()
方法的第一行,它确实显示正确。
清除浏览器缓存是没有用的。
服务器启动执行没有问题也没有异常。
我应该怎么做才能解决这个问题?
这是我的入口点类
public class Segnalazioni_Degrado implements EntryPoint
protected static List<Macrocategoria> listaMacrocategorie;
protected static List<Segnalazione> segnalazioniAttiveCached = new ArrayList<Segnalazione>();
protected static List<SegnalazioneRisolta> segnalazioniRisolteCached = new ArrayList<SegnalazioneRisolta>();
protected static final DataLayerServiceAsync dataLayerService = GWT
.create(DataLayerService.class);
protected static final LoginServiceAsync loginService = GWT
.create(LoginService.class);
protected static final MailServiceAsync mailService = GWT
.create(MailService.class);
protected static Properties props;
private final String TITOLO = "PORTALE SEGNALAZIONI DEGRADO";
private LatLng romaLatLng;
private DockLayoutPanel mainPnl;
private HorizontalPanel northPnl;
private HorizontalPanel southPnl;
private VerticalPanel westPnl;
private AbsolutePanel centerPnl;
protected static StatsPanel statsPnl;
protected static MenuPanel menuPnl;
protected static LoginPanel loginPnl;
protected static LegendPanel legendPnl;
protected static MapWidget map;
private Label titoloLbl;
private/* Button */FocusWidget areaRiservataBtn;
private Button followUsOnTwitterBtn;
private html mailto;
/**
* TODO tweet segnalazione inserita o risolta, porta su .css tutto il
* possibile, prendi tutto da config, fai log su server, crea mail, leggenda
* icone, elimina file foto non solo link
*/
public void onModuleLoad()
loadProps();
buildUI();
void loadProps()
props.set("scarsa manutenzione manto stradale", "images/red.png");
props.set("veicolo abbandonato", "images/red.png");
props.set("discarica abusiva", "images/green.png");
props.set("accumulo spazzatura", "images/green.png");
void buildUI()
Maps.loadMapsApi("", "2", false, new Runnable()
public void run()
buildHomePage();
);
private void buildHomePage()
mainPnl = new DockLayoutPanel(Unit.PCT);
mainPnl.setStyleName("mainPanel");
northPnl = new HorizontalPanel();
northPnl.setStyleName("northPanel");
southPnl = new HorizontalPanel();
southPnl.setStyleName("southPanel");
westPnl = new VerticalPanel();
westPnl.setStyleName("westPanel");
centerPnl = new AbsolutePanel();
centerPnl.setStyleName("centerPnl");
loginPnl = new LoginPanel();
statsPnl = new StatsPanel();
menuPnl = new MenuPanel();
Segnalazioni_Degrado.dataLayerService
.getListaMacrocategorie(new AsyncCallback<List<Macrocategoria>>()
@Override
public void onFailure(Throwable caught)
caught.printStackTrace();
@Override
public void onSuccess(List<Macrocategoria> result)
Segnalazioni_Degrado.listaMacrocategorie = result;
centerPnl.add(new LegendPanel());
);
/**
* costruisco la Google Map
*/
Size mapSize = Size.newInstance(500, 500);
MapOptions mapOpts = MapOptions.newInstance();
mapOpts.setSize(mapSize);
romaLatLng = LatLng.newInstance(41.8902624, 12.4923096);
map = new MapWidget(romaLatLng, 12, mapOpts);
map.checkResizeAndCenter();
map.setSize("99%", "99%");
map.addControl(new LargeMapControl());
map.setDoubleClickZoom(true);
map.setScrollWheelZoomEnabled(true);
map.setStyleName("map");
/**
* costruisco il titolo del portale
*/
titoloLbl = new Label(TITOLO);
titoloLbl.setStyleName("titolo");
/**
* costruisco bottone per accedere ad area riservata
*/
/* areaRiservataBtn = new Button("Accedi all'area riservata"); */
areaRiservataBtn = new Button("AREA RISERVATA");
areaRiservataBtn.setStyleName("bottomBtn");
areaRiservataBtn.addClickHandler(new ClickHandler()
@Override
public void onClick(ClickEvent event)
new AreaRiservataDialog();
);
/**
* costruisco bottone twitter
*/
followUsOnTwitterBtn = new Button();
followUsOnTwitterBtn.addStyleName("bottomBtn");
followUsOnTwitterBtn.addStyleName("twitter");
followUsOnTwitterBtn
.getElement()
.appendChild(
new HTML(
"<div><img src=images/twitter.gif><b>segui @stop_degrado</b></div>")
.getElement());
followUsOnTwitterBtn.addClickHandler(new ClickHandler()
@Override
public void onClick(ClickEvent event)
Window.open("https://twitter.com/stop_degrado", "_blank", "");
);
/**
* costruisco bottone mailto
*/
mailto = new HTML("<a href=mailto:dummy@fake.foo> Contattaci </a>");
mailto.setStyleName("bottomBtn");
/**
* creo bottone ABOUT US
*/
Button aboutus = new Button("ABOUT US");
aboutus.setStyleName("bottomBtn");
aboutus.addClickHandler(new ClickHandler()
@Override
public void onClick(ClickEvent event)
new AboutUsPopup();
);
northPnl.add(titoloLbl);
northPnl.add(loginPnl);
westPnl.add(menuPnl);
westPnl.add(statsPnl);
southPnl.add(followUsOnTwitterBtn);
southPnl.add(aboutus);
southPnl.add(areaRiservataBtn);
southPnl.add(mailto);
centerPnl.add(map);
mainPnl.addNorth(northPnl, 8);
mainPnl.addWest(westPnl, 30);
mainPnl.addSouth(southPnl, 3.5);
mainPnl.add(centerPnl);
RootLayoutPanel.get().add(mainPnl);
MenuPanel.refreshBtn.click();
【问题讨论】:
尝试激活日志记录:gwtproject.org/doc/latest/DevGuideLogging.html 并检查浏览器的 javascript-console。 @ChristianKuetbach 我不确定应该记录哪些事件..顺便说一句,chrome 似乎可以正确加载 segnalazioni_degrado.nocache.js @ChristianKuetbach 我刚刚注意到 Chrome 上的控制台显示 Uncaught TypeError: Cannot call method 'zd' of null 这意味着你有一个 NullPointer。尝试在 DETAILED 中编译。这将保留方法的变量名称。也许你会很幸运并得到正确的代码。奇怪的是,你在 DevMode 中没有问题。 【参考方案1】:我认为是NullPointer
:
protected static Properties props; // << NULL
public void onModuleLoad()
loadProps(); // props is still NULL
buildUI();
void loadProps()
// props is still NULL
props.set("scarsa manutenzione manto stradale", "images/red.png"); // BANG!
[...]
顺便说一句:
你为什么把props
设为静态?您的入口点只有一个实例。所以不能共享任何状态。
【讨论】:
你是对的,非常感谢。为什么在开发模式下执行时没有抛出 NullPointerException?找到问题会容易得多.. 我不知道为什么 NPE 没有在 DevMode 中发生。也许你设置了一次 staic 变量并且没有重新启动 DevMode。以上是关于Tomcat 显示空白页 - GWT devmode 工作正常的主要内容,如果未能解决你的问题,请参考以下文章