为什么我在 IntelliJ IDEA Ultimate 2020.2 的 JSP&servlets 中收到 404 found error?
Why i am getting 404 found error in JSP&servlets in IntelliJ IDEA Ultimate 2020.2?
我正在 jsp 中创建简单的登录 Web 应用程序,并在 IntelliJ IDEA Ultimate 2020.2 中创建 servlet。
以下是我的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>
这是我的 servlet。它位于 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
属性的路径是相对于上下文路径的。
我正在 jsp 中创建简单的登录 Web 应用程序,并在 IntelliJ IDEA Ultimate 2020.2 中创建 servlet。
以下是我的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>
这是我的 servlet。它位于 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
属性的路径是相对于上下文路径的。