Error 404 on GWT RPC

夙愿已清 提交于 2019-12-12 10:19:54

问题


I've written a quick GWT app with the following code:

MyTaskService

package com.google.gwt.mytasks.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("taskAction")
public interface MyTasksService extends RemoteService {
    public void addTask(String title, String description);
}

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE web-app
    PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
    "http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>

    <!-- Default page to serve -->
    <welcome-file-list>
        <welcome-file>MyTasks.html</welcome-file>
    </welcome-file-list>
    <servlet>
        <servlet-name>MyTasksService</servlet-name>
        <servlet-class>com.google.gwt.mytasks.server.MyTasksServiceImpl</servlet-class>
    </servlet>

    <servlet-mapping>
  <servlet-name>MyTasksService</servlet-name>
  <url-pattern>/mytasks/taskAction</url-pattern>
</servlet-mapping>

</web-app>

Module.gwt.xml

<module rename-to='mytasks'>
    <inherits name="com.google.gwt.user.User"/>
    <inherits name="com.google.gwt.user.theme.standard.Standard"/>
    <entry-point class="com.google.gwt.mytasks.client.MyTasks"/>

<!-- Specify the paths for translatable code                    -->
  <source path='client'/>
  <source path='shared'/>



</module>

Every time I click on the submit button I get the following error:

com.google.gwt.user.client.rpc.StatusCodeException: 404 Error 404 NOT_FOUND

HTTP ERROR: 404

NOT_FOUND

RequestURI=/com.google.gwt.mytasks.MyTasks/taskAction

Powered by Jetty://






















回答1:


The problem seems to be that GWT isn't renaming the module before publishing, i you have a look at RemoteServiceRelativePath annotation documentation it defines the servlet path as GWT.getModuleBaseURL() + value(), being value() the value given to the annotation. One easy solution that might work would be to define the servlet mapping at the path the module is looking at.

Instead of:

<servlet-mapping>
  <servlet-name>MyTasksService</servlet-name>
  <url-pattern>/mytasks/taskAction</url-pattern>
</servlet-mapping>

Use:

<servlet-mapping>
  <servlet-name>MyTasksService</servlet-name>
  <url-pattern>/com.google.gwt.mytasks.MyTasks/taskAction</url-pattern>
</servlet-mapping>


来源:https://stackoverflow.com/questions/9903873/error-404-on-gwt-rpc

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!