如何使用Netbeans 8.2在Maven中映射Servlet?

时间:2018-04-24 06:07:00

标签: java maven servlet-mapping

我访问了Servlet not being mapped, java web.xml not being overridden in target folder并尝试实施。

每当使用Neatbeans界面添加Servlet并驻留在project_folder/src/main/webapp/WEB-INF/并且具有如下内容(默认由Netbeans创建)时,我的web.xml会自动创建 -

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">
    <servlet>
        <servlet-name>AdminPathController</servlet-name>
        <servlet-class>AdminPathController</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>AdminPathController</servlet-name>
        <url-pattern>/AdminPathController</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>
            30
        </session-timeout>
    </session-config>
</web-app>

但是当我点击地址localhost:8080/entry-dispatch/AdminPathController时,会返回错误HTTP Status 404 - Not Found

稍后我在pom.xml中添加了一些插件代码,如下所示映射web.xml文件,如下所示 -

<plugin>
   <groupId>org.apache.maven.plugins</groupId>
   <artifactId>maven-war-plugin</artifactId>
   <version>2.4</version>
   <configuration>
      <webXml>${basedir}/src/main/webapp/WEB-INF/web.xml</webXml>
   </configuration>
 </plugin>

0 个答案:

没有答案