gmaps を使用して gwt アプリを作成しています。ボタンをクリックしてサービスを呼び出すと、Eclipse のコンソールに次のように表示されます。 PS: サービスはテスト目的のみです。私は本当のサービスを実装していません!
[WARN] 404 - POST /findmeagasstationweb/inserirpostorpc (127.0.0.1) 1422 bytes
Request headers
Host: 127.0.0.1:8888
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:17.0) Gecko/20100101 Firefox/17.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
Accept-Language: pt-pt,pt;q=0.8,en;q=0.5,en-us;q=0.3
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://127.0.0.1:8888/FindMeAGasStationWeb.html?gwt.codesvr=127.0.0.1:9997
X-GWT-Permutation: HostedMode
X-GWT-Module-Base: http://127.0.0.1:8888/findmeagasstationweb/
Content-Type: text/x-gwt-rpc; charset=utf-8
Content-Length: 225
Pragma: no-cache
Cache-Control: no-cache
Response headers
Content-Type: text/html; charset=iso-8859-1
Content-Length: 1422
私のアプリの次のコード:
定義済みサーブレット
<!-- Servlets -->
<servlet>
<servlet-name>insereServlet</servlet-name>
<servlet-class>com.pz.findmeagasstationweb.server.InsereNovoPostoImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>insereServlet</servlet-name>
<url-pattern>/inserirpostorpc/</url-pattern>
</servlet-mapping>
クラス FindMeAGasStationWeb
package com.pz.findmeagasstationweb.client;
//imports are omitted
public class FindMeAGasStationWeb implements EntryPoint {
Label latLabel = new Label("Latitude");
TextBox latBox = new TextBox();
Label longLabel = new Label("Longitude");
TextBox longBox = new TextBox();
Label nameLabel = new Label("Nome do Posto");
TextBox nameBox = new TextBox();
Label descLabel = new Label("Descricao");
TextBox descBox = new TextBox();
Label sc95Label = new Label("Preco Gasolina 95");
TextBox sc95Box = new TextBox();
Label sc98Label = new Label("Preco Gasolina 98");
TextBox sc98Box = new TextBox();
Label gasoleoLabel = new Label("Preco Gasoleo");
TextBox gasoleoBox = new TextBox();
Button inserir = new Button("Inserir Posto");
Grid grid = new Grid(2, 8);
public int controlo;
public void onModuleLoad() {
final AsyncCallback<String> callback = new AsyncCallback<String>(){
public void onFailure(Throwable caught){
Window.alert("Falha a inserir os dados."+caught);
}
public void onSuccess(String result){
Window.alert(""+result);
}
};
grid.setWidget(0, 0, latLabel);
grid.setWidget(0, 1, latBox);
grid.setWidget(1, 0, longLabel);
grid.setWidget(1, 1, longBox);
grid.setWidget(0, 2, nameLabel);
grid.setWidget(0, 3, nameBox);
grid.setWidget(1, 2, descLabel);
grid.setWidget(1, 3, descBox);
grid.setWidget(0, 4, sc95Label);
grid.setWidget(0, 5, sc95Box);
grid.setWidget(1, 4, sc98Label);
grid.setWidget(1, 5, sc98Box);
grid.setWidget(0, 6, gasoleoLabel);
grid.setWidget(0, 7, gasoleoBox);
grid.setWidget(1, 7, inserir);
latBox.setEnabled(false);
longBox.setEnabled(false);
RootPanel.get().add(grid);
inserir.addClickHandler(new ClickHandler() {
public void onClick(ClickEvent event) {
//.inserirPosto(latBox.getText(), longBox.getText(), nameBox.getText(), descBox.getText(),
try{
InsereNovoPostoAsync getServico = (InsereNovoPostoAsync) GWT.create(InsereNovoPosto.class);
ServiceDefTarget serviceDef = (ServiceDefTarget) getServico;
serviceDef.setServiceEntryPoint(GWT.getModuleBaseURL()
+ "inserirpostorpc");
getServico.inserirPosto("1","2", "a", "b", "1", "2", "3", callback);
}
catch(Exception ex){
Window.alert(""+ex);
}
//getServico().inserirPosto(latBox.getText(), longBox.getText(), nameBox.getText(), descBox.getText(), sc95Box.getText(), sc98Box.getText(), gasoleoBox.getText(), callback);
/*
(latBox.getText(), longBox.getText(), nameBox.getText(),
descBox.getText(), sc95Box.getText(), sc98Box.getText(),
gasoleoBox.getText(), callback);
/*RootPanel.get().add(
new Label("Thanks for your submission."));
Window.alert("Submit name=" + nameBox.getText()
+ "\naddress=" + addrBox.getText() + "\nphone="
+ phoneBox.getText());*/
}
});
MapWidget mapWiget = new MapWidget(LatLng.newInstance(48.136559, 11.576318), 13);
mapWiget.setSize("1024px", "500px");
mapWiget.addControl(new SmallMapControl());
mapWiget.addControl(new MapTypeControl());
mapWiget.addMapClickHandler(new MapClickHandler() {
public void onClick(MapClickEvent e) {
MapWidget sender = e.getSender();
Overlay overlay = e.getOverlay();
LatLng point = e.getLatLng();
if (overlay != null && overlay instanceof Marker) {
sender.removeOverlay(overlay);
latBox.setText("");
longBox.setText("");
controlo = 0;
} else {
if(controlo==0){
String a[] = point.toString().split(",");
String b = a[0].toString();
b = b.substring(1);
String c = a[1].toString();
c = c.substring(0, c.length()-1);
latBox.setText(""+b);
longBox.setText(""+c);
sender.addOverlay(new Marker(point));
controlo=1;
}
}
}
});
RootPanel.get().add(mapWiget);
}
}
サービス: InsereNovoPosto
package com.pz.findmeagasstationweb.client;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;
@RemoteServiceRelativePath("inserirpostorpc")
public interface InsereNovoPosto extends RemoteService {
public String inserirPosto(String lat, String longi, String nome,
String descricao, String sc95, String sc98, String gasoleo);
}
InsereNovoPostoAsync
package com.pz.findmeagasstationweb.client;
import com.google.gwt.user.client.rpc.AsyncCallback;
public interface InsereNovoPostoAsync {
public void inserirPosto(String lat, String longi, String nome,
String descricao, String sc95, String sc98, String gasoleo, AsyncCallback<String> callback);
}
InsereNovoPostoImpl
package com.pz.findmeagasstationweb.server;
import com.pz.findmeagasstationweb.client.InsereNovoPosto;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;
@SuppressWarnings("serial")
public class InsereNovoPostoImpl extends RemoteServiceServlet implements InsereNovoPosto {
@Override
public String inserirPosto(String lat, String longi, String nome,
String descricao, String sc95, String sc98, String gasoleo) {
Window.alert(""+lat+"-"+longi+"-"+nome+"-"+descricao+"-"+sc95+"-"+sc98+"-"+gasoleo);
return nome;
}
}
findmegasstationweb.gwt.xml
<?xml version="1.0" encoding="UTF-8"?>
<!--
When updating your version of GWT, you should also update this DTD reference,
so that your app can take advantage of the latest GWT module capabilities.
-->
<!DOCTYPE module PUBLIC "-//Google Inc.//DTD Google Web Toolkit 2.5.0//EN"
"http://google-web-toolkit.googlecode.com/svn/tags/2.5.0/distro-source/core/src/gwt-module.dtd">
<module rename-to='findmeagasstationweb'>
<!-- Inherit the core Web Toolkit stuff. -->
<inherits name='com.google.gwt.user.User'/>
<!-- Inherit the default GWT style sheet. You can change -->
<!-- the theme of your GWT application by uncommenting -->
<!-- any one of the following lines. -->
<inherits name='com.google.gwt.user.theme.clean.Clean'/>
<!-- <inherits name='com.google.gwt.user.theme.standard.Standard'/> -->
<!-- <inherits name='com.google.gwt.user.theme.chrome.Chrome'/> -->
<!-- <inherits name='com.google.gwt.user.theme.dark.Dark'/> -->
<!-- Other module inherits -->
<inherits name='com.google.gwt.maps.GoogleMaps'/>
<script src='http://maps.google.com/maps?gwt=1&file=api&v=2' />
<!-- Specify the app entry point class. -->
<entry-point class='com.pz.findmeagasstationweb.client.FindMeAGasStationWeb'/>
<!-- Specify the paths for translatable code -->
<source path='client'/>
<source path='shared'/>
</module>
何がうまくいかないのですか?どんな助けでも素晴らしいでしょう... 高度に感謝し、私の悪い英語で申し訳ありません!