GWT: Servlet URL mapping gives 404 error

I read other GWT Servlet questions, but I have problems resolving my problem. My package is called Maps, and it has a service called MyService (which was configured according to the GWT tutorial). The web.xml file includes the following:

<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 a line:

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

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

Change 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 XHR with FireBug, it shows me that there is a call to com.x.maps.Maps

+6
source share
4 answers

404 Not found, usually occurs when the service endpoint path is erroneously determined by the GWT. Try removing @RemoteServiceRelativePath("service") and recompiling and checking. If this does not work, find out the endpoint of the service URL manually (by hitting probable paths from the browser until the error changes to 500 internal errors), and then enter the correct path as the @RemoteServiceRelativePath("correct/path") argument. The few tests I would try immediately are @RemoteServiceRelativePath("/Maps/service") and @RemoteServiceRelativePath("Maps/service") without a slash

+4
source

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

The servlet mapping should consist of a rename-in module and a RemoteServiceRelativePath service. So, if your * .gwt.xml file has the following line:

 <module rename-to='XXX'> 

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

 @RemoteServiceRelativePath("YYY") 

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

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

New answer after all comments:

Cool, you have made progress! You get to 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

The problem here is that your servlet is mapped to respond to XHR requests coming to <url-pattern>/Maps/service</url-pattern> , but instead you click /com.x.maps.maps.Maps . Therefore, you get a 404 status code that is not found.

 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 
+1
source

I had the same problem, but I decided to change the Servlet url template in web.xml

Try putting in your web.xml the path to the directory in which your GWT Javascript module is created, behind WEB-INF / deploy. in my case:

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

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

 <module rename-to='gwtmodulemain'> 

so that you can reference your module from your HTML as follows:

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

Good luck

+1
source

Source: https://habr.com/ru/post/892541/


All Articles