Servlets and web.xml

93 views
Skip to first unread message

Jonathan

unread,
Feb 6, 2009, 3:05:57 PM2/6/09
to Google Web Toolkit
Hi to all,

I'm under linux and I follow this tutorial
http://jeff.ourexchange.net/2008/03/01/deploying-gwt-applications-with-jetty/.
I have a simple gwt application that browses for a file and upload it
using a servlet (class FileServlet extends HttpServlet).
In hosted mode (with tomcat) with the hosted browser of gwt, all works
as expected, my servlet runs fine.

I try to deploy application to a Jetty embedded server and i get a
HTTP ERROR: 503 SERVICE_UNAVAILABLE if i enable my servlet in web.xml
(under WEB-INF). Also when i run the Jetty server (in console), i get
two exceptions like "Failed startup of context
org.mortbay.jetty.webapp.WebAppContext@1b9ce4b{/com.tergwt.Main,file:/
home/jon/GWTDeploy/webapps/com.tergwt.Main/}"
java.lang.NullPointerException
I don't see the form of the upload.

If i disable the servlet declaration in the xml file, the server runs
without exceptions but it doesnt upload and i get "<h2>HTTP ERROR:
404</h2><pre>NOT_FOUND</pre><p>RequestURI=/com.tergwt.Main//
FileServlet</p>" if i try...

