Deploy GWT .war with Servlet in Tomcat

青春壹個敷衍的年華 提交于 2019-12-11 04:45:43

问题


I've been following the tutorial on building a sample GWT Application: http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html

I then wanted to try exposing a servlet for serving up some JSON data according to this tutorial: http://code.google.com/webtoolkit/doc/latest/tutorial/JSON.html

Both tutorials are very clear and I had no issues getting it to work in Eclipse running in development mode. The way I'm testing it is by going to this URL: http://localhost:8888/stockwatcher/stockPrices?q=ABC+DEF That returns json results just as is designed in the tutorial. But now I want to deploy this project as a war file and run it in my own Tomcat server. I found this tutorial for deploying turning the project into a .war file: http://blog.elitecoderz.net/gwt-and-tomcat-create-war-using-eclipse-to-deploy-war-on-tomcat/2009/12/. It was clear, and the .war file built without any errors, but after I deploy it, my servlet for JSON data does not work. I simply get a 404 page and nothing happens. I also don't see anything in the server.log. Also, I am attempting to deploy this in Tomcat 6, if that makes any difference.


回答1:


I figured it out; it was a problem with the url-pattern tag in my web.xml file.

This is what I had:

<url-pattern>/stockwatcher/stockPrices</url-pattern>

but this resulted in the stockPrices servlet being accessible from this URL: http://127.0.0.1:8080/stockwatcher/stockwatcher/stockPrices?q=ABC

Instead, I changed it to:

<url-pattern>/stockPrices</url-pattern>

Because it's already within the stockwatcher war context.

Now this link works as expected: http://127.0.0.1:8080/stockwatcher/stockPrices?q=ABC




回答2:


You could try to copy the whole folder that is created during compiling into your tomcat webapps folder. If that works you would know if the problem lies in creating the war or has a different source. I would assume it has something to do with your web.xml. In your tomcat directory if you look in /webapps/yourproject/WEB-INF/ how does the web.xml look like? Do you have rpcs in your application ? are they working?




回答3:


you have mapped the servlet as

/stockwatcher/stockPrices

but you are invoking it as:

/stockwatcher/stockPrice?q=ABC

It's a typo.




回答4:


Make sure that application was started on the same path as it was in eclipse

http://127.0.0.1:8080/stockwatcher

Tomcat uses the war/folder name as a root path by default, so if you have stockwatcher-1.0-SHAPSHOT.war it will be published as http://127.0.0.1:8080/stockwatcher-1.0-SHAPSHOT...

Also to Tomcat Management page http://localhost:8080/manager/html to make sure on which path your application has been published



来源:https://stackoverflow.com/questions/8460936/deploy-gwt-war-with-servlet-in-tomcat

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!