GWT-此代码的主要步骤
今天我要在GWT框架上迈出第一步。我需要理解(使用netbeans官方软件了解此应用程序的工作原理:)我放置代码:GWT-此代码的主要步骤,gwt,Gwt,今天我要在GWT框架上迈出第一步。我需要理解(使用netbeans官方软件了解此应用程序的工作原理:)我放置代码: /* * To change this template, choose Tools | Templates * and open the template in the editor. */ package org.yournamehere.client; import com.google.gwt.core.client.EntryPoint; import com.g
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.yournamehere.client;
import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.Label;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Timer;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
* Main entry point.
*
* @author djfonplaz
*/
public class MainEntryPoint implements EntryPoint {
/**
* Creates a new instance of MainEntryPoint
*/
public MainEntryPoint() {
}
public static GWTServiceAsync getService() {
// Create the client proxy. Note that although you are creating the
// service interface proper, you cast the result to the asynchronous
// version of the interface. The cast is always safe because the
// generated proxy implements the asynchronous interface automatically.
return GWT.create(GWTService.class);
}
public void onModuleLoad() {
final Label quoteText = new Label();
Timer timer = new Timer() {
public void run() {
//create an async callback to handle the result:
AsyncCallback callback = new AsyncCallback() {
public void onFailure(Throwable arg0) {
//display error text if we can't get the quote:
quoteText.setText("Failed to get a quote");
}
public void onSuccess(Object result) {
//display the retrieved quote in the label:
quoteText.setText((String) result);
}
};
getService().myMethod(callback);
}
};
timer.scheduleRepeating(1000);
RootPanel.get().add(quoteText);
}
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.yournamehere.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
/**
*
* @author djfonplaz
*/
@RemoteServiceRelativePath("gwtservice")
public interface GWTService extends RemoteService {
public String myMethod();
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.yournamehere.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
/**
*
* @author djfonplaz
*/
public interface GWTServiceAsync {
public void myMethod(AsyncCallback callback);
}
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.yournamehere.server;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import org.yournamehere.client.GWTService;
/**
*
* @author djfonplaz
*/
public class GWTServiceImpl extends RemoteServiceServlet implements GWTService {
private Random randomizer = new Random();
private static final long serialVersionUID = -15020842597334403L;
private static List quotes = new ArrayList();
static {
quotes.add("No great thing is created suddenly - Epictetus");
quotes.add("Well done is better than well said - Ben Franklin");
quotes.add("No wind favors he who has no destined port - Montaigne");
quotes.add("Sometimes even to live is an act of courage - Seneca");
quotes.add("Know thyself - Socrates");
}
public String myMethod() {
return (String) quotes.get(randomizer.nextInt(5));
}
}
因此(或多或少):
如果有人能帮助我,我会非常高兴!cheers文件MainEntryProject.java位于客户端包中,因此它不是servlet,而是由GWT编译为JavaScript的java文件。生成嵌入到HTML文件(welcomeGWT.HTML)中的javascript。 所以
- 首先加载welcomeGWT.html
- 然后浏览器开始执行GWT生成的javascript,该javascript在1000ms后调用服务器方法myMethod
- 最后,服务器返回回调,客户端执行下一个代码:
public void onFailure(可丢弃的arg0){
quoteText.setText(“获取报价失败”);
}
成功时公共无效(对象结果){
quoteText.setText((字符串)结果);
}
答案:1) 客户端调用该方法。
2) 客户
3) 我只能猜测,似乎这只是RPC滚动文件maintentryproject.java在客户端包中的位置,所以它不是servlet,而是GWT将编译为JavaScript的java文件。生成嵌入到HTML文件(welcomeGWT.HTML)中的javascript。 所以
- 首先加载welcomeGWT.html
- 然后浏览器开始执行GWT生成的javascript,该javascript在1000ms后调用服务器方法myMethod
- 最后,服务器返回回调,客户端执行下一个代码:
public void onFailure(可丢弃的arg0){
quoteText.setText(“获取报价失败”);
}
成功时公共无效(对象结果){
quoteText.setText((字符串)结果);
}
答案:1) 客户端调用该方法。
2) 客户
3) 我只能猜测,似乎这只是RPC如何滚动来理解发生了什么,GWT使用它来创建该服务的实际客户端实现是很重要的。使用这种技术,可以生成通常需要自己编写的代码。整个RPC调用将自动为您生成
interface GWTService:这只是您对服务外观的定义
接口GWTServiceAsync:这是在服务的自动生成客户端部分中实现的接口
类GWTServiceImpl:这是在服务器端运行的代码
因此,当您调用
GWT.create(GWTService.class)时代码>您将获得一个自动生成的类实例。如果您真的对所发生的事情感兴趣,您必须查看生成器实现
这或多或少是您手动执行的操作:
-序列化(google为此使用非标准方法,并且可以通过不同的GWT版本进行更改)
-使用序列化数据设置请求
-发送请求并等待响应
-反序列化响应并调用通过回调返回结果要了解发生了什么,GWT使用它来创建该服务的实际客户端实现是很重要的。使用这种技术,可以生成通常需要自己编写的代码。整个RPC调用将自动为您生成
interface GWTService:这只是您对服务外观的定义
接口GWTServiceAsync:这是在服务的自动生成客户端部分中实现的接口
类GWTServiceImpl:这是在服务器端运行的代码
因此,当您调用GWT.create(GWTService.class)时代码>您将获得一个自动生成的类实例。如果您真的对所发生的事情感兴趣,您必须查看生成器实现
这或多或少是您手动执行的操作:
-序列化(google为此使用非标准方法,并且可以通过不同的GWT版本进行更改)
-使用序列化数据设置请求
-发送请求并等待响应
-反序列化响应并通过回调调用返回结果是的,主Java应用程序就是这样。但至少,有一个类可以获取和发送值trought方法。在这个框架上,我不明白这是怎么可能的:)是的,这发生在主Java应用程序上。但至少,有一个类可以获取和发送值trought方法。在这个框架下,我不明白这是怎么可能的:)嗯……好吧!我只是觉得它很奇怪,呵呵(事实上我根本不知道这个框架,我想呵呵)。那么,调用GWTServiceAsync的“抽象”方法将自动调用在GWTServiceImpl上编写的该方法的实现?之后,我可以使用实例“result”管理该方法返回的内容?是的,如果从ServiceAsync服务调用该方法,将导致从ServiceImpl文件调用服务器方法。认为本文应该解释所有其他内容:和往常一样,在服务接口中定义的返回类型,在AsyncCallback参数中定义的YourServiceAsync,如:“AsyncCallback callback”。然后是ServiceImpl方法中的服务器端:“publicstringmymethod(strings){…}”嗯……好的!我只是觉得它很奇怪,呵呵(事实上我根本不知道这个框架,我想呵呵)。因此,将调用GWTServiceAsync的“抽象”方法