关于servlet的配置

当我们使用eclipse新建一个Servlet时,我们到web.xml中配置后有时会出现服务器无法启动的情况

下面我们来看:

eg:

servlet:

**
 * Servlet implementation class LogoServlet
 */
@WebServlet("/LogoServlet")//重点在这里
public class LogoServlet extends HttpServlet {
 private static final long serialVersionUID = 1L;

 
 public LogoServlet() {
 
 }
 protected void doGet(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
  this.doPost(request, response);
 }
 protected void doPost(HttpServletRequest request, HttpServletResponse response)
   throws ServletException, IOException {
 
 }

}

当我们去web.xml中配置了一个与@WebServlet("/LogoServlet相同的servlet后那么服务器就无法启动了,

因为:

eclipse自动帮我生成了注解,servlet3.0支持注解,那么问题就来了,你们是双胞胎,我到底该用哪一个呢,

好吧你们是双胞胎,那我得静静的考虑下,所以就不启动服务器咯。

因此

方法一:我们只需不使用注解,获取不去配置web.xml就可以了。

方法二:改变二者的任意一个名就可以啦。

 原创,不对之处请指正。邮箱:jleeci@foxmail.com

原文地址:https://www.cnblogs.com/JLeeci/p/5599171.html