gpt4 book ai didi

java - "HTTP status 500 - Internal server error"作为通过服务器上传文件

转载 作者:行者123 更新时间:2023-12-02 04:12:23 26 4
gpt4 key购买 nike

我正在尝试通过本地主机服务器上传文件,但在运行该文件时出现内部服务器错误“实例化 servlet 类时出错”。

我已经在fileupload包下的UploadServelet.java类中编写了通过服务器上传文件的代码,并且还在web.xml文件中完成了servlet的映射”,但仍然收到错误。

<小时/>

Index.jsp

<div class="container">
<form method="POST" action="upload" enctype="multipart/form-data">

<label for="fname"> Select Input File: </label>
<input type="file" name="myFile" id="myFile" /> <br/>
<input type="submit" value="upload" name="upload" id="upload" />

</form>
</div>
<小时/>

Web.xml

<?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_4_0.xsd" version="4.0">
<display-name>Circedb</display-name>

<servlet>
<servlet-name>UploadServelet</servlet-name>
<servlet-class>src.fileupload.UploadServelet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>UploadServelet</servlet-name>
<url-pattern>/upload</url-pattern>
</servlet-mapping>
<session-config>
<session-timeout>
30
</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>

错误日志:类型异常报告消息实例化 Servlet 类 [src.fileupload.UploadServelet] 时出错描述 服务器遇到意外情况,无法满足请求。

异常

javax.servlet.ServletException: Error instantiating servlet class [src.fileupload.UploadServelet]
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
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:408)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1747)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)

根本原因

java.lang.ClassNotFoundException: src.fileupload.UploadServelet
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1363)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1186)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:490)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:92)
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:408)
org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:836)
org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1747)
org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
java.lang.Thread.run(Unknown Source)

注意根本原因的完整堆栈跟踪可在服务器日志中找到。

最佳答案

UploadServelet是否正确编译并上传

您需要通过删除 src 来更新其包:

 <servlet-class>fileupload.UploadServelet</servlet-class>

关于java - "HTTP status 500 - Internal server error"作为通过服务器上传文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56681492/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com