html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>titletitle>
<link rel="stylesheet" type="text/css" href="style.css">
head>
<body>
<section>
<div>
<form action="Main_LoginServlet" method="post">
<p>
<button type="submit">登录button>
p>
form>
div>
section>
body>
html>
package main_Login;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;
import java.io.PrintWriter;
@WebServlet(name = "Main_LoginServlet", urlPatterns = "/Main_LoginServlet")
public class Main_LoginServlet extends HttpServlet {
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=utf-8");
PrintWriter out=response.getWriter();
out.println("a");
// RequestDispatcher requestDispatcher=request.getRequestDispatcher("/main_Login.html");
// requestDispatcher.forward(request,response);
}
}
html可以打开,但是Servlet打不开
①web.xml文件有修改过
<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>Main_LoginServletservlet-name>
<servlet-class>main_Login.Main_LoginServletservlet-class>
servlet>
<servlet-mapping>
<servlet-name>Main_LoginServletservlet-name>
<url-pattern>/Main_LoginServleturl-pattern>
servlet-mapping>
web-app>
②tomcat也懵懵懂懂试过
③相对路径改绝对路径也试过
能够正常让Servlet运行
回复错位置了 看一楼的评论