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