@WebServlet注释和错误404
首先:我使用 GlassFish 3.1 + Eclipse Java EE indigo。 我想用 javaee 测试缓存解决方案,所以我制作了一个虚拟应用程序。我有一个很大的生成数据库,我列出、搜索、修改等一些数据。为此,我编写了一些基本的 servlet,并使用 GET 参数进行调用。例如:/app/list?page=product&pageSize=100 ListServlet 带有注释
@WebServlet({ "/ListServlet", "/list" })
,它的工作方式就像一个魅力,我可以使用这两个 url。 所以我需要一些额外的servlet(用于搜索、修改)。我创建了它们并以相同的方式进行注释。 但是当我输入 url http://localhost/app/modify
或 /app/search?id=1 时,我收到错误 404。 我尝试编写一个非常虚拟的 helloservlet,它打印一条 hello world 消息,但它不起作用:错误 404。我重新启动了 glassfish 服务器和计算机,但没有帮助。
有什么问题吗?我错过了什么吗?
编辑: servlet 是相同的包,使用相同的导入...
First of all: I use GlassFish 3.1 + Eclipse Java EE indigo.
I want to testing cache solutions with javaee so I made a dummy app. I have a big generated database and I list, search, modify, etc some data. To do that I wrote some basic servlet and I call with GET parameters. e.g.: /app/list?page=product&pageSize=100
The ListServlet is annotated with
@WebServlet({ "/ListServlet", "/list" })
and it works like a charm, I can use both urls.
So I need some additional servlet (for search, modify). I created them and annotated the same way.
But when I type the url http://localhost/app/modify
or /app/search?id=1 I get error 404.
I tried to write a very dummy helloservlet which is print a hello world message but it didn't work: error 404. I restarted the glassfish server and the computer but not helped.
What's the problem? Did I miss something?
EDIT:
the servlets are the same package uses the same imports...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您确定您的网址模式正确吗?尝试这样的事情:
如果您希望所有模式都进入同一个 servlet。如果没有,您将必须为每个模式使用不同的 servlet,并且我猜这些 servlet 应该以不同的方式命名。
无论如何,对于这种行为,我建议使用 Restlet 路由。
编辑:
我测试过。在这里,我的 servlet 工作起来就像一个魅力:
第二个:
我确实这样称呼它们: http://localhost: 8080/eetest/hello1 和 http://localhost:8080/eetest/hello2 并且它们打印分别为“Hello Servlet One”和“Hello Servlet Two”。
(在 JBoss AS 7 - 网络配置文件上测试)
Are you sure your url patterns are correct? Try something like this:
If you want all the patterns go into the same servlet. If not, you would have to have a different servlets for each pattern, and those servlets should be named differently I guess.
Anyway, for this kind of behaviour I would recommend using for example Restlet routing.
EDITED:
I tested it. Here you have my servlets working like a charm:
and the second one:
I do call them like: http://localhost:8080/eetest/hello1 and http://localhost:8080/eetest/hello2 and they print 'Hello Servlet One' and 'Hello Servlet Two' respectivelly.
(tested on JBoss AS 7 - web profile)
我遇到了这个问题,问题是我的 servlet 中忘记了导入语句。确保您的 servlet 已正确编译。
I had this issue and the problem was a forgotten import statement in my servlet. Make sure your servlet is compiling correctly.