2014-01-31 61 views
0

我正在学习在我的web项目中使用gwt,但遇到了一个麻烦。我创建了一个按钮:gwt组件映射问题

public class Example implements EntryPoint 
{ 
    public void onModuleLoad() 
    { 
     Button btnStart = new Button("Start"); 
     RootPanel.get().add(btnStart); 
    } 
} 

在我的web项目的war模块中,并部署到jboss上。要http://localhost:8080/war/后,我看到了什么都没有,除了问候我的example.html的:

<html> 
<head> 
    <title>Example Application</title> 
    <link rel="stylesheet" href="Example.css"> 
</head> 
<body> 
<script type="text/javascript" language="javascript" src="com.tests.gwt.Example.nocache.js"></script> 
<h1>Example Application</h1> 
</body> 
</html> 

有什么麻烦吗?

回答

1

这看起来不正确:

<script type="text/javascript" language="javascript" src="com.tests.gwt.Example.nocache.js"></script> 

我怀疑模块名称丢失:

<script type="text/javascript" language="javascript" src="your_modulename/Example.nocache.js"></script> 

That's how your war should look like

1

你nocache.js处于该com.tests.gwt 。示例目录。

你的脚本SRC必须是:

<script type="text/javascript" language="javascript" src="com.tests.gwt.Example/com.tests.gwt.Example.nocache.js"></script> 

可以在gwt.xml模块文件使用重命名,为简化模块名称:

<module rename-to="example"> 
    <inherits name="com.google.gwt.user.User" /> 
    <entry-point class="com.tests.gwt.Example" /> 
</module> 

script标签将变为:

<script type="text/javascript" language="javascript" src="example/example.nocache.js"></script>