So i guess it has something to do with the web.xml file.
Unfortunately, i don't success with it.
Here is the content of my web.xml file without the web-app marks.
<servlet>
<servlet-name>fileServlet</servlet-name>
<servlet-class>com.tergwt.server.FileServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>fileServlet</servlet-name>
<url-pattern>/files/*</url-pattern>
</servlet-mapping>

I don't know what else i can do to fix this problem as i'm not an
expert with these things.
My main.java contains the upload form and it uses the FileServlet to
make the doPost().
Here is the full tree of my webapp deployed folder with the embed
Jetty server : http://filebin.ca/cjgvj/tree.txt.

Thanks in advance.
Best regards.
Jonathan

Jonathan

unread,
Feb 6, 2009, 7:42:03 PM2/6/09
to Google Web Toolkit
Wow, i'm almost happy !
I finally managed to get rid of the HTTP ERROR 503.
I misplaced the bin files (.classes), they need to be under yourapp/
web-inf/classes/...
So i took the time to copy libs here too (in lib folder).

OK this done, i don't success to upload my file.
I browse it correctly, but when i click submit i get : <h2>HTTP ERROR:
404</h2><pre>NOT_FOUND</pre>
<p>RequestURI=/com.tergwt.Main//FileServlet</p><p><i><small><a
href="http://jetty.mortbay.org/">Powered by Jetty://</a></small></i></p><br>
as a response of the server.

My web.xml updated :
<servlet>
<servlet-name>fileServlet</servlet-name>
<servlet-class>com.tergwt.server.FileServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>fileServlet</servlet-name>
<url-pattern>/fileServlet</url-pattern>
</servlet-mapping>

My entrypoint if needed:
onModuleLoad() {
final FormPanel form = new FormPanel();
form.setAction(GWT.getModuleBaseURL() + "/FileServlet");
...
}

If someone could tell me what's wrong, it could be nice :)

Thanks in advance,
Regards.


On 6 fév, 21:05, Jonathan <jonathan.delf...@gmail.com> wrote:
> Hi to all,
>
> I'm under linux and I follow this tutorialhttp://jeff.ourexchange.net/2008/03/01/deploying-gwt-applications-wit....

Shawn Brown

unread,
Feb 6, 2009, 7:50:57 PM2/6/09
to Google-We...@googlegroups.com
Well you have to specify a valid url.

You are configuring /fileServlet to go to your servlet and then asking
requesting a url of /FileServlet.

Aren't you? I am not sure but think capitalization is significant.

Best,

Shawn

Jonathan

unread,
Feb 6, 2009, 7:59:15 PM2/6/09
to Google Web Toolkit
Hey i just saw this before your message.
But even with that, it stills not working.
I still get this message 404<p>RequestURI=/com.tergwt.Main//
FileServlet</p><p><i><small>...

And i changed my formAction to form.setAction("/FileServlet"); instead
of form.setAction(GWT.getModuleBaseURL() + "/FileServlet");
So now, no more idea on my side ...

Cheers

On 7 fév, 01:50, Shawn Brown <big.coffee.lo...@gmail.com> wrote:
> Well you have to specify a valid url.
>
> You are configuring /fileServlet to go to your servlet and then asking
> requesting a url of /FileServlet.
>
> Aren't you?  I am not sure but think capitalization is significant.
>
> Best,
>
> Shawn
>

Jonathan

unread,
Feb 6, 2009, 8:01:57 PM2/6/09
to Google Web Toolkit
With form.setAction("/FileServlet"); i get <h2>HTTP ERROR: 404</
h2><pre>NOT_FOUND</pre>
<p>RequestURI=/FileServlet</p>

That's strange.
Thanks for the help.
Cheers

Shawn Brown

unread,
Feb 6, 2009, 10:30:35 PM2/6/09
to Google-We...@googlegroups.com
What about playing with:

form.setAction(GWT.getModuleBaseURL() + "/FileServlet");

and trying form.setAction("hard_coded_path_to_your_app_dir" + "/FileServlet");

I think GWT.getModuleBaseURL() isn't returning a valid path and
neither is form.setAction("/FileServlet")

Best,

Shawn

Jonathan

unread,
Feb 7, 2009, 7:05:47 AM2/7/09
to Google Web Toolkit
Hi,
Thanks again for the help.

GWT.getModuleBaseURL() returns http://localhost:8080/com.tergwt.Main/
so i guess the path is correct...
I tried to put the hardcoded path to my app folder (/home/jon/
GWTDeploy/webapps/com.tergwt.Main + /FileServlet) and i still get this
404.
I even tried to point it to the classes folder ...

I'm not sure to understand very well in what involves this setAction
line. It should point to my FileServlet.class file ?
Or something else ?

This servlet/form works fine in the embedded tomcat in hosted browser.
So i guess something between the two config is missing (in my jetty
server)
But i can't find what ! It's quite annoying :)

Thanks in advance...
Regards

On 7 fév, 01:59, Jonathan <jonathan.delf...@gmail.com> wrote:

jmpeace

unread,
Feb 7, 2009, 9:23:57 AM2/7/09
to Google Web Toolkit
Why don't you try opening a separated browser window and point to
http://localhost:8888/FileServlet

It should give you a HTTP Status 500 error meaning it is listening
there in hosted mode

On Feb 7, 8:05 am, Jonathan <jonathan.delf...@gmail.com> wrote:
> Hi,
> Thanks again for the help.
>
> GWT.getModuleBaseURL() returnshttp://localhost:8080/com.tergwt.Main/

Jonathan

unread,
Feb 7, 2009, 9:48:17 AM2/7/09
to Google Web Toolkit
Pointing to http://localhost:8080/com.tergwt.Main/FileServlet shows me
HTTP 405 (HTTP method GET is not supported by this URL).
http://localhost:8080/FileServlet shows 404 (normal it's not in my
webapp folder).

So, the FileServlet is here, but it stills can't be found by the form
action ?

I'm not using the GWT hosted browser with the tomcat integrated server
(I'm using Jetty).
Here is my web.xml file :
<servlet>
<servlet-name>fileServlet</servlet-name>
<servlet-class>com.tergwt.server.FileServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>fileServlet</servlet-name>
<url-pattern>/FileServlet</url-pattern>
</servlet-mapping>

Thanks,
Regards

On 7 fév, 15:23, jmpeace <jmpe...@gmail.com> wrote:
> Why don't you try opening a separated browser window and point tohttp://localhost:8888/FileServlet

Jonathan

unread,
Feb 7, 2009, 9:56:39 AM2/7/09
to Google Web Toolkit
Wow i don't know what happened but i put
form.setAction(GWT.getHostPageBaseURL() + "FileServlet");
using this web.xml and all finally works fine...

Thanks you very much for the help, i can now go forward !
Thanks again !

Best regards,
Jonathan

On 7 fév, 15:48, Jonathan <jonathan.delf...@gmail.com> wrote:
> Pointing tohttp://localhost:8080/com.tergwt.Main/FileServletshows me
> HTTP 405 (HTTP method GET is not supported by this URL).http://localhost:8080/FileServletshows 404 (normal it's not in my

Shawn Brown

unread,
Feb 7, 2009, 7:16:45 PM2/7/09
to Google-We...@googlegroups.com
Hi,

So what is the value for GWT.getHostPageBaseURL()?

What is your app called? By that I mean under Jetty_home/webapps/, in
what dir is your app.

Probably it's not com.tergwt.Main, but that is what you were asking in
http://localhost:8080/com.tergwt.Main/FileServlet

http://localhost:8080/dir_of_your_app/FileServlet should work. This
means that your web.xml file is at
/dir_of_your_app/WEB-INF/web.xml

> Wow i don't know what happened but i put
> form.setAction(GWT.getHostPageBaseURL() + "FileServlet");

well that is different than...

>> > > > of form.setAction(GWT.getModuleBaseURL() + "/FileServlet");


Glad it works!

Shawn

Reply all
Reply to author
Forward
0 new messages