jsp - 为什么我在 IntelliJ IDEA Ultimate 2020.2 的 JSP&servlet 中发现 404 错误?
问题描述
我正在 IntelliJ IDEA Ultimate 2020.2 中的 jsp 和 servlet 中创建简单的登录 Web 应用程序。
以下是我的 index.jsp
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>Calculator</title>
</head>
<body>
<form method="post" action="/LoginServlet">
UerName:<input type="text" name="t1"><br>
Password:<input type="text" name="t2"><br>
<input type="submit" value="Ok"><br>
</form>
</body>
</html>
这是我的小服务程序。它位于 src->main->java->francis
@WebServlet(name = "LoginServlet")
public class LoginServlet extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("Welcome.....");
}
}
Web.xml 是
<?xml version="1.0" encoding="UTF-8"?>
<web-app 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_4_0.xsd"
version="4.0">
<servlet>
<servlet-name>LoginServlet</servlet-name>
<servlet-class>francis.LoginServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>LoginServlet</servlet-name>
<url-pattern>/LoginServlet</url-pattern>
</servlet-mapping>
</web-app>
但是输出屏幕是...
请帮我。提前致谢
解决方案
代替
<form method="post" action="/LoginServlet">
和
<form method="post" action="LoginServlet">
会自动翻译成the-context-path/LoginServlet
. 请注意,您放入action
属性的路径是相对于上下文路径的。
推荐阅读
- java - 如何将一个类导入另一个类
- python - 使用 conda 和 pip 安装软件包
- python - 将 csv 单元格转换为嵌套列表
- python - 有没有办法在 Python 中创建相关变量来设置这些变量的标准偏差?
- vscode-settings - 复制和粘贴文件创建符号链接?如何让它创建一个文件呢?
- r - 如何在不导入所有函数的情况下在包中使用 data.table?
- flutter - 如何将 TextSpan 列表转换为单个文本?
- java - 在java中,在将命名变量添加到arraylist的同一行上创建/构造/定义命名变量的正确语法是什么?
- php - AttributeRepository::create($x) 必须兼容
- apt - 无法在 Ubuntu pyxis 容器中安装 update-notifier-common