http status 404 : the required resource is not found

你离开我真会死。 提交于 2019-12-08 13:27:29

The WebServlet name attribute cannot start with a /. Rather do,

@WebServlet("UserAccessServlet")

or leave it blank (if you want the WebServlet to use the name of your Servlet class name. Example:

@WebServlet
public class UserAccessServlet extends HttpServlet {


//Do stuff
}

I would recommend declaring your WebServlet annotations fully like in this example.

I'm not sure when and in what for conditions you are receiving this error. But if you are deploying to tomcat, the following might occur:

Assuming your webapp is called "my.webapp" resulting in my.webapp.war assuming you have a Servlet "servlet1" which performs action1 => @WebServlet(urlPatterns = "/action1") (note the slash in front of action1)

Assuming you are calling this action with a html form: <form action="/action1" method="GET"> this might not work because of the slash in front of action1

When it's there tomcat will redirect to localhost:8080/action1?.. while it should redirect to localhost:8080/my.project/action1?..

Solution alter the html so the form looks like: <form action="action1" method="GET">, don't change the @WebServlet(urlPatterns = "/action1")

Hope this helps someone!

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