使用java.lang.ClassNotFoundException的第一个HelloWorld servlet

时间:2017-11-04 17:40:57

标签: servlets java-ee

在逐步完成所有教程后,我的第一个HelloWorld不像教程那样工作。我有这个错误:

  

java.lang.ClassNotFoundException:pl.random.servlets.HelloWorldServlet

我的档案:

的web.xml:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" id="WebApp_ID" version="3.0">
 <servlet>
    <servlet-name>HelloWorld</servlet-name>
    <servlet-class>pl.random.servlets.HelloWorldServlet</servlet-class>
  </servlet>
  <servlet-mapping>
    <servlet-name>HelloWorld</servlet-name>
    <url-pattern>/test</url-pattern>
  </servlet-mapping>
</web-app>

HelloWorldServlet.java

package pl.random.servlets;

import java.io.PrintWriter;
import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

public class HelloWorldServlet extends HttpServlet{

    public static final long serialVersionUID = 102831973239L;

    public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        PrintWriter out = response.getWriter();
        out.print("Hello World");

}}

这里是我的项目资源管理器:

descriptionImage

0 个答案:

没有答案