用JAVABEAN在JSP文件中说实例化异常,真是一团雾水,俩帮帮我,在线等~~~~~(50分)

  • 主题发起人 主题发起人 kkg
  • 开始时间 开始时间
K

kkg

Unregistered / Unconfirmed
GUEST, unregistred user!
出错信息:
javax.servlet.ServletException: class bbs.ltuser : java.lang.InstantiationException: bbs.ltuser
org.apache.jasper.runtime.PageContextImpl.handlePageException(PageContextImpl.java:682)
org.apache.jsp.userlist_jsp._jspService(userlist_jsp.java:70)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:294)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)

root cause
java.lang.InstantiationException: class bbs.ltuser : java.lang.InstantiationException: bbs.ltuser
org.apache.jsp.userlist_jsp._jspService(userlist_jsp.java:48)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:136)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:320)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:294)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
代码:
dbs.java
package bbs;
import java.sql.*;
import java.io.*;
public class dbs{
private Connection conn=null;

public Connection getconn(){
String url ="jdbc:mysql://localhost/ltxt?user=admin&password=admin&useUnicode=true&characterEncoding=8859_1";
try{
Class.forName("org.gjt.mm.mysql.Driver").newInstance();
conn=DriverManager.getConnection(url);
}catch(Exception ex){
ex.printStackTrace();
}
return conn;
}


public void closeconn(Connection conn){
try{
if(conn!=null) conn.close();
}catch(Exception ex){
ex.printStackTrace();
}
}

public void closestat(PreparedStatement stat){
try{
if(stat!=null) stat.close();
}catch(Exception ex){
ex.printStackTrace();
}
}

public void closestat(Statement stat){
try{
if(stat!=null) stat.close();
}catch(Exception ex){
ex.printStackTrace();
}
}

public void closers(ResultSet rs){
try{
if (rs!=null) rs.close();
}catch(Exception ex){
ex.printStackTrace();
}
}
}
--------------------------------------------------------------------
ltuser.java
package bbs;
import bbs.dbs;
import java.sql.*;
import java.io.*;
import java.util.*;
public class ltuser extends dbs {

private Connection conn=null;
private PreparedStatement prepstat=null;
private Statement stat=null;
private ResultSet rs=null;
private String sql=null;
private String username=null;
private String password=null;
private String mail=null;
private String ms="Welcome to Sixteenforum ";

public ltuser(String username,String password,String mail,String ms){
this.username=username;
this.password=password;
this.mail=mail;
if ( ms.length()>0 ) {
this.ms=ms;
};

}

public String getusername(){
return this.username;
}

public String getmail(){
return this.mail;
}

public String getms(){
return this.ms;
}

public String getpassword(){
return this.password;
}

public ArrayList userlist(){
ArrayList userlist=new ArrayList();
try{
conn=getconn();
sql="select * from users order by name";
stat=conn.createStatement();
rs=stat.executeQuery(sql);
while (rs.next()){
System.out.println(rs.getString("name"));
ltuser user=new ltuser(rs.getString("name"),rs.getString("psw"),rs.getString("mail")
,rs.getString("ms"));
userlist.add(user);
}
}catch(Exception ex){
ex.printStackTrace();
}finally{

closers(rs);
closestat(stat);
closeconn(conn);
}

return userlist;

}

public int insert(){
sql="insert into users (name,psw,mail,ms) values (?,?,?,?)";
try{
conn=getconn();
//conn.setAutoCommit(false);
prepstat=conn.prepareStatement(sql);
prepstat.setString(1,username);
prepstat.setString(2,password);
prepstat.setString(3,mail);
prepstat.setString(4,ms);
prepstat.executeUpdate();
closestat(prepstat);
closeconn(conn);
return 1;

}catch(Exception ex){
ex.printStackTrace();
closestat(prepstat);
closeconn(conn);
return -1;
}
}
}
dw中:
<%@ page contentType="text/html;
charset=gb2312" language="java" errorPage="" %>
<jsp:useBean id="myuser" scope="page" class="bbs.ltuser"/>
<html>
<head>
<title>Untitleddo
cument</title>
<meta http-equiv="Content-Type" content="text/html;
charset=gb2312">
</head>
<body>
</body>
</html>
 
你写一个构造函数,看看
 
确实是没有无参的构造函数
对与接口来说,在 interface 中定义都是一写抽象的类或属性,没有具体的方法,
在类中important 后,还是要从新定义方法,书上说JAVA不支持一个子类继承1个以上的
父类,为了解决这个问题,就有了接口,我想问,既然接口都不可以定义具体的方法,最后还
是要在子类中定义,那这个接口和在类中定义一个方法有什么不同呢!
难到是为了同一事物有同样的属性方法,但是具体不同,而写一个方法名一样但是具体方法在
具体的事物中定义!
一团雾水!不解~~~~~~~~
 
后退
顶部