在Tomcat中使用Servlet部署GWT .war [英] Deploy GWT .war with Servlet in Tomcat
问题描述
我一直在遵循有关构建示例GWT应用程序的教程: http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html
I've been following the tutorial on building a sample GWT Application: http://code.google.com/webtoolkit/doc/latest/tutorial/gettingstarted.html
然后我想根据本教程尝试公开一个servlet,以提供一些JSON数据: http://code.google.com/webtoolkit/doc/latest/tutorial/JSON.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
两个教程都很清晰,我也没有任何问题可以使其在以开发模式运行的Eclipse中工作.我测试它的方法是转到以下URL: http://localhost:8888 /stockwatcher/stockPrices?q = ABC + DEF 会按照本教程的设计返回json结果.但是现在我想将该项目作为war文件部署并在我自己的Tomcat服务器中运行.我发现了本教程,用于部署将项目转换为.war文件:
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.
推荐答案
我知道了;这是我的web.xml文件中的url-pattern标记出现的问题.
I figured it out; it was a problem with the url-pattern tag in my web.xml file.
这就是我所拥有的:
<url-pattern>/stockwatcher/stockPrices</url-pattern>
,但这导致可从以下URL访问stockPrices servlet: http://127.0.0.1:8080/stockwatcher/stockwatcher/stockPrices?q=ABC
but this resulted in the stockPrices servlet being accessible from this URL: http://127.0.0.1:8080/stockwatcher/stockwatcher/stockPrices?q=ABC
相反,我将其更改为:
<url-pattern>/stockPrices</url-pattern>
因为它已经在StockWatcher战争环境中了.
Because it's already within the stockwatcher war context.
现在此链接可以正常使用: http://127.0.0.1:8080/stockwatcher /stockPrices?q = ABC
Now this link works as expected: http://127.0.0.1:8080/stockwatcher/stockPrices?q=ABC
这篇关于在Tomcat中使用Servlet部署GWT .war的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!