GWT Project <servlet-mapping> clarification - how mapping happens

403 views
Skip to first unread message

Tharindu Madushanka

unread,
Jun 2, 2009, 6:41:54 PM6/2/09
to Google Web Toolkit
Hi,

Perhaps this might not be the correct place to ask this. But please
kindly tell some answer to this.

I am new to web development and I started reading about GWT, and when
I look at web.xml I see the

<servlet>
<servlet-name>greetServlet</servlet-name>
<servlet-class>com.gwt.test.server.GreetingServiceImpl</servlet-
class>
</servlet>

<servlet-mapping>
<servlet-name>greetServlet</servlet-name>
<url-pattern>/calc/greet</url-pattern>
</servlet-mapping>

I used ant script created to run the application in hosted mode. When
I run the application in hosted browser it shows the url as
http://localhost:8080/calc.html
Perfectly I could access this Url from other browser as well. But my
question is what is the purpost of <url-pattern>/calc/greet</url-
pattern> . I tried to access the url by typing http://localhost:8080/calc/greet,
but it displays following error - HTTP Error 405

HTTP method GET is not supported by this URL

RequestURI=/calc/greet
It it directly access from url by typing http://.../calc.html, then
what is the purpost of url-mapping tag. I saw on blogs we can add
several this kind of mapping. But still how it knows this request maps
to this url-pattern. In our case, I only request calc.html and then
how web.xml file knows I requested calc/greet.

Please calrify a little on this. I am so confused about how this
happen.


Kind regards,
-Tharindu

Jim

unread,
Jun 2, 2009, 7:46:39 PM6/2/09
to Google Web Toolkit
In GWT 1.6,

1.calc.html should contain a generated Javascript code like
"<script type="text/javascript" language='javascript' src='mail/
mail.nocache.js'></script>" in http://www.gwtorm.com/mail/Mail.html.

2.A service interface like MailService has the following code:
@RemoteServiceRelativePath("mailService")
public interface MailService extends RemoteService {
void save(Contact contact) throws LinqException;
Mails getMails(int startIndex, int count) throws LinqException;
int getTotalMailCount() throws LinqException;
List<Contact> getContacts(int personId) throws LinqException;
Contact getContact(ContactPK contactPK) throws LinqException;
}

3.mailService is mapped to MailServiceImpl servlet as indicated
in the following web.xml.
<servlet>
<servlet-name>mailServlet</servlet-name>
<servlet-
class>com.google.gwt.sample.mail.client.server.MailServiceImpl</
servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>mailServlet</servlet-name>
<url-pattern>/mail/mailService</url-pattern>
</servlet-mapping>

If you took look at
com.google.gwt.user.server.rpc.RemoteServiceServlet, you will find
RemoteServiceServlet just overrides doPost method. That is a reason
you get HTTP Error 405 when you try to get access to that url through
get method.

Jim
http://www.gwtorm.com - GWT ORM
http://code.google.com/p/dreamsource-orm/


On Jun 2, 6:41 pm, Tharindu Madushanka <tharindu...@gmail.com> wrote:
> Hi,
>
> Perhaps this might not be the correct place to ask this. But please
> kindly tell some answer to this.
>
> I am new to web development and I started reading about GWT, and when
> I look at web.xml I see the
>
>  <servlet>
>     <servlet-name>greetServlet</servlet-name>
>     <servlet-class>com.gwt.test.server.GreetingServiceImpl</servlet-
> class>
>   </servlet>
>
>   <servlet-mapping>
>     <servlet-name>greetServlet</servlet-name>
>     <url-pattern>/calc/greet</url-pattern>
>   </servlet-mapping>
>
> I used ant script created to run the application in hosted mode. When
> I run the application in hosted browser it shows the url ashttp://localhost:8080/calc.html
> Perfectly I could access this Url from other browser as well. But my
> question is what is the purpost of  <url-pattern>/calc/greet</url-
> pattern> . I tried to access the url by typinghttp://localhost:8080/calc/greet,
> but it displays following error - HTTP Error 405
>
> HTTP method GET is not supported by this URL
>
> RequestURI=/calc/greet
> It it directly access from url by typinghttp://.../calc.html, then

Tharindu Madushanka

unread,
Jun 2, 2009, 8:52:10 PM6/2/09
to Google Web Toolkit
>
>     3.mailService is mapped to MailServiceImpl servlet as indicated
> in  the following web.xml.
> <servlet>
>     <servlet-name>mailServlet</servlet-name>
>     <servlet-
> class>com.google.gwt.sample.mail.client.server.MailServiceImpl</
> servlet-class>
>   </servlet>
>
>   <servlet-mapping>
>     <servlet-name>mailServlet</servlet-name>
>     <url-pattern>/mail/mailService</url-pattern>
>   </servlet-mapping>
>
> If you took look at
> com.google.gwt.user.server.rpc.RemoteServiceServlet, you will find
> RemoteServiceServlet just overrides doPost method. That is a reason
> you get HTTP Error 405 when you try to get access to that url through
> get method.
>

Sorry for asking again, but still I am not clear. I am clear about the
module , host page creation and use of nocache.js file. But my
question is ::::::
I want to know whether we can get the functionality working by
calling
http://localhost/mail/mailService URL
If not the case, what is the purpose of adding it as a <url-pattern>
In my case I have to type the url http://localhost/calc.html to open
it from FF. Then there is no pattern there. Could you kindly explain
just about what is the purpose or functionality with related to
example browser request urls appear in the browser.

Thanks.
-Tharindu

Jim

unread,
Jun 2, 2009, 9:24:42 PM6/2/09
to Google Web Toolkit
In your example, once you type http://localhost:8080/calc/greet in
FF, it is a synchronous regular request in Get method. Your servlet
doesn't override doGet method and
com.google.gwt.user.server.rpc.RemoteServiceServlet returns HTTP Error
405 to your request. In GWT application, it is a asynchronous RPC to
your servlet and you must implement the following methods in your
widgets:

public void onFailure
(Throwable caught) {
}

public void onSuccess(Mails mails) {


}


Jim


On Jun 2, 8:52 pm, Tharindu Madushanka <tharindu...@gmail.com> wrote:
> >     3.mailService is mapped to MailServiceImpl servlet as indicated
> > in  the following web.xml.
> > <servlet>
> >     <servlet-name>mailServlet</servlet-name>
> >     <servlet-
> > class>com.google.gwt.sample.mail.client.server.MailServiceImpl</
> > servlet-class>
> >   </servlet>
>
> >   <servlet-mapping>
> >     <servlet-name>mailServlet</servlet-name>
> >     <url-pattern>/mail/mailService</url-pattern>
> >   </servlet-mapping>
>
> > If you took look at
> > com.google.gwt.user.server.rpc.RemoteServiceServlet, you will find
> > RemoteServiceServlet just overrides doPost method. That is a reason
> > you get HTTP Error 405 when you try to get access to that url through
> > get method.
>
> Sorry for asking again, but still I am not clear. I am clear about the
> module , host page creation and use of nocache.js file. But my
> question is ::::::
>  I want to know whether we can get the functionality working by
> callinghttp://localhost/mail/mailServiceURL
> If not the case, what is the purpose of adding it as a <url-pattern>
> In my case I have to type the urlhttp://localhost/calc.htmlto open
> it from FF. Then there is no pattern there. Could you kindly explain
> just about what is the purpose or functionality with related to
> example browser request urls appear in the browser.
>
> Thanks.
> -Tharindu- Hide quoted text -
>
> - Show quoted text -

amayen

unread,
Jun 4, 2009, 6:44:34 AM6/4/09
to Google Web Toolkit
Hi Tharindu!

To make it more clearly for you the calc.html and the url /calc/greet
refer to different resources.

The calc.html is the HTML resource that the browser initially loads to
show your GWT app.

The /calc/greet path denotes a Java SERVLET. This servlet is there to
access some resources on the webserver
that should not be publicly available through the users browser. Like
connection to a database etc.

The calc.html communicates via asynchronous calls with the /calc/greet
servlet. For communicating it sends specific request too the /calc/
greet url. If you invoke the the /calc/greet url without using these
specific requests you will get the error you are seeing.

So the /calc/greet url is not there to be invoked directly by a user.
But it must be there for the calc.html to work correctly, because it
will communicate with it.

Hope that clears things up. You can also try to remove the servlet
mapping in web.xml and you should see that if you go to calc.html it
will not work, like it should, because it can't access the servlet
anymore.


Kind regards,


Anatol
Reply all
Reply to author
Forward
0 new messages