当前位置: 代码迷 >> Java Web开发 >> JSP & servlet :javax.servlet.ServletException,该如何解决
  详细解决方案

JSP & servlet :javax.servlet.ServletException,该如何解决

热度:2348   发布时间:2016-04-10 22:36:06.0
JSP & servlet :javax.servlet.ServletException
新手刚开始学习JSP与servlet,不知道为什么总是报这个异常
javax.servlet.ServletException: Error instantiating servlet class com.soft.whdx.servlet.LoginSerlvet
下面是详细错误报告:
type Exception report

message Error instantiating servlet class com.soft.whdx.servlet.LoginSerlvet

description The server encountered an internal error that prevented it from fulfilling this request.

exception

javax.servlet.ServletException: Error instantiating servlet class com.soft.whdx.servlet.LoginSerlvet
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
root cause

java.lang.ClassNotFoundException: com.soft.whdx.servlet.LoginSerlvet
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1720)
org.apache.catalina.loader.WebappClassLoader.loadClass(WebappClassLoader.java:1571)
org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:501)
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:98)
org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:408)
org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1040)
org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:607)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2441)
org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2430)
java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:886)
java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:908)
java.lang.Thread.run(Thread.java:619)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.53 logs.

其中servlet源代码如下:
package com.soft.MyFirstWebProject.servlet;

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

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

import com.soft.MyFirstWebProject.service.IUserService;
import com.soft.MyFirstWebProject.service.UserServiceImpl;

@SuppressWarnings("serial")
public class LoginSerlvet extends HttpServlet {


private IUserService service=new UserServiceImpl();
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doPost(request,response);
}

 
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

 String uid=request.getParameter("uid");
 String pwd=request.getParameter("pwd");

 if (service.login(uid, pwd)){
  request.getRequestDispatcher("index.jsp").forward(request, response);
 }else{
  request.getRequestDispatcher("error.jsp").forward(request, response);
 }
 
 
}

}
servlet调用的login方法如下:
public class UserServiceImpl implements IUserService {

private DbHelperImpl dao=new DbHelperImpl();
public boolean login(String uid, String pwd) {
String sql="select count(*) n from userinfo where userid=? and userpwd=?";
Object[] params={uid,pwd};
Map row=dao.runSelect(sql, params)[0];
int n=Integer.parseInt(row.get("n").toString());
return n==1;
}

}




------解决方案--------------------
java.lang.ClassNotFoundException: com.soft.whdx.servlet.LoginSerlvet

找不到 。看看是否存在或者路径对不。
------解决方案--------------------
引用:
java.lang.ClassNotFoundException: com.soft.whdx.servlet.LoginSerlvet

找不到 。看看是否存在或者路径对不。


如果不存在,就可能是程序那行代码有错,没有编译成功
  相关解决方案