一尘不染

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

tomcat

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

HTTP状态500-实例化servlet类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>

coreServlet.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来尝试,但出现了同样的错误。我在哪里做错了?


阅读 907

收藏
2020-06-16

共1个答案

一尘不染

不要将src文件夹放在WEB-INF目录中!!

2020-06-16