Calling servlet results in HTTP Status 404 “The requested resource is not available” [duplicate]

我的梦境 提交于 2019-11-29 10:44:08
BalusC

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

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").

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">

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

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

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.

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.

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.

See also:

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