eclipse GWT:Servlet URL 映射给出 404 错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6657924/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 16:35:19  来源:igfitidea点击:

GWT: Servlet URL mapping gives a 404 error

eclipsegwtservlets

提问by simchona

I have read the other GWT Servlet questions, but I'm having trouble solving my problem still. My package is called Maps, and it has a service named MyService (which was set up according to a GWT Tutorial). The web.xml file includes the following:

我已经阅读了其他 GWT Servlet 问题,但我仍然无法解决我的问题。我的包名为 Maps,它有一个名为 MyService 的服务(根据 GWT 教程设置)。web.xml 文件包括以下内容:

<servlet>
    <servlet-name>MyServiceImpl</servlet-name>
    <servlet-class>com.xerox.maps.maps.server.MyServiceImpl</servlet-class>
</servlet>

<servlet-mapping>
    <servlet-name>MyServiceImpl</servlet-name>
    <url-pattern>/Maps/service</url-pattern>
</servlet-mapping>

In MyService, I have the line:

在 MyService 中,我有一行:

@RemoteServiceRelativePath("service")
public interface MyService extends RemoteService { ...

However, when I try to make an RPC call, there is an error thrown. The details of the error say that it is a 404 HTTP error. How can I fix this, to make sure that the mapping is correct?

但是,当我尝试进行 RPC 调用时,会抛出错误。错误的详细信息说它是 404 HTTP 错误。我该如何解决这个问题,以确保映射正确?

Edit 7.27

编辑 7.27

MyService.java contains the annotation:

MyService.java 包含注释:

@RemoteServiceRelativePath("service")

And web.xml contains:

而 web.xml 包含:

<servlet-name>MyServiceImpl</servlet-name>
<url-pattern>/com.x.maps.Maps/service</url-pattern>

If I follow the XHR with FireBug, it shows me that there is a call to com.x.maps.Maps

如果我使用 FireBug 跟踪 XHR,它会告诉我有一个对 com.x.maps.Maps 的调用

采纳答案by Zasz

404 Not found is thrown usually when service endpoint path is inferred wrongly by GWT. Try removing @RemoteServiceRelativePath("service")and recompile and check, If that does not work find out the URL endpoint of the service manually (by hitting likely paths from a browser till the error changes to 500 internal error) and then give the correct path as argument to @RemoteServiceRelativePath("correct/path"). Few trials I would try right away is @RemoteServiceRelativePath("/Maps/service")and @RemoteServiceRelativePath("Maps/service")without the slash

当 GWT 错误地推断服务端点路径时,通常会抛出 404 Not found。尝试删除@RemoteServiceRelativePath("service")并重新编译并检查,如果这不起作用,手动找出服务的 URL 端点(通过从浏览器点击可能的路径,直到错误更改为 500 内部错误),然后将正确的路径作为参数提供给@RemoteServiceRelativePath("correct/path"). 我会立即尝试的少数试验是@RemoteServiceRelativePath("/Maps/service")并且@RemoteServiceRelativePath("Maps/service")没有斜线

回答by Erel Segal-Halevi

According to this tutorial: https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC

根据本教程:https: //developers.google.com/web-toolkit/doc/latest/tutorial/RPC

The servlet-mapping should be composed of the module "rename-to" and the service "RemoteServiceRelativePath". So, if you have, in your *.gwt.xml file, the following line:

servlet-mapping 应该由模块“rename-to”和服务“RemoteServiceRelativePath”组成。因此,如果您在 *.gwt.xml 文件中有以下行:

<module rename-to='XXX'>

And in your *Service.java file you have the following line:

在您的 *Service.java 文件中,您有以下行:

@RemoteServiceRelativePath("YYY")

Then, in your "web.xml" file, you should have the following lines:

然后,在您的“web.xml”文件中,您应该有以下几行:

  <servlet-mapping>
    <servlet-name>...servlet-name>
    <url-pattern>/XXX/YYY</url-pattern>
  </servlet-mapping>

回答by Zasz

New answer after all the comments :

所有评论后的新答案:

Cool, you have made progress! You are hitting this URL -

酷,你进步了!你正在点击这个网址 -

http://127.0.0.1:8888/com.x.maps.maps.Maps

With this POST data I assume - /%7C98544A4AED8C7D42E80C55859E9CEC4C%7Ccom.x.maps.maps.client.MyService%7CreadFile%7Cjava.lang.String/2004016611%7CPrinterList.xls%7C1%7C2%7C3%7C4%7C1%7C5%7C6%7C

有了这个 POST 数据,我假设 - /%7C98544A4AED8C7D42E80C55859E9CEC4C%7Ccom.x.maps.maps.client.MyService%7CreadFile%7Cjava.lang.String/2004016611%7CPrinterList.xls%7C1%7C2%7C3%7C4%7C1%7C5%7C6%7C

This is where the problem is, your servlet is mapped to respond to XHR requests coming to <url-pattern>/Maps/service</url-pattern>but you are hitting /com.x.maps.maps.Mapsinstead. Hence you are getting the 404 path not found status code.

这就是问题所在,您的 servlet 被映射为响应到达的 XHR 请求,<url-pattern>/Maps/service</url-pattern>但您正在点击/com.x.maps.maps.Maps。因此,您将获得 404 路径未找到状态代码。

Alter the url-pattern on the server-side web.xml to match what the browser is making,
OR
Alter the GWT code using the RemoteServiceRelativePath annotation to make the request to /Maps/service instead of to /com.x.maps.maps.Maps

回答by Javier_ts

I have had the same problem but I solved it changing the url-pattern of the Servlet in the web.xml

我遇到了同样的问题,但我通过更改 web.xml 中 Servlet 的 url-pattern 解决了这个问题

Try to put in your web.xml the path to the directory where your GWT javascript module is generated, behind WEB-INF/deploy. in my case:

尝试将生成 GWT javascript 模块的目录的路径放在 web.xml 中,位于 WEB-INF/deploy 后面。就我而言:

<url-pattern>/gwtmodulemain/selection</url-pattern>

You can also rename your module name in your gwt.xml file:

您还可以在 gwt.xml 文件中重命名模块名称:

<module rename-to='gwtmodulemain'>

so you can refer your module from your HTML in this way:

所以你可以通过这种方式从你的 HTML 引用你的模块:

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

Good luck!

祝你好运!