0

*更新*

刚刚意识到我有 RequestBuilder.PUT 而不是 RequestBuilder.GET ...现在更改该行会给我一个 404 Not Found 错误。这是萤火虫输出:

Response Headerspretty print

HTTP/1.1 404 Not Found

Server: Apache-Coyote/1.1

Content-Type: text/html;charset=utf-8

Content-Length: 999

Date: Sun, 06 Oct 2013 21:23:48 GMT



Request Headerspretty print

GET /a-bcd/abcd//BMDWebUtil HTTP/1.1

Host: xx.xx.xx.xx:8080

User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0

Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8

Accept-Language: en-US,en;q=0.5

Accept-Encoding: gzip, deflate

Content-Type: application/json

Referer: http://xx.xx.xx.xx:8080/a-bcd/

Cookie: JSESSIONID=29CB8485902F8B31A0E237B6689B3118

Authorization: Basic YWxsVXNlcjpwYXNzd29yZA==

Connection: keep-alive

Cache-Control: max-age=0

我猜我有一些路径设置不正确......我确实注意到在“GET”旁边的萤火虫输出中,路径中有一个双/......这可能是问题吗?这个双重/来自哪里?

感谢您的任何意见!

*结束更新*

我创建了一个应该将字符串插入网页的 guice servlet。这是一个非常简单的 servlet。使用 RequestBuilder 调用 servlet 时出现 403 Forbidden 错误。

这是我的 Firebug 输出:

Response Headersview source
Content-Length  961
Content-Type    text/html;charset=utf-8
Date    Sat, 05 Oct 2013 05:34:14 GMT
Server  Apache-Coyote/1.1
Request Headersview source
Accept  text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Encoding gzip, deflate
Accept-Language en-US,en;q=0.5
Authorization   Basic YWxsVXNlcjpwYXNzd29yZA==
Connection  keep-alive
Content-Length  0
Content-Type    application/json
Cookie  JSESSIONID=29CB8485902F8B31A0E237B6689B3118
Host    10.13.36.85:8080
Referer http://10.13.36.85:8080/a-bcd/
User-Agent  Mozilla/5.0 (Windows NT 6.1; WOW64; rv:24.0) Gecko/20100101 Firefox/24.0

BCDWebUtilServlet 类:

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    PrintWriter out = response.getWriter(); 
    try 
        String name= webUtil.getName();

        out.print(classification);
    } finally {
        out.close();
    }
}


@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    PrintWriter out = response.getWriter(); 
    try 
        String name = webUtil.getName();

        out.print(name);
    } finally {
        out.close();
    }    
}

EntryPoint 类:(GWT.getModuleBaseURL() 输出:http://xx.xx.xx.xx:8080/a-bcd/abcd/

@Override
public void onModuleLoad() {
    // This is required for Gwt-Platform proxy's generator
    DelayedBindRegistry.bind(ginjector);        

    ginjector.getPlaceManager().revealCurrentPlace();
    setUpEnv();

}

private void setUpEnv(){
    try {
        Window.alert(GWT.getModuleBaseURL());
        RequestBuilder rb = requestBuilderProvider.get(RequestBuilder.PUT, GWT.getModuleBaseURL() + "/BCDWebUtil");
        rb.sendRequest(null, new RequestCallback() {

            @Override
            public void onResponseReceived(Request request, Response response) {
                if(response.getStatusCode() != 200){
                    // there was an error, add to error display
                    Window.alert("Error");
                }else{
                    classification = response.getText();
                    Window.alert("Success! " + classification);
                }
            }

            @Override
            public void onError(Request request, Throwable exception) {
            }
        });
    } catch (RequestException ex) {
    }
}

ServletModule 类:

serve("/a-bcd/abcd/BCDWebUtil/*").with(BCDWebUtilServlet.class);

.gwt.xml:

<servlet path="/BCDWebUtil" class="com.abcd.server.guice.servlet.BCDWebUtilServlet"/>

先感谢您!

4

1 回答 1

0

我发现我的问题是路径...... ServletModule 类应该是:

serve("/abcd/BCDWebUtil/*").with(BCDWebUtilServlet.class);    

此外,在我的 EntryPoint 文件中创建 RequestBuilder 时,我需要在路径末尾添加一个“/”:

RequestBuilder rb = requestBuilderProvider.get(RequestBuilder.PUT, GWT.getModuleBaseURL() + "/BCDWebUtil/");

我在网上找到了一条提示,说尝试在浏览器中输入不同的 URL 路径,直到出现 500 错误……这就是您需要调用的路径。

于 2013-10-07T06:15:40.193 回答