我正在使用Eclipse Juno 4.2,Java 1.7和Tomcat 7.但是在我的系统中,当我创建servlet时,web.xml
文件不会自动创建,而是另一个系统会自动创建web.xml
文件.我完全糊涂了,有什么配置吗?
我还要web.xml
在创建动态项目时添加文件.
我想@WebServlet
在Tomcat 8上运行的Java EE webapp中使用注释.
我已经读过,我需要在我的Servlet版本3.1中声明,web.xml
并且我的Servlet需要扩展HttpServlet
.我做了所有这些,但仍然@WebServlet
不起作用.我正在获得HTTP 404.
我也试过我的配置用metadata-complete="false"
在我web.xml
,但还是没有成功.
这是我的web.xml和Servlet.
完整的示例代码可以在GitHub上找到.
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">
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<!-- http://stackoverflow.com/a/7924117/451634 -->
<!-- Put "-1" to disable this feature -->
<context-param>
<param-name>facelets.REFRESH_PERIOD</param-name>
<param-value>1</param-value>
</context-param>
<servlet>
<servlet-name>Faces Servlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Faces Servlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<!-- JSF -->
<listener>
<listener-class>org.apache.myfaces.webapp.StartupServletContextListener</listener-class>
</listener>
<!-- CDI -->
<listener>
<listener-class>org.apache.webbeans.servlet.WebBeansConfigurationListener</listener-class>
</listener>
</web-app>
Run Code Online (Sandbox Code Playgroud)
TestServlet.java …