我正在js和IntelliJ IDEA Ultimate 2020.2中的servlet中创建简单的Login 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>
这是我的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
属性的路径是相对于上下文路径的。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句