[英]Servlet Mapping Tomcat Error Eclipse
I am trying to do servlet mapping in Eclipse.我正在尝试在 Eclipse 中进行 servlet 映射。 Working with annotations to map the servlets seems to be working fine, but when I try to use the web.xml file I am getting problems.
Working with annotations to map the servlets seems to be working fine, but when I try to use the web.xml file I am getting problems. I would like to be able to map jsp's as well, hence why I want to use the xml file over the annotation style.
我也希望能够使用 map jsp,因此我想在注释样式上使用 xml 文件。 Here is the error I am encountering when trying to add a servlet mapping to the web.xml file.
这是我在尝试将 servlet 映射添加到 web.xml 文件时遇到的错误。
Here is my web.xml file:这是我的 web.xml 文件:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
id="WebApp_ID" version="3.1">
<display-name>Ryans Testing Project</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>AController</servlet-name>
<servlet-class>controller/AController</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>AController</servlet-name>
<url-pattern>/AController</url-pattern>
</servlet-mapping>
</web-app>
Also, here is an image of my file structure:另外,这是我的文件结构的图像:
<servlet-class>
tag can take only a fully qualified class name. <servlet-class>
标记只能采用完全限定的 class 名称。 So do it as所以这样做
<servlet>
<servlet-name>AController</servlet-name>
<servlet-class>controller.AController</servlet-class>
</servlet>
where controller
is a package name.其中
controller
是 package 名称。
I would like to be able to map jsp's as well, hence why I want to use the xml file over the annotation style.
我也希望能够使用 map jsp,因此我想在注释样式上使用 xml 文件。
Here is what the Servlet 3.0 specification says:这是 Servlet 3.0 规范所说的:
10.13 Inclusion of a web.xml Deployment Descriptor
10.13 包含 web.xml 部署描述符
A web application is NOT required to contain a web.xml if it does NOT contain any Servlet, Filter, or Listener components or is using annota tions to declare the same.
如果 web 应用程序不包含任何 Servlet、过滤器或声明侦听器组件或使用注释,则不需要包含 web.xml。 In other words an application containing only static files or JSP pages does not require a web.xml to be present.
换句话说,仅包含 static 文件或 JSP 页面的应用程序不需要 web.Z0F635D5ZE0F38764F to be present。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.