2
212
Unregistered / Unconfirmed
GUEST, unregistred user!
我的处理是jsp初使页面调用add.jsp,add.jsp调用两个javabean.分别是连接数据库和插入数据库
javabean,执行后报错如下:
Error: 500
Location: /zx/jsp/add.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for JSPC:/tomcat/work/localhost_8080%2Fzx/_0002fjsp_0002fzx_00031_0002ejspzx1_jsp_0.java:74: Can't make static reference to method void insertRecord(java.lang.String, java.lang.String) in class testbean.ExecSql.
ExecSql.insertRecord(testno,testname);
^
代码如下:
初使页面default.jsp:
<html>
<head>
<title>正在测试</title>
</head>
<body bgcolor="white">
<font size = 5 color="#0000FF">
<form type=POST action=zx1.jsp>
<br>
请增加或删除:
<br>
编号:
<input type=text name=userid size=10>
<br>
姓名:
<INPUT TYPE=text name=username size=10>
<br> <br>
<INPUT TYPE=submit name="submit" value="增加">
<INPUT TYPE=reset name="reset" value="取消">
</form>
</FONT>
</body>
</html>
处理增加add.jsp
<%@ page contentType="text/html;
charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="testbean.*"%>
<jsp:userBean id="exec" class="testbean.ExecSql" scop="page">
<%
String testno;
String testname;
testno=(String)request.getParameter("userid");
testname=(String)request.getParameter("username");
ExecSql.insertRecord(testno,testname);
/*response.sendRedirect("zx1.jsp");*/
%>
连接处理javabean
package testbean;
import java.sql.*;
public class DBConnection
{
private String DBConnect="jdbcdbc:jsptest";
private String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private String DBUser="zx";
private String DBPwd="zx";
private ResultSet rs=null;
private Connection Conn=null;
public DBConnection()
{
}
public String DBConnect()
{
String strExc="";
try
{
Class.forName(DBDriver);
Conn=DriverManager.getConnection(DBConnect,DBUser,DBPwd);
}
catch(ClassNotFoundException e)
{
strExc=e.toString();
}
catch(SQLException e)
{
strExc=e.toString();
}
return(strExc);
}
public void setDBConnect(String location )
{
DBConnect=location;
}
public void setDBDriver(String driver)
{
DBDriver=driver;
}
public void setConn(Connection conn)
{
Conn=conn;
}
public String getDBConnection()
{
return(DBConnect);
}
public String getDBDriver()
{
return(DBDriver);
}
public Connection getConn()
{
return(Conn);
}
public ResultSet getRs()
{
return(rs);
}
}
增加处理javabean
package testbean;
import java.sql.*;
import java.io.*;
public class ExecSql
{
private Connection conn=null;
private DBConnection dbConn=null;
private int concurType=ResultSet.CONCUR_READ_ONLY;
private int scrollType=ResultSet.TYPE_FORWARD_ONLY;
public ExecSql()
{
}
public ExecSql(DBConnection dbConn)
{
this.dbConn=dbConn;
}
private void createConnection()
{
if (conn==null)
{
if (dbConn==null)
{
dbConn=new DBConnection();
dbConn.DBConnect();
}
conn=dbConn.getConn();
}
}
public void insertRecord(String testid, String testname)
{
String sql;
byte[] temp={1};
sql="insert into zx.zx value('testid ',' testname')";
try
{
temp=sql.getBytes("iso-8859-1");
}
catch(UnsupportedEncodingException e)
{
}
String sqlCStr=new String(temp);
try
{
if (conn==null)
{
createConnection();
}
if (conn==null)
return;
else
{
Statement s=conn.createStatement(scrollType,concurType);
s.executeUpdate(sqlCStr);
}
}
catch (SQLException e)
{
}
}
}
麻烦各位大虾了,我很急[[blue][/blue]
javabean,执行后报错如下:
Error: 500
Location: /zx/jsp/add.jsp
Internal Servlet Error:
org.apache.jasper.JasperException: Unable to compile class for JSPC:/tomcat/work/localhost_8080%2Fzx/_0002fjsp_0002fzx_00031_0002ejspzx1_jsp_0.java:74: Can't make static reference to method void insertRecord(java.lang.String, java.lang.String) in class testbean.ExecSql.
ExecSql.insertRecord(testno,testname);
^
代码如下:
初使页面default.jsp:
<html>
<head>
<title>正在测试</title>
</head>
<body bgcolor="white">
<font size = 5 color="#0000FF">
<form type=POST action=zx1.jsp>
<br>
请增加或删除:
<br>
编号:
<input type=text name=userid size=10>
<br>
姓名:
<INPUT TYPE=text name=username size=10>
<br> <br>
<INPUT TYPE=submit name="submit" value="增加">
<INPUT TYPE=reset name="reset" value="取消">
</form>
</FONT>
</body>
</html>
处理增加add.jsp
<%@ page contentType="text/html;
charset=gb2312"%>
<%@ page import="java.sql.*"%>
<%@ page import="testbean.*"%>
<jsp:userBean id="exec" class="testbean.ExecSql" scop="page">
<%
String testno;
String testname;
testno=(String)request.getParameter("userid");
testname=(String)request.getParameter("username");
ExecSql.insertRecord(testno,testname);
/*response.sendRedirect("zx1.jsp");*/
%>
连接处理javabean
package testbean;
import java.sql.*;
public class DBConnection
{
private String DBConnect="jdbcdbc:jsptest";
private String DBDriver="sun.jdbc.odbc.JdbcOdbcDriver";
private String DBUser="zx";
private String DBPwd="zx";
private ResultSet rs=null;
private Connection Conn=null;
public DBConnection()
{
}
public String DBConnect()
{
String strExc="";
try
{
Class.forName(DBDriver);
Conn=DriverManager.getConnection(DBConnect,DBUser,DBPwd);
}
catch(ClassNotFoundException e)
{
strExc=e.toString();
}
catch(SQLException e)
{
strExc=e.toString();
}
return(strExc);
}
public void setDBConnect(String location )
{
DBConnect=location;
}
public void setDBDriver(String driver)
{
DBDriver=driver;
}
public void setConn(Connection conn)
{
Conn=conn;
}
public String getDBConnection()
{
return(DBConnect);
}
public String getDBDriver()
{
return(DBDriver);
}
public Connection getConn()
{
return(Conn);
}
public ResultSet getRs()
{
return(rs);
}
}
增加处理javabean
package testbean;
import java.sql.*;
import java.io.*;
public class ExecSql
{
private Connection conn=null;
private DBConnection dbConn=null;
private int concurType=ResultSet.CONCUR_READ_ONLY;
private int scrollType=ResultSet.TYPE_FORWARD_ONLY;
public ExecSql()
{
}
public ExecSql(DBConnection dbConn)
{
this.dbConn=dbConn;
}
private void createConnection()
{
if (conn==null)
{
if (dbConn==null)
{
dbConn=new DBConnection();
dbConn.DBConnect();
}
conn=dbConn.getConn();
}
}
public void insertRecord(String testid, String testname)
{
String sql;
byte[] temp={1};
sql="insert into zx.zx value('testid ',' testname')";
try
{
temp=sql.getBytes("iso-8859-1");
}
catch(UnsupportedEncodingException e)
{
}
String sqlCStr=new String(temp);
try
{
if (conn==null)
{
createConnection();
}
if (conn==null)
return;
else
{
Statement s=conn.createStatement(scrollType,concurType);
s.executeUpdate(sqlCStr);
}
}
catch (SQLException e)
{
}
}
}
麻烦各位大虾了,我很急[[blue][/blue]