简体   繁体   English

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

[英]SEVERE: Allocate exception for servlet, error when trying to call a servlet from JSP page

When I run the jsp on the tomcat server and it runs ok, but when I click submit it throws the following error, I have checked over everything and I am not sure where to go from here because it seems like it should work, any help would be much appreciated, Thank you. 当我在tomcat服务器上运行jsp时,它运行正常,但是当我单击“提交”时,它会引发以下错误,我已经检查了所有内容,但我不确定从这里去哪里,因为它似乎应该可以工作,所以有任何帮助将不胜感激,谢谢。

Error Stack Trace: 错误堆栈跟踪:

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

The JSP page: 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>

The Servlet: 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);
    }
}

}

For anybody that has a similar problem in the future, after cleaning the project, ensure that the build automatically box is checked under the project drop down menu as this is required to rebuild after clean, mine was unchecked by default for some reason. 对于以后遇到类似问题的任何人,在清理项目后,请确保在项目下拉菜单下选中了“自动构建”框,因为清理后需要重新生成该框,默认情况下,我的出于某种原因未选中。

Also I made a small error in the code, I used annotations (@webservlet) in my servlet and I also added the servlet to my web.xml which caused a conflict. 另外,我在代码中犯了一个小错误,我在Servlet中使用了批注(@webservlet),并且还将servlet添加到了web.xml中,这导致了冲突。 This is now done automatically with annotations. 现在,这将自动通过注释完成。

I also got the same exception and resolved just by putting full qualified calssname in the web.xml fle. 我也遇到了同样的异常,只是通过将完整的合格calssname放在web.xml文件中来解决。 $fully qualified class name$ $完全合格的班级名称$

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM