RPC调用的Servlet映射

时间:2013-12-09 10:23:00

标签: gwt servlets rpc web.xml

我对GWT编程很陌生,但我已用Java编写了很长时间!

我已经使用RPC调用创建了一个小应用程序,但它不起作用。

当我点击按钮开始通话时,我只在控制台上收到以下消息:

[WARN] 404 - POST /wps_akt/student (127.0.0.1) 1401 bytes
   Request headers
      Host: 127.0.0.1:8888
      Connection: keep-alive
      Accept: */*
      User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/31.0.1650.63 Safari/537.36
      Accept-Encoding: gzip,deflate,sdch
      Accept-Language: de-DE,de;q=0.8,en-US;q=0.6,en;q=0.4
      Content-Length: 137
      X-GWT-Module-Base: http://127.0.0.1:8888/wps_akt/
      X-GWT-Permutation: HostedMode
      Origin: http://127.0.0.1:8888
      Content-Type: text/x-gwt-rpc; charset=UTF-8
      Referer: http://127.0.0.1:8888/Wps_akt.html?gwt.codesvr=127.0.0.1:9997
   Response headers
      Content-Type: text/html; charset=iso-8859-1
      Content-Length: 1401

web.xml如下所示:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
              http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
         version="2.5"
         xmlns="http://java.sun.com/xml/ns/javaee">



  <!-- Servlets -->
    <servlet>
    <servlet-name>StudentServiceImpl</servlet-name>
    <servlet-class>at.htlpinkafeld.wps.server.StudentServiceImpl</servlet-class>
  </servlet>

  <servlet-mapping>
    <servlet-name>StudentServiceImpl</servlet-name>
    <url-pattern>/student</url-pattern>
  </servlet-mapping>


  <!-- Default page to serve -->
  <welcome-file-list>
    <welcome-file>Wps_akt.html</welcome-file>
  </welcome-file-list>

</web-app>

感谢您的帮助 斯蒂芬

1 个答案:

答案 0 :(得分:2)

@RemoteServiceRelativePath中的GWT-RPC路径相对于GWT.getModuleBaseURL(),即GWT生成* .nocache.js和 .cache。文件的文件夹(该文件夹)以您的GWT模块名称或* .gwt.xml文件中的rename-to属性命名。

因此,<servlet-mapping>应使用/wps_akt/student,而不只是/student

如果您想使用/student,那么您必须调整@RemoteServiceRelativePath以阅读"../student"(假设GWT编译器接受它)或明确设置路径(投射您的服务ServiceDefTarget并使用您将servlet映射到的URL调用setServiceEntryPoint