Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/url/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在GWT应用程序中更改URL?_Java_Url_Gwt - Fatal编程技术网

Java 如何在GWT应用程序中更改URL?

Java 如何在GWT应用程序中更改URL?,java,url,gwt,Java,Url,Gwt,我希望在这个问题上有人能帮我 在GWT中更改页面时,如何更改地址栏内容?(例如:关于Aboutus www.mysite.com/Aboutus) 此外,如果用户在地址栏(www.mysite.com/aboutus)中键入,GWT应用程序是否会将其转发到aboutus页面 谢谢您可以使用它来构建您的web应用程序。应用程序将在位置、视图和活动中组织,视图只包含构建接口的代码,而活动包含视图实际执行的操作。每个地点/活动/视图对应一个URL。对于某些应用程序,这是一种简单方便的组织方式。地址栏是

我希望在这个问题上有人能帮我

在GWT中更改页面时,如何更改地址栏内容?(例如:关于Aboutus www.mysite.com/Aboutus)

此外,如果用户在地址栏(www.mysite.com/aboutus)中键入,GWT应用程序是否会将其转发到aboutus页面


谢谢

您可以使用它来构建您的web应用程序。应用程序将在位置、视图和活动中组织,视图只包含构建接口的代码,而活动包含视图实际执行的操作。每个地点/活动/视图对应一个URL。对于某些应用程序,这是一种简单方便的组织方式。

地址栏是根据您的网页设置的,因此如果您有,请说:
welcome.html
您必须将此脚本放入其中:

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

src attr指的是模块中的条目类(这里的模块是指:
module.gwt.xml
file)

因此,该脚本使用GWT Java EntryClass中编写的逻辑连接html页面

www.mysite.com/aboutus
上代表您的“
aboutus
”的模块,因此,如果您有一个与此模块相关的页面,您可以在以下位置找到它:

www.mysite.com/aboutus/this\u与\u aboutus\u module.html相关

所以这是一对一:一页对一个模块


或多对一:一页多个逻辑中的多个div标记
(如果有)
要指定任何一段代码都将匹配Suiteble div One

您应该使用小部件如下导航:

Anchor nameLink = new Anchor();
nameLink.setText(rec.get("userSeq") + " / " + rec.get("userName"));
nameLink.getElement().setAttribute("style", "padding: 5px;");
String url = GWT.getHostPageBaseURL() + GWT.getModuleName() + ".html";
if (GWT.getHostPageBaseURL().contains("localhost") || GWT.getHostPageBaseURL().contains("127.0.0.1")) {
    url = url + "?gwt.codesvr=127.0.0.1:9997";
}
nameLink.getElement().setAttribute("style", "padding: 10px;");
nameLink.getElement().setAttribute("href", url + "#customer");
并且您的控制器或演示者类应该实现
ValueChangeHandler
,例如

public final void onValueChange(final ValueChangeEvent<String> event) {
String token = event.getValue();

if (token != null) {
    String[] tokens = History.getToken().split(":");
    final String token1 = tokens[0];
    final String token2 = tokens.length > 1 ? tokens[1] : "";

    if (token1.equals("customer")) {

        GWT.runAsync(new RunAsyncCallback() {
            public void onFailure(final Throwable caught) {
            }

            public void onSuccess() {
                CustomerAuctionView view = CustomerAuctionView.getInstance(service);
                CustomerAuctionPresenter presenter = CustomerAuctionPresenter.getInstance(service, eventBus, view);
                presenter.run();
            }
        });
    }
}
在值更改时公开最终作废(最终值更改事件){
字符串标记=event.getValue();
if(令牌!=null){
String[]tokens=History.getToken().split(“:”);
最终字符串标记1=标记[0];
最终字符串token2=tokens.length>1?tokens[1]:“”;
如果(1.等于(“客户”)){
GWT.runAsync(新的RunAsyncCallback(){
失败时公开作废(最终可丢弃){
}
成功时的公共无效(){
CustomerActionView视图=CustomerActionView.getInstance(服务);
CustomerActionPresenter presenter=CustomerActionPresenter.getInstance(服务、事件总线、视图);
presenter.run();
}
});
}
}
您也可以尝试使用

newPageButton.addClickHandler(new ClickHandler() {
    public void onClick(final ClickEvent event) {
        History.newItem("customer");
    }
});

通过
JSNI
,您可以找到
URL

public static native String getURL() 
  /*-{

var x = "URL: " + location.href;
alert(x);


  }-*/;

Window.setLocation(“”)不适合您?我如何在请求和导航中做到这一点?这是否解决了“在GWT中更改页面时如何更改地址栏内容”的问题?回答问题时请小心。我已对您的代码进行了一些格式化,以便其他人可以看到您的建议。您需要将源代码缩进4个空格,否则Stackoverflow无法将其识别为源代码。