Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
469 views
in Technique[技术] by (71.8m points)

java - HTTP Status 500 - Error instantiating servlet class pkg.coreServlet

I am creating simple servlet and deploying it in tomcat server but I am getting the following error:

HTTP Status 500 - Error instantiating servlet class pkg.coreServlet

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:

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 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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Do not put the src folder in the WEB-INF directory!!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...