且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

调用Servlet会导致HTTP状态404“请求的资源不可用".

更新时间:2023-08-19 23:23:34

请求的资源(/omgtuk/Register)不可用.

The requested resource (/omgtuk/Register) is not available.

这仅表示servlet不在监听/Register的URL模式.换句话说,您没有@WebServlet("/Register").

This simply means that the servlet isn't listening on an URL pattern of /Register. In other words, you don't have a @WebServlet("/Register").

在您的特定情况下,您在URL中输入了大小写错误.网址区分大小写.您正在调用/Register,但是您的servlet正在监听/register.相应地修正表单操作.

In your particular case, you made a case mistake in the URL. URLs are case sensitive. You're calling /Register, but your servlet is listening on /register. Fix your form action accordingly.

因此,它应该看起来像这样:

So, it should not look like this:

<form action="Register">

但是它应该看起来像这样:

But it should look like this:

<form action="register">

或者这,如果您无聊时碰巧在JSP周围移动,这会更健壮:

Or this, which is more robust in case you happen to move around JSPs when you're bored:

<form action="${pageContext.request.contextPath}/register">


无关与具体问题无关,请注意,您是通过类上的@WebServlet注释和web.xml中的<servlet>条目注册了servlet的.这个不对.您应该使用其中一个.从Servlet 3.0(Java EE 6)开始,@WebServlet是注册servlet的新方法,而<servlet>是注册servlet的旧方法.


Unrelated to the concrete problem, please note that you registered the servlet via both a @WebServlet annotation on the class and a <servlet> entry in web.xml. This is not right. You should use the one or the other. The @WebServlet is the new way of registering servlets since Servlet 3.0 (Java EE 6) and the <servlet> is the old way of registering servlets.

只需除去web.xml中的整个<servlet><servlet-mapping>.您无需同时指定两者.确保您正在阅读最新的书籍/教程. Servlet 3.0自2009年12月以来已经存在.

Just get rid of the whole <servlet> and <servlet-mapping> in web.xml. You don't need to specify both. Make sure that you're reading up to date books/tutorials. Servlet 3.0 exist since December 2009 already.

另一个细节是p1不是 一个类,而是一个包.在加入Java EE之前,我强烈建议您花更多的时间在学习基本Java上.

Another detail is that p1 is not a class, it's a package. I'd warmly recommend to invest a bit more time in learning basic Java before diving into Java EE.