gpt4 book ai didi

java - HTTP 状态 500 - 实例化 servlet 类 pkg.coreServlet 时出错

转载 作者:搜寻专家 更新时间:2023-10-30 21:39:36 24 4
gpt4 key购买 nike

我正在创建简单的 servlet 并将其部署到 tomcat 服务器中,但出现以下错误:

HTTP Status 500 - Error instantiating servlet class pkg.coreServlet

tomcat服务器上的文件结构:

webapps     
|
- aarya
|
- WEB-INF
|
-web.xml
-src(folder)
|
-pkg
|
-coreServlet.class

web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">


<servlet>
<servlet-name>aaryaservlet</servlet-name>
<servlet-class>pkg.coreServlet</servlet-class>
</servlet>

<servlet-mapping>
<servlet-name>aaryaservlet</servlet-name>
<url-pattern>/coreServlet</url-pattern>
</servlet-mapping>
</web-app>

核心Servlet.java:

package pkg;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class coreServlet extends HttpServlet
{
/**
*
*/
private static final long serialVersionUID = 1L;

public void doGet(HttpServletRequest req,HttpServletResponse res)
throws ServletException,IOException


{
PrintWriter out = res.getWriter();
res.setContentType("text/html");
out.println("this is First servlet Example ");
}
}

我给的 url 是 http://localhost:8080/aarya/coreServlet我尝试重新启动 tomcat,但出现了同样的错误。我哪里做错了?

最佳答案

不要把src文件夹放在WEB-INF目录下!!

关于java - HTTP 状态 500 - 实例化 servlet 类 pkg.coreServlet 时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15921540/

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