The servlets named [LogRecord] and [com.action.service.imp.LogServiceImp] are both mapped to the url

Caused by: java.lang.IllegalArgumentException: The servlets named [LogRecord] and [com.action.service.imp.LogServiceImp] are both mapped to the url-pattern [/LogRecord] which is not permitted

I am new to sevlets and have no idea what most of the errors mean. What am I doing wrong? I have search for other questions like this on SO but the answers I found didn’t work.

This is my web.xml file:

  <servlet>
    <servlet-name>LogRecord</servlet-name>
    <servlet-class>com.action.servlet.LogRecord</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>LogRecord</servlet-name>
    <url-pattern>/LogRecord</url-pattern>
  </servlet-mapping>
@WebServlet(urlPatterns="/LogRecord")
public class LogServiceImp implements LogDao{

    @Override
    public void delete(log logi) {
        // TODO Auto-generated method stub
    }

    @Override
    public void update(log logi) {
        // TODO Auto-generated method stub  
    }

answers:

It could be because"` "you're mixing the web.xml servlets configuration with the annotation based configuration"`", so check that you don't declare the same servlet in the web.xml.

Based in your xml you have two options because you are configuring your servlet with annotations you can delete de tags from your web.xml. Or if you want to fix your web.xml you need to delete the start / from the servlet-name tag, it need to match with the before servlet name so:

<servlet-mapping> 
   <servlet-name>HelloServlet</servlet-name> 
   <url-pattern>/HelloServlet</url-pattern> 
</servlet-mapping>

原因是因为我同时在注解里面和web.xml里面同时定义了url-pattern,所以导致出错。
具体注解怎么影响以及为什么会出现冲突,下来再看看资料。。。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值