尽管遵循了在线说明等,但Netbeans servlet错误仍然发生

问题描述

我最近不得不在班上使用Netbeans,在所有同学中,我是唯一一个遇到servlet问题的人。我将在下面放置index.html,web.xml和servlet类的代码。此外,HTTP Status 500错误将始终出现,并且在线说明对我的servlet没有帮助。我正在使用Tomcats 9.0,Netbeans 11.2。我还同时安装了JDK 14和8。我安装了8个导致“错误:选项-Xbootclasspath不允许目标14”的原因。我希望有人看到了这一点并可以对我有所帮助,谢谢!

index.html

<html>
<head>
    <title>title</title>
    <Meta charset="UTF-8">
    <Meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body>
    <div>Todo write content</div>
    <a href="ServletTest">click</a>
</body>
</html>

web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.1" 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_3_1.xsd">
<servlet>
    <servlet-name>ServletTest</servlet-name>
    <servlet-class>com.anothertest.ServletTest</servlet-class>
</servlet>
<servlet-mapping>
    <servlet-name>ServletTest</servlet-name>
    <url-pattern>/ServletTest</url-pattern>
</servlet-mapping>
<session-config>
    <session-timeout>
        30
    </session-timeout>
</session-config>
</web-app>

ServletTest.java

package com.anothertest;

import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.servletexception;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class ServletTest extends HttpServlet {


protected void processRequest(HttpServletRequest request,HttpServletResponse response)
        throws servletexception,IOException {
    response.setContentType("text/html;charset=UTF-8");
    try ( PrintWriter out = response.getWriter()) {
        /* Todo output your page here. You may use following sample code. */
        out.println("<!DOCTYPE html>");
        out.println("<html>");
        out.println("<head>");
        out.println("<title>Servlet ServletTest</title>");            
        out.println("</head>");
        out.println("<body>");
        out.println("<h1>Servlet ServletTest at " + request.getcontextpath() + "</h1>");
        out.println("</body>");
        out.println("</html>");
    }
}

@Override
protected void doGet(HttpServletRequest request,IOException {
    processRequest(request,response);
}

@Override
protected void doPost(HttpServletRequest request,response);
}

@Override
public String getServletInfo() {
    return "Short description";
}// </editor-fold>

}

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)