Trying to get the simplest communication between the client and server.

29 views
Skip to first unread message

Dale12

unread,
Jul 5, 2011, 11:33:36 AM7/5/11
to Google Web Toolkit
I'm new to GWT and trying to get the simplest project under my belt.
I've got a project that does nothing but send a string from the client
to the server. The server adds a string to that string and returns
it. I've been spinning my wheels on this for days and don't know
where to go from here or what to even ask at this point. I've read
numerous tutorials and sample projects on the subject and it all makes
sense.

My project compiles fine. Then when I try to run "web application" i
get the following message in the browser (Chrome): "
"
HTTP ERROR 404

Problem accessing /MyGWTModule.html. Reason:

NOT_FOUND
"
I also get the following warning in the eclipse console.

[WARN] No file found for: /MyGWTModule.html
[WARN] No file found for: /favicon.ico

I compile and then "run web application". Am I missing a step?

If I zipped the project would someone be willing to take a quick look
at it (via email). Or let me know if there's a better way of sharing
it. Meanwhile, I'll post the project files in this post in hopes that
it will be enough for someone to help.

Also, could someone fill me in on what the Util class is for in the
MyRemoteService interface is for?

Thanks, the help is much appreciated.

**************************************Entry point file
MyGWTModule**************************************************************

package com.mycompany.project.client;

import com.google.gwt.core.client.EntryPoint;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.Window;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.ui.Button;
import com.google.gwt.user.client.ui.RootPanel;
import com.google.gwt.core.client.GWT;

/**
* Entry point classes define <code>onModuleLoad()</code>.
*/
public class MyGWTModule implements EntryPoint {

//MyRemoteServiceAsync myRSAsync =
MyRemoteServiceAsync.Util.getInstance();
MyRemoteServiceAsync svc = GWT.create(MyRemoteService.class);

AsyncCallback<String> callback = new AsyncCallback<String>() {
public void onSuccess(String result) {
Window.alert(result);
}
public void onFailure(Throwable caught) {
Window.alert("RPC Failed.");
}
};

private Button clickMeButton;
public void onModuleLoad() {
RootPanel rootPanel = RootPanel.get();

clickMeButton = new Button();
rootPanel.add(clickMeButton);
clickMeButton.setText("Click me!");
clickMeButton.addClickHandler(new ClickHandler(){
public void onClick(ClickEvent event) {
Window.alert("Hello, GWT World!");
String s = "ass";
svc.printSomething(s, callback);
Window.alert(s);

}
});
}
}
**************************************End Entry point
file**************************************************************

*************************************MyRemoteService
Interface***************************************************************

package com.mycompany.project.client;

import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwt.user.client.rpc.RemoteService;
import com.google.gwt.user.client.rpc.RemoteServiceRelativePath;

@RemoteServiceRelativePath("MyRemoteService")
public interface MyRemoteService extends RemoteService {
/**
* Utility class for simplifying access to the instance of async
service.
*/
public String printSomething(String s);

public static class Util {
private static MyRemoteServiceAsync instance;
public static MyRemoteServiceAsync getInstance(){
if (instance == null) {
instance = GWT.create(MyRemoteService.class);
}
return instance;
}
}
}
*************************************End MyRemoteService
Interface***************************************************************

*************************************MyRemoteServiceAsync
Interface***************************************************************
package com.mycompany.project.client;

import com.google.gwt.user.client.rpc.AsyncCallback;

public interface MyRemoteServiceAsync {

public void printSomething(String s, AsyncCallback<String> callback);

*************************************End MyRemoteServiceAsync
Interface***************************************************************

*************************************MyRemoteServiceImpl
Interface***************************************************************
package com.mycompany.project.server;

import com.mycompany.project.client.MyRemoteService;
import com.google.gwt.user.server.rpc.RemoteServiceServlet;

@SuppressWarnings("serial")
public class MyRemoteServiceImpl extends RemoteServiceServlet
implements MyRemoteService {

public String printSomething(String s){

return s + "hole";
}
}

*************************************END MyRemoteServiceImpl
Interface***************************************************************

*************************************MyGWTModule.gwt.xml (auto
generated)
***************************************************************
<module>
<inherits name="com.google.gwt.user.User"/>
<inherits name="com.google.gwt.user.theme.standard.Standard"/>
<entry-point class="com.mycompany.project.client.MyGWTModule"/>
</module>
*************************************END
MyGWTModule.gwt.xml***************************************************************

************************************* web.xml (auto generated)
***************************************************************
<?xml version="1.0" encoding="utf-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5">
<servlet>
<servlet-name>MyRemoteService</servlet-name>
<servlet-class>com.mycompany.project.server.MyRemoteServiceImpl</
servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyRemoteService</servlet-name>
<url-pattern>/com.mycompany.project.MyGWTModule/MyRemoteService</url-
pattern>
</servlet-mapping>
</web-app>

*************************************END web.xml
***************************************************************

Jens

unread,
Jul 5, 2011, 11:55:10 AM7/5/11
to google-we...@googlegroups.com
I think your code looks fine.

Do you actually have a MyGWTModule.html file inside your war folder or any html page that includes the generated .js files from GWT? 
If not you have to create one (New -> HTML Page. The one with the GWT icon). 
You can also create it by hand. Just make sure you have

<script type="text/javascript" language="javascript" src="<your module name>/<your module name>.nocache.js"></script>

in the html page's <head> tag and if you ever want to have history support you need

<iframe src="javascript:''" id="__gwt_historyFrame" tabIndex='-1' style="position:absolute;width:0;height:0;border:0"></iframe>

inside the <body> tag.

-- J.

Dale12

unread,
Jul 5, 2011, 4:06:42 PM7/5/11
to Google Web Toolkit
Thanks for the response. Yes, the HTML file and the CSS file are
there in the war fiolder. It was created manually when I generated my
GWT module. Possibly the path is messed up somewhere?
I also tried to create a new HTML file as you suggested (not manually)
and when I clicked on finish, nothing happened.

Any other ideas?

Dale12

unread,
Jul 5, 2011, 4:08:28 PM7/5/11
to Google Web Toolkit
In addition to that, I can manually open the HTML file and when I
click on the button, I get an "RPC failed" message, which is what I
programmed it to do onFail().

On Jul 5, 11:55 am, Jens <jens.nehlme...@gmail.com> wrote:

Rike255

unread,
Jul 5, 2011, 5:01:44 PM7/5/11
to Google Web Toolkit
I'm new to GWT too so I'm not much help, but I went through this
tutorial and found it extremely useful:

http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html

It explains basically everything that you posted above. Note that
there is no Util class in the Service interface though, that's
basically the only difference I could find between the code you posted
and this example. I was able to get this example working properly in
my Eclipse environment (ran it exactly how you described too... GWT
compile + Run as Web App)
Reply all
Reply to author
Forward
0 new messages