高手救命呀javax.servlet.ServletException: Servlet execution threw an exception

月伴寒江 软件工程师  2012-07-27 11:58:01
困惑了我一上午。新手才开始学习jsp,求高手救命呀!

错误提示
HTTP Status 500 -

type Exception report

message

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

exception

javax.servlet.ServletException: Servlet execution threw an exception
root cause

java.lang.NoClassDefFoundError: bean/userBean
test.userservlet.doGet(userservlet.java:15)
test.userservlet.doPost(userservlet.java:40)
javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
note The full stack trace of the root cause is available in the Apache Tomcat/6.0.35 logs.

Apache Tomcat/6.0.35
...全文
5739 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
月伴寒江 2012-07-31
最后找到了是编译路径的问题。也就是包的引用路径。
回复
月伴寒江 2012-07-27
我的源文件是
userBean.java如下:
package bean;

import java.sql.*;

public class userBean
{
private String username;
private String userpass;
public userBean()
{

}
public userBean(String username,String userpass)
{
this.username=username;
this.userpass=userpass;
}

public void setUsername(String username)
{
this.username=username;

}
public void setUserpass(String userpass)
{
this.userpass=userpass;

}
public String getUsername()
{
return username;
}
public String getUserpass()
{
return userpass;
}

public boolean login() throws Exception
{
//return username.equals(userpass);
//Class.forName("MySQL ODBC 5.1 Driver");
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con=DriverManager.getConnection("jdbc:odbc:studydatabase","root","");
String sql="select * from usertable where username=? and userpass=?";
PreparedStatement stmt=con.prepareStatement(sql);
stmt.setString(1,username);
stmt.setString(2,userpass);
ResultSet rs=stmt.executeQuery();
boolean b=rs.next();
rs.close();
stmt.close();
con.close();
boolean b=false;
b=(username==userpass);
return b;
}

}




userservlet.java如下:
package test;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import bean.*;
//import test.*;

public class userservlet extends HttpServlet
{
public void doGet(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
String username=request.getParameter("username");
String userpass=request.getParameter("userpass");
boolean b=false;
try{
userBean user=new userBean();
user.setUsername(username);
user.setUserpass(userpass);


b=user.login();
//b=(username==userpass);
}
catch(Exception e){
response.setContentType("text/html;charset=gb2312");
PrintWriter out=response.getWriter();
out.println(e.toString());
return;
}
if(b){
RequestDispatcher rd=request.getRequestDispatcher("success.jsp");
rd.forward(request, response);
}
else{
RequestDispatcher rd=request.getRequestDispatcher("error.jsp");
rd.forward(request, response);
}
}
public void doPost(HttpServletRequest request,HttpServletResponse response)throws IOException,ServletException
{
doGet(request,response);
}
}

在其中我有引入bean包呀
回复
waitwinrandy 2012-07-27
java.lang.NoClassDefFoundError: bean/userBean 这个没有,
导致userservlet的DoGet和DoPost有问题,仔细看看。
回复
waitwinrandy 2012-07-27
java.lang.NoClassDefFoundError: bean/userBean 这个没有,
导致userservlet的DoGet和DoPost有问题,仔细看看。
回复
ydmmeiduo 2012-07-27
如果是新手刚开始学的话,我编码也才一年,但是能懂点,主要是理解项目是如何运行的,是至关重要的,项目的入口都是web.xml,然后再去找对应的servlet或者jsp,然后在jsp里可以写一些连接逻辑层的接口,再然后跳到那个action里,然后可以再那里再去调用一下数据库什么的,最后还可以以return 结束,跳到相应的界面
回复
licip 2012-07-27
java.lang.NoClassDefFoundError: bean/userBean
你的包没有引入进来。
回复
aa7229806 2012-07-27
你web.xml 文件没有配置好

<servlet-class>web.DerbyServlet</servlet-class>
class的话不能用/ 要用.
bean.userBean

下面是例子:
<web-app id="WebApp_ID">
<display-name>JavaDB</display-name>
<servlet>
<servlet-name>DerbyServlet</servlet-name>
<display-name>DerbyServlet</display-name>
<description></description>
<servlet-class>web.DerbyServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>DeleteServlet</servlet-name>
<display-name>DeleteServlet</display-name>
<description></description>
<servlet-class>web.DeleteServlet</servlet-class>
</servlet>
<servlet>
<servlet-name>InsertServlet</servlet-name>
<display-name>InsertServlet</display-name>
<description></description>
<servlet-class>web.InsertServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>DerbyServlet</servlet-name>
<url-pattern>/DerbyServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>DeleteServlet</servlet-name>
<url-pattern>/DeleteServlet</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>InsertServlet</servlet-name>
<url-pattern>/InsertServlet</url-pattern>
</servlet-mapping>
</web-app>
回复
LucEaspe 2012-07-27
bean/userBean 这个类 没有找到。
回复
相关推荐
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2012-07-27 11:58
社区公告
暂无公告