您的位置:首页 > 移动开发

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

2016-08-23 12:09 645 查看
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,所以导致出错。
具体注解怎么影响以及为什么会出现冲突,下来再看看资料。。。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  servlets
相关文章推荐