m0_63191417 2022-11-10 14:48 采纳率: 0%
浏览 285

html跳转Servlet一直404,尝试多个办法无解

遇到问题:html跳转Servlet显示404
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>title</title>
    <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打不开

img

img

我的解答思路和尝试过的方法

img

①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>Main_LoginServlet</servlet-name>
        <servlet-class>main_Login.Main_LoginServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>Main_LoginServlet</servlet-name>
        <url-pattern>/Main_LoginServlet</url-pattern>
    </servlet-mapping>
</web-app>

②tomcat也懵懵懂懂试过

img

img

③相对路径改绝对路径也试过

img

我想要达到的结果

能够正常让Servlet运行

  • 写回答

2条回答 默认 最新

  • CSDN-Ada助手 CSDN-AI 官方账号 2022-11-10 16:55
    关注
    评论

报告相同问题?

问题事件

  • 创建了问题 11月10日

悬赏问题

  • ¥30 AVL fire DVI中的Design Explorer里面的Run的Status为什么总是Terminated?哪里出问题了?需要修改哪里?
  • ¥15 有二开IOT平台code的来搞钱了。
  • ¥15 求lingo语言编程以下内容
  • ¥15 cannot import name '_MissingValues' from 'sklearn.utils._param_validation'引用smoke
  • ¥15 求PHP跨站免登录技术
  • ¥15 AVL fire DVI中的Design Explorer里面的Objectives /Constraints的scale应该怎么设置
  • ¥15 qml如何绘制三维笛卡尔坐标系并向其中添加折线?
  • ¥15 treelib库有读取树数据方法吗?
  • ¥15 咨询一个PYTHON的问题
  • ¥15 机器学习建模调参,roc评价指标