请教:这是什么问题,在线等
exception
org.apache.jasper.JasperException: Cannot find any information on property 'id ' in a bean of type 'inf.DB '
org.apache.jasper.runtime.JspRuntimeLibrary.getReadMethod(JspRuntimeLibrary.java:837)
org.apache.jasper.compiler.Generator$GenerateVisitor.visit(Generator.java:1011)
org.apache.jasper.compiler.Node$GetProperty.accept(Node.java:1062)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Node$Visitor.visitBody(Node.java:2213)
org.apache.jasper.compiler.Node$Visitor.visit(Node.java:2219)
org.apache.jasper.compiler.Node$Root.accept(Node.java:456)
org.apache.jasper.compiler.Node$Nodes.visit(Node.java:2163)
org.apache.jasper.compiler.Generator.generate(Generator.java:3270)
org.apache.jasper.compiler.Compiler.generateJava(Compiler.java:189)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:286)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:267)
org.apache.jasper.compiler.Compiler.compile(Compiler.java:255)
org.apache.jasper.JspCompilationContext.compile(JspCompilationContext.java:556)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:293)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:291)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:241)
javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
代码如下:
package inf;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
public class DB {
private static String url = "jdbc:microsoft:sqlserver://localhost:1433;databaseName=test ";
private static String driver = "com.microsoft.jdbc.sqlserver.SQLServerDriver ";
private static String userName = "sa ";
private static String password = "zhsoft ";
private static Connection conn = null;
private static Statement stmt = null;
static ResultSet rs = null;
static String id = null;
static String title = null;
static String content = null;
static String auther = null;
static String time = null;
static String keyword = null;
static String type = null;
public static String sql = "select * from news where type= '1 ' ";
public DB(){
try{
Class.forName(driver);
conn=DriverManager.getConnection(url,userName,password);
stmt = conn.createStatement();
}
catch (Exception e) {
e.printStackTrace();
}
}
public ResultSet Query() throws SQLException{
try {
rs = stmt.executeQuery(sql);
} catch (SQLException e) {
e.printStackTrace();
}
while(rs.next())
{
id = rs.getString(1);
title = rs.getString(2);
content = rs.getString(3);
auther = rs.getString(4);
time = rs.getString(5);
keyword = rs.getString(6);
type = rs.getString(7);
System.out.println(id+ " "+title+ " "+content+ " "+auther+ " "+time+ " "+keyword+ " "+type);
}
return null;
}
/*int Update(int row){
try {
row = stmt.executeUpdate(sql);
} catch (SQLException e) {
//
e.printStackTrace();
}
return row;
}
public String getSql(String para,String tab) {
sql = "select "+ " "+para+ " "+ "from "+ " "+tab;
return sql;
}
public void setSql(String para,String tab) {
this.sql = "select "+ " "+para+ " "+ "from "+ " "+tab;
}*/
}
jsp 代码如下:
<%@ page language= "java " contentType= "text/html; charset=ISO-8859-1 "
pageEncoding= "ISO-8859-1 "%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN " "http://www.w3.org/TR/html4/loose.dtd ">
<html>
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=ISO-8859-1 ">
<title> Insert title here </title>
</head>
<body>
<jsp:useBean id= "news " class= "inf.DB "> </jsp:useBean>
<jsp:getProperty name= "news " property= "id "/>
<jsp:getProperty name= "news " property= "title "/>
<jsp:getProperty name= "news " property= "content "/>
<jsp:getProperty name= "news " property= "auther "/>
<jsp:getProperty name= "news " property= "time "/>
<jsp:getProperty name= "news " property= "keyword "/>
<jsp:getProperty name= "news " property= "type "/>
!-- <%=news.Query()%> ;
</body>
</html>
[解决办法]
<jsp:getProperty name= "news " property= "id "/>
对于这句话要有public String getId()方法,否则是读取不到这个属性值的,这是javaBean规范!
要看书!!!!