SEVERE:为servlet分配异常,尝试从JSP页面调用servlet时出错

时间:2014-04-16 20:00:25

标签: java jsp tomcat servlets

当我在tomcat服务器上运行jsp并运行正常时,但是当我点击提交时它会抛出以下错误,我检查了所有内容,我不知道从哪里开始,因为它似乎应该工作,任何帮助将不胜感激,谢谢。

错误堆栈跟踪:

SEVERE: Allocate exception for servlet RegistrationServlet
java.lang.ClassNotFoundException: logon.RegistrationServlet.java
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
at org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
at org.apache.catalina.core.DefaultInstanceManager.loadClass(DefaultInstanceManager.java:529)
at org.apache.catalina.core.DefaultInstanceManager.loadClassMaybePrivileged(DefaultInstanceManager.java:511)
at org.apache.catalina.core.DefaultInstanceManager.newInstance(DefaultInstanceManager.java:139)
at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:864)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:134)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:315)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)

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" 
xmlns:web="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_2_5.xsd" 
id="WebApp_ID" version="2.5">
<display-name>RegistrationTest</display-name>
 <servlet>
        <display-name>RegistrationServlet</display-name>
        <servlet-name>RegistrationServlet</servlet-name>
        <servlet-class>logon.RegistrationServlet</servlet-class>
 </servlet>
 <servlet-mapping>
     <servlet-name>RegistrationServlet</servlet-name>
     <url-pattern>/RegistrationServlet</url-pattern>
 </servlet-mapping>
</web-app>

JSP页面:

<h2>Signup Details</h2>
        <form name="actionForm" action="RegistrationServlet" method ="post">
        <br/>Username:<input type="text" name="name">
        <br/>Password:<input type="password" name="password">
        <br/>Email:<input type="text" name="email">
        <br/><input type="submit" value="Submit">
        </form>

Servlet:

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

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

public RegistrationServlet() {
    super();

}


protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

}


protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    try{
        System.out.println("In the registration Servlet");
        User user = new User();
        user.setName(request.getParameter("name"));
        user.setPassword(request.getParameter("password"));
        user.setEmail(request.getParameter("email"));
        RegisterUser.addUser(user);
        //response.sendRedirect("welcome.jsp");        
    } catch (Throwable exc)
    {
        System.out.println(exc);
    }
}

}

2 个答案:

答案 0 :(得分:3)

对于将来遇到类似问题的任何人,在清理项目后,确保在项目下拉菜单下选中自动构建框,因为这需要在清理后重建,默认情况下我的默认情况下未选中。

此外,我在代码中犯了一个小错误,我在servlet中使用了注释(@webservlet),并且我还将servlet添加到我的web.xml中,这导致了冲突。现在使用注释自动完成。

答案 1 :(得分:0)

我也得到了同样的异常并且只是通过在web.xml文件中放入完全限定的calssname来解决。 $完全合格的班级名称