jsp:setProperty 能帮我解决的给下qq,解决了,绝对给分。。。拜托拜托
确定是<jsp:setPropertyname="DBBean"property="connStr"value="jdbc:odbc:vote"/>这里传value值进去...
确定是<jsp:setProperty name="DBBean" property="connStr"value="jdbc:odbc:vote"/> 这里传value值进去出错啦,遇到过同样问题的大哥请指教啊。郁闷ing
这是bean里面的代码:
package bean;
import java.sql.*;
public class DBBean {
private Connection con=null;
private Statement stmt=null;
private String connStr;
public DBBean()
{
BulidConnection();
}
public void BulidConnection() {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(connStr);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
public Connection getConnection()
{
if(con==null)
BulidConnection();
return con;
}
public void close()
{
try
{
con.close();
con=null;
}
catch(SQLException ex){}
}
public ResultSet excuteQuery(String sql)
{
ResultSet rs=null;
try
{
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex.getMessage());
}
return rs;
}
}
这是jsp页面的代码:
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<html>
<body>
<font size=6 color= blue>
通过Javabeans访问数据库
</font>
<jsp:useBean id="DBBean"scope="session"class="bean.DBBean"/>
<jsp:setProperty name="DBBean" property="connStr"value="jdbc:odbc:vote"/>
<%
ResultSet rs=DBBean.excuteQuery("SELECT vote.item FROM vote");
%>
<table bgcolor =red>
<td bgcolor=orange><b>电影名称</b></td>
<%
while(rs.next())
{
%>
<tr bgcolor =blue>
<td><%=rs.getString("item")%><br></td>
</tr>
<%
}
rs.close();
DBBean.close();
%>
</table>
</body>
</html>
错误内容是:
org.apache.jasper.JasperException: Cannot find any information on property 'connStr' in a bean of type 'bean.DBBean'
org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:365)
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
org.apache.jsp._1_jsp._jspService(_1_jsp.java:97)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 展开
这是bean里面的代码:
package bean;
import java.sql.*;
public class DBBean {
private Connection con=null;
private Statement stmt=null;
private String connStr;
public DBBean()
{
BulidConnection();
}
public void BulidConnection() {
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
con = DriverManager.getConnection(connStr);
}
catch(Exception ex)
{
System.out.println(ex.toString());
}
}
public Connection getConnection()
{
if(con==null)
BulidConnection();
return con;
}
public void close()
{
try
{
con.close();
con=null;
}
catch(SQLException ex){}
}
public ResultSet excuteQuery(String sql)
{
ResultSet rs=null;
try
{
stmt=con.createStatement();
rs=stmt.executeQuery(sql);
}
catch(SQLException ex)
{
System.out.println(ex.getMessage());
}
return rs;
}
}
这是jsp页面的代码:
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<html>
<body>
<font size=6 color= blue>
通过Javabeans访问数据库
</font>
<jsp:useBean id="DBBean"scope="session"class="bean.DBBean"/>
<jsp:setProperty name="DBBean" property="connStr"value="jdbc:odbc:vote"/>
<%
ResultSet rs=DBBean.excuteQuery("SELECT vote.item FROM vote");
%>
<table bgcolor =red>
<td bgcolor=orange><b>电影名称</b></td>
<%
while(rs.next())
{
%>
<tr bgcolor =blue>
<td><%=rs.getString("item")%><br></td>
</tr>
<%
}
rs.close();
DBBean.close();
%>
</table>
</body>
</html>
错误内容是:
org.apache.jasper.JasperException: Cannot find any information on property 'connStr' in a bean of type 'bean.DBBean'
org.apache.jasper.runtime.JspRuntimeLibrary.internalIntrospecthelper(JspRuntimeLibrary.java:365)
org.apache.jasper.runtime.JspRuntimeLibrary.introspecthelper(JspRuntimeLibrary.java:308)
org.apache.jsp._1_jsp._jspService(_1_jsp.java:97)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:393)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:320)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:266)
javax.servlet.http.HttpServlet.service(HttpServlet.java:803) 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询