【发布时间】:2015-05-29 17:28:33
【问题描述】:
规格 Tomcat 8.0.20,操作系统:win 7,Java:1.8
1) Servlet StartServletInit 扩展了 HttpServlet
2) StartServletInit 只有一种方法 "public void init(ServletConfig config)”,它在类路径中读取“属性文件”并打印 在控制台上控制注入的键/值对。
3) Web.xml 有如下标题条目
version="3.1"
**metadata-complete="false"**
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"
3) Web.xml 在启动时加载为
<servlet>
<servlet-name>StartServletInit</servlet-name>
<servlet-class>org.web.init.StartServletInit</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
O/p :完美执行并在控制台上打印。 ===> :)
问题
注释 [注释 web.xml 的 loadOnStartup 并注释代码] "@WebServlet(name = "StartServletInit",loadOnStartup = 1)
O/p :不 - 将键/值打印到控制台。 ===> :(
【问题讨论】:
-
为什么 web.xml 中有双星号?
标签: tomcat annotations servlet-3.0