Guice Servlet调用404 Not Found

时间:2013-10-05 05:56:22

标签: java gwt servlets guice

*的 更新 *

刚才意识到我有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”旁边的firebug输出中路径有一个double / in ...可能是问题吗?这会加倍/来自哪里?

感谢您的任何输入!!

* 结束更新 *

我创建了一个应该将String插入网页的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"/>

提前谢谢!

1 个答案:

答案 0 :(得分:0)

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

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

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

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

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