找不到Tomcat类 - Servlet

时间:2013-08-08 21:01:40

标签: eclipse tomcat servlets

我在通过Eclipse和Tomcat部署基本Web应用程序时遇到了一个奇怪的问题

错误 -

SEVERE: Allocate exception for servlet DeCommServlet

java.lang.ClassNotFoundException: com.authentication.DeCommServlet
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1714)

但是,应用程序仍然可以访问DeCommServlet doPost()方法,并且tomcat保持部署但出现该错误。

的Servlet

    <servlet>
    <servlet-name>DeCommServlet</servlet-name>
    <servlet-class>com.authentication.DeCommServlet</servlet-class>
</servlet> 

<!--  Servlet Mappings -->

<servlet-mapping>
    <servlet-name>DeCommServlet</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping> 

servlet类是正确的链接但仍然出现此错误。我在任何lib文件夹中都没有任何内容,但在应用程序属性中,我在Build Path&gt;&gt;中添加了Apache Tomcat Lib。库

有没有人见过这个?

DeCommServlet代码:

@WebServlet("/DeCommServlet")
public class DeCommServlet extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
 * @see HttpServlet#HttpServlet()
 */
public DeCommServlet() {
    super();
    // TODO Auto-generated constructor stub
}

/**
 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doGet(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    System.out.println("sdf");
    System.out.println("ddd");
}

/**
 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
 *      response)
 */
protected void doPost(HttpServletRequest request,
        HttpServletResponse response) throws ServletException, IOException {
    // TODO Auto-generated method stub
    request.getUserPrincipal().getName();   
    response.sendRedirect("http://www.google.com"); 
}

新课程路径1

2 个答案:

答案 0 :(得分:1)

这就是你的webapp的样子:

> DeCommGlobal
> |-->src
>      |-->com
>           |-->authentication
>                      |-->DeCommServlet.java
> |-->META-INF
> |-->WEB-INF
>     |-->classes
>     |-->lib

答案 1 :(得分:0)

导致问题的是部署程序集。添加了lib文件夹,我们很高兴!感谢