当前位置: 首页 > 知识库问答 >
问题:

HTTP状态500-内部服务器错误(Java、Eclipse、Servlets、Tomcat)

须衡虑
2023-03-14
package xxx.xxx;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class SearchServlet extends HttpServlet {

    private static final long serialVersionUID = 1L;

    public void service(HttpServletRequest req, HttpServletResponse res) throws IOException {

        String str = req.getParameter("str_search");

        PrintWriter out = res.getWriter();

        out.println(str);

    }

}
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd" id="WebApp_ID" version="3.1">
    <servlet>
        <servlet-name>search</servlet-name>
        <servlet-class>SearchServlet</servlet-class>
    </servlet>
    <servlet-mapping>
        <servlet-name>search</servlet-name>
        <url-pattern>/search</url-pattern>
    </servlet-mapping>
</web-app>
HTTP Status 500 – Internal Server Error

Type Exception Report

Message Error instantiating servlet class [SearchServlet]

Description The server encountered an unexpected condition that prevented it from fulfilling the request.

Exception

javax.servlet.ServletException: Error instantiating servlet class [SearchServlet]
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:748)
Root Cause

java.lang.ClassNotFoundException: SearchServlet
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1360)
    org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1182)
    org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:528)
    org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
    org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:678)
    org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343)
    org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:798)
    org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
    org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:810)
    org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1500)
    org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    java.lang.Thread.run(Thread.java:748)
Note The full stack trace of the root cause is available in the server logs.

Apache Tomcat/8.5.47

我想知道这是否与Eclipse安装到权限有关,或者可能与项目结构有关?有人有线索吗?也许我应该寻找一个容器映像或其他东西来尝试在其上构建?多谢了。

共有1个答案

赵钊
2023-03-14

只需在 标记中添加类的全限定名。

示例:

<servlet-class>com.stack.SearchServlet</servlet-class>

或者如果您愿意:

package com.stack;    

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;    

/**
 * Servlet implementation class MyServlet
 */
@WebServlet("/MyServlet")
public class MyServlet extends HttpServlet {
    private static final long serialVersionUID = 1L;

    /**
     * @see HttpServlet#HttpServlet()
     */
    public MyServlet() {
        super();
        // TODO Auto-generated constructor stub
    }    

    /**
     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        response.getWriter().append("Served at: ").append(request.getContextPath());
    }    

    /**
     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
     */
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        // TODO Auto-generated method stub
        doGet(request, response);
    }    

}
 类似资料:
  • 当我尝试使用JSP运行我的Web应用程序(基本CRUD)时,GlassFish服务器返回以下消息: HTTP状态500-内部服务器错误 类型异常报告 消息内部服务器错误 说明服务器遇到内部错误,无法满足此请求。 例外 java.lang.NullPointerException 注意GlassFish Server Open Source Edition 4.1日志中提供了异常及其根本原因的完整堆

  • 下面是我的一部分。jsp。 下面是我的错误: HTTP状态500–内部服务器错误 类型异常报告 消息在行[20]处处理[/home.jsp]时发生异常 说明服务器遇到意外情况,无法满足请求。 例外组织。阿帕奇。贾斯珀。JasperException:在第[20]行处理[/home.jsp]时发生异常 17:这是添加信息页 18: Stacktrace:org。阿帕奇。贾斯珀。servlet。Jsp

  • 当我尝试使用JSP运行我的Web应用程序时,GlassFish服务器返回以下消息: 我不知道该怎么办。我认为这个错误与找不到javax有关。servlet。jsp。jstl。glassfish服务器中的jar库

  • 这是我从mysql数据库中删除数据的代码,我得到了这个错误。 在我选择名称并尝试提交后...它给我这个错误 HTTP状态500-内部服务器错误 类型异常报告 Message内部服务器错误 描述服务器遇到内部错误,无法满足此请求。 例外 组织。阿帕奇。贾斯珀。JaspereException:java。lang.NumberFormatException:空根本原因 JAVAlang.NumberF

  • 我正在学习JAX-RS,在发出生成JSON的GET请求时,出现HTTP Status 500内部服务器错误。XML工作正常。 我搜索了其他问题,但找不到解决方案。这可能是因为我目前缺乏知识。然而,据我所知,有人建议我的项目在构建路径中缺少一个JAR。 我没有使用Maven。我刚刚在Eclipse中创建了一个动态Web应用程序,并将JAX-RS/jerjar添加到我的WEB-INF/lib目录中,并

  • null HTTP状态500-内部服务器错误 请解决这个错误,我也尝试了java JDK6版本,但它不起作用