在我的servlet代码中(在一个动态web项目中)有这样一行代码:
@WebServlet("/login")但是当我右键单击项目run-as,run -as在服务器上运行时,它会显示
http://localhost:8090/LoginServletApp/结果是404。我必须手动将url更改为
http://localhost:8090/LoginServletApp/login如何在默认情况下提供此url (即以“/login”结尾)?我做了一些查看,提到了一个名为web.xml的文件,它可以基于每个项目创建,但这似乎适用于物理文件;我要求eclipse生成一个部署描述符,它为我创建了这个文件:
<?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_4_0.xsd" version="4.0">
<display-name>LoginServletApp</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>
</web-app>提前感谢你,如果之前有人问过这个问题,我深表歉意(可能有,但我找不到解决方案)。
编辑:我将下面这行代码添加到web.xml文件中,但正如预期的那样,它不起作用:
<welcome-file>login.html</welcome-file>发布于 2018-08-13 09:55:20
根据欢迎文件列表中的条目,容器按顺序查找文件。因此,如果您将登录作为第一个添加到列表中,它将首先被提供,并且您将不会获得404。
<welcome-file-list>
<welcome-file>login</welcome-file>
..
</welcome-file-list>https://stackoverflow.com/questions/51814269
复制相似问题