我在我的 GWT 项目中制作 RPC 并且它正在运行,但是我想要处理的数据以某种方式消失了。我使用本地主机作为服务器。我在服务器包中有两个类:防御:
package org.elsys.salvation.server;
import org.elsys.salvation.client.Defence;
import org.elsys.salvation.client.FunctionalityManager;
public class Defences {
private ArrayList<Defence> netDefences;
private ArrayList<Defence> hardDefences;
private ArrayList<Defence> softDefences;
public Defences(FunctionalityManager fm){
netDefences = fm.getNetDefences();
hardDefences = fm.getHardDefences();
softDefences = fm.getSoftDefences();
}
public ArrayList<Defence> getNetDefences() {
return netDefences;
}
public ArrayList<Defence> getHardDefences() {
return hardDefences;
}
public ArrayList<Defence> getSoftDefences() {
return softDefences;
}
}
和 DefenceServiceImpl.java :
package org.elsys.salvation.server;
import java.util.ArrayList;
import org.elsys.salvation.client.DefenceService;
import org.elsys.salvation.client.FunctionalityManager;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
public class DefenceServiceImpl extends RemoteServiceServlet implements DefenceService {
private Defences defences;
@Override
public void saveDefences(FunctionalityManager fm) {
defences = new Defences(fm);
}
@Override
public void getHardDefences(FunctionalityManager fm) {
fm.setHardDefences(defences.getHardDefences());
}
@Override
public void getNetDefences(FunctionalityManager fm) {
fm.setNetDefences(defences.getNetDefences());
}
@Override
public void getSoftDefences(FunctionalityManager fm) {
fm.setSoftDefences(defences.getSoftDefences());
}
}
下面是 DefenceService 接口:
package org.elsys.salvation.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("defences")
public interface DefenceService extends RemoteService {
void saveDefences(FunctionalityManager fm);
void getHardDefences(FunctionalityManager fm);
void getNetDefences(FunctionalityManager fm);
void getSoftDefences(FunctionalityManager fm);
}
和 DefenceServiceAsync:
package org.elsys.salvation.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface DefenceServiceAsync {
void saveDefences(FunctionalityManager fm, AsyncCallback<Void> callback);
void getHardDefences(FunctionalityManager fm, AsyncCallback<Void> callback);
void getNetDefences(FunctionalityManager fm, AsyncCallback<Void> callback);
void getSoftDefences(FunctionalityManager fm, AsyncCallback<Void> callback);
}
这是我调用 saveDefences 方法的代码:
private void addDiploma() {
final AsyncCallback<Void> callback = new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Void result) {
SC.say("Submited");
}
};
some code...
Button submitButton = new Button("Submit");
submitButton.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
FM.getDiploma(projectNameTextBox, diplomantsNameTextBox,
diplomaLeadersListBox, reviewersListBox,
specialtiesComboBox, typeComboBox);
FM.generateDefences();
defenceSvc.saveDefences(FM,callback);
RootPanel.get("mainDiv").clear();
showDefences();
}
});
some more code...
}
下面是 FM 和 defenceSvc 的定义:
public FunctionalityManager FM = new FunctionalityManager();
private DefenceServiceAsync defenceSvc = GWT.create(DefenceService.class);
这是我想将保存的数据返回客户端的地方:
protected void showDefence() {
FunctionalityManager funcM = new FunctionalityManager();
final AsyncCallback<Void> callback = new AsyncCallback<Void>() {
public void onFailure(Throwable caught) {
}
@Override
public void onSuccess(Void result) {
// TODO Auto-generated method stub
}
};
defenceSvc.getHardDefences(funcM, callback);
defenceSvc.getNetDefences(funcM, callback);
defenceSvc.getSoftDefences(funcM, callback);
final ListGrid DiplomaGrid = new ListGrid();
DiplomaGrid.setWidth(500);
DiplomaGrid.setHeight(224);
DiplomaGrid.setShowAllRecords(true);
DiplomaGrid.setCanEdit(true);
DiplomaGrid.setEditEvent(ListGridEditEvent.CLICK);
DiplomaGrid.setModalEditing(true);
DiplomaData dd= new DiplomaData(funcM);
ListGridField nameField = new ListGridField("name", "Project Name");
ListGridField diplomantsField = new ListGridField("diplomants", "Diplomants");
ListGridField leaderField = new ListGridField("leader", "Leader");
ListGridField reviewerField = new ListGridField("reviewer", "Reviewer");
ListGridField typeField = new ListGridField("type", "Type");
ListGridField dateField = new ListGridField("date", "Date");
DiplomaGrid.setFields(new ListGridField[] {nameField, diplomantsField, leaderField,reviewerField, typeField, dateField});
DiplomaGrid.setData(dd.getRecords());
RootPanel.get("mainDiv").add(DiplomaGrid);
}
web.xml:
<servlet>
<servlet-name>defenceServiceImpl</servlet-name>
<servlet-class>org.elsys.salvation.server.DefenceServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>defenceServiceImpl</servlet-name>
<url-pattern>/salvation/defences</url-pattern>
</servlet-mapping>
当我在开发模式下运行它时,它正在运行,但是当我调用 showDefence() 方法时,我无法检索服务器数据上的序列化。有人可以告诉问题出在哪里吗?