gpt4 book ai didi

java - Servlet 映射 Tomcat 错误 Eclipse

转载 作者:行者123 更新时间:2023-11-28 23:57:27 25 4
gpt4 key购买 nike

我正在尝试在 Eclipse 中进行 servlet 映射。使用注释来映射 servlet 似乎工作正常,但是当我尝试使用 web.xml 文件时,我遇到了问题。我也希望能够映射 jsp,因此我想在注释样式上使用 xml 文件。这是我在尝试将 servlet 映射添加到 web.xml 文件时遇到的错误。

“在本地主机上启动 Tomcat v8.0 服务器”遇到问题。本地主机上的服务器 Tomcat v8.0 服务器无法启动。

这是我的 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>

此外,这是我的文件结构的图像:

enter image description here

最佳答案

<servlet-class>标签只能采用完全限定的类名。所以这样做

<servlet>
<servlet-name>AController</servlet-name>
<servlet-class>controller.AController</servlet-class>
</servlet>

哪里controller是包名。

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.

这是 Servlet 3.0 规范的内容:

10.13 Inclusion of a web.xml Deployment Descriptor

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. In other words an application containing only static files or JSP pages does not require a web.xml to be present.

关于java - Servlet 映射 Tomcat 错误 Eclipse,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38038477/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com