面向 Java 开发人员的 Ajax: 探索 Google Web Toolkit

http://tech.ddvip.com   2006年11月20日    社区交流

本文详细介绍面向 Java 开发人员的 Ajax: 探索 Google Web Toolkit

  清单 6. 远程 WeatherService 接口和部分实现

public interface WeatherService extends RemoteService {
  /**
  * Return HTML description of weather
  * @param zip zipcode to fetch weather for
  * @param isCelsius true to fetch temperatures in celsius,
  * false for fahrenheit
  * @return HTML description of weather for zipcode area
  */
  public String getWeatherHtml(String zip, boolean isCelsius)
   throws WeatherException;
}
public class YahooWeatherServiceImpl extends RemoteServiceServlet
  implements WeatherService {
  /**
  * Return HTML description of weather
  * @param zip zipcode to fetch weather for
  * @param isCelsius true to fetch temperatures in celsius,
  * false for fahrenheit
  * @return HTML description of weather for zipcode area
  */
  public String getWeatherHtml(String zip, boolean isCelsius)
   throws WeatherException {
   // Clever programming goes here
  }
}

  从这时起,就开始脱离标准的 RMI 方法。因为来自 JavaScript 的 Ajax 调用是异步的,所以需要做些额外的工作来定义客户机代码用来调用服务的异步接口。异步接口的方法签名与远程接口的方法签名有所不同,所以 GWT 要依靠 Magical Coincidental Naming。换句话说,在异步接口和远程接口之间不存在静态的编译时关系,但是 GWT 会通过命名约定来指出该关系。清单 7 显示了WeatherService的异步接口:

来源:ibm    作者:Philip McCarthy    责编:豆豆技术应用

正在加载评论...