本文介绍了HTTP 状态 500 - 实例化 servlet 类 pkg.coreServlet 时出错的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在创建简单的 servlet 并将其部署在 tomcat 服务器中,但出现以下错误:
I am creating simple servlet and deploying it in tomcat server but I am getting the following error:
HTTP 状态 500 - 实例化 servlet 类 pkg.coreServlet 时出错
tomcat 服务器上的文件结构:
File Structure on the tomcat server:
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:
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 ");
}
}
我给的网址是 http://localhost:8080/aarya/coreServlet
我尝试重新启动 tomcat,但出现相同的错误.我哪里做错了?
url I am giving is http://localhost:8080/aarya/coreServlet
I try by restarting tomcat but I am getting same error. Where I am doing wrong?
推荐答案
不要把src文件夹放在WEB-INF目录下!!
Do not put the src folder in the WEB-INF directory!!
这篇关于HTTP 状态 500 - 实例化 servlet 类 pkg.coreServlet 时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!