开发者

GWT: Servlet URL mapping gives a 404 error

开发者 https://www.devze.com 2023-03-19 18:59 出处:网络
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 Tuto

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:

<servlet>
    <servlet-name>MyServiceImpl</servlet-name>
    <servlet-class>com.xerox.maps.maps.server.MyServiceImpl</s开发者_如何转开发ervlet-class>
</servlet>

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

In MyService, I have the line:

@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?

Edit 7.27

MyService.java contains the annotation:

@RemoteServiceRelativePath("service")

And web.xml contains:

<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


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


According to this tutorial: 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:

<module rename-to='XXX'>

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

@RemoteServiceRelativePath("YYY")

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

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


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

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.Maps instead. Hence you are getting the 404 path not found status code.

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


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

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:

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

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

<module rename-to='gwtmodulemain'>

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

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

Good luck!

0

精彩评论

暂无评论...
验证码 换一张
取 消