怎么显示不出来数据呀!高手请进!

magie16036936 2004-08-30 06:22:17

这个是bean !
package test;
import test.jdbc;
import java.sql.*;

public class Staff extends jdbc {
String m_id,m_name,m_country;//,m_sex,m_birth,m_phone,m_mobile,m_address,m_zip,
//m_email;
private String e_name;
//private String password;
private String e_id;
private String country;
// private String sex;
// private String dep;
// public void setDep(String s){dep=s;}
// public String getDep(){return dep;}
// public void setSex(String s){sex=s;}
// public String getSex(){return sex;}
public String getE_id() {
return e_id;
}
public void setE_id(String e_id) {
this.e_id = e_id;
}
public String getE_name() {
return e_name;
}
public void setE_name(String e_name) {
this.e_name = e_name;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country= country;
}
// public String getJiguan() {
// return jiguan;
// }
// public void setJiguan(String jiguan) {
// this.jiguan = jiguan;
// }
// public boolean hasLogin(String id){ //检查该学生是否已经注册
// boolean f=true;
// String sql="select id from student where id ='"+id+"'";
// sqlBean db =new sqlBean();
// try{
// ResultSet rs=db.executeQuery(sql);
// if(rs.next()){ f=false;}
// else{ f=true;}
// }catch(Exception e){ e.getMessage();}
// return f;
// }

public ResultSet getStaff()
{
String sql="select * from employees";
ResultSet rs = this.executeQuery(sql);
try{
while(rs.next())
{
this.m_id=rs.getString("E_id");
this. m_name=rs.getString("E_name");
this.m_country=rs.getString("Country");
//System.out.println(m_country);
//m_sex=rs.getString("sex");
//m_birth=rs.getString("birth_date");
//m_phone=rs.getString("phone");
//m_mobile=rs.getString("mobile");
//m_address=rs.getString("address");
//m_zip=rs.getString("zip");
//m_email=rs.getString("email");
//rs.close();
}

}catch(SQLException ex) {
System.err.println(ex.getMessage());
}
return rs;
}
public ResultSet getList(){
String getSql="select * from employees ";


try{
if (m_id==null) m_id ="";
if (m_name==null) m_name ="";
if (m_country == null) m_country = "";
if (!(m_id.trim().equals("")))
getSql = " and m_id ='"+e_id+"'";
if (!(m_name.trim().equals("")))
getSql = " and m_name ='"+e_name+"'";
if (!(m_country.trim().equals("")))
getSql = " and m_country='"+country+"'";
rs = this.executeQuery(getSql);

}catch(Exception e) {
System.err.println(e.getMessage());
}
return rs;
}
//public int updateStaff()
//{
// String sql="update employees set e_name='"+e_name+"',country='"+country+"' where e_id='"+e_id+"' ";
// System.out.print(sql);
//jdbc db= new jdbc();
// return db.executeInsert(sql);
//
// }

public void deleteStaff(){

String sql="delete from employees where e_id ='"+m_id+"' ";

this.executeDelete(sql);
}

public int deleteStaff(String e_id){
int num=0;
String sql="delete from employees where e_id ='"+m_id+"' ";

num=this.executeDelete(sql);
return num;
}
public void addStaff() {
String sql="insert into employees (e_name,country,e_id) "+
"VALUES('"+e_name+"','"+country+"','"+e_id+"')";


this.executeInsert(sql);
}

public String getM_id(){
return m_id;
}

public String getM_name(){
return m_name;
}
public String getM_country(){
return m_country;
}
//public String getM_sex(){
// return m_sex;
//}
//public String getM_birth(){
// return m_birth;
//}
//public String getM_phone(){
// return m_phone;
//}
//public String getM_mobile(){
// return m_mobile;
//}
//public String getM_address(){
// return m_address;
// }
//public String getM_zip(){
// return m_zip;
// }
//public String getM_email(){
// return m_email;
// }

}
这个是jsp的页面!
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="errorpage.jsp" %>
<%@ page import="test.jdbc"%>
<%@page import="test.Staff"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>所有yuangong</title>
</head>
<body bgcolor="#0099FF" text="#FFFFFF" link="#00FF00">
<jsp:useBean id="Staff" scope="page" class="test.Staff">
<jsp:setProperty name="staff" property="*"/>
</jsp:useBean>
<div align="center">
<p>
<font color="#00FF00" size="+3" face="方正舒体">所有员工</font> </p>
<p> </p>
<p align="left"><a href="addstaff.jsp"><font size="+1" face="方正舒体"><strong>新增员工</strong></font></a></p>
</div>
<div align="center">
<table width="75%" border="1">
<tr>
<td>员工号</td>
<td>姓名</td>
<td>国籍</td>
<td>删除</td>
<td>更新</td>
</tr>
<%
Staff newStaff=new Staff();
ResultSet rs=newStaff.getStaff();
while(rs.next()) {
String m_id=rs.getString("e_id");
String m_name=rs.getString("e_name");
String m_country=rs.getString("country");
System.out.println(m_name);
%>
<tr>
<td><%=m_id%></td>
<td><%=m_name%></td>
<td><%=m_country%></td>
<td><a href="StaffSvlt?action=delete&e_id=<%=m_id%>">删除</a></td>
<td><a href="updatesta.jsp?e_id=<%=m_id%> ">更新</a></td>
</tr>
<%
}
%>
</table>
</div>
<p align="left"><a href="admin.jsp">BackTo Admin</a></p>
</body>
</html>
!是不是bean里的循环出了问题!
...全文
71 点赞 收藏 8
写回复
8 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
steveyue 2004-08-31
问题多多,在jsp里既然<jsp:useBean id="Staff" scope="page" class="test.Staff">
<jsp:setProperty name="staff" property="*"/>(属性到底是什么,怎么没赋值)
</jsp:useBean>为什么后面还要Staff newStaff=new Staff();
<%
Staff newStaff=new Staff();
ResultSet rs=newStaff.getStaff();
while(rs.next()) {
String m_id=rs.getString("e_id");
String m_name=rs.getString("e_name");
String m_country=rs.getString("country");
System.out.println(m_name);
%>
m_id,m_name,m_country应该用newStaff的方法来取值。
还有就是BEAN问题了
public ResultSet getList(){
String getSql="select * from employees ";


try{
if (m_id==null) m_id ="";
if (m_name==null) m_name ="";
if (m_country == null) m_country = "";
if (!(m_id.trim().equals("")))
getSql = " and m_id ='"+e_id+"'";
if (!(m_name.trim().equals("")))
getSql = " and m_name ='"+e_name+"'";
if (!(m_country.trim().equals("")))
getSql = " and m_country='"+country+"'";
rs = this.executeQuery(getSql);

}catch(Exception e) {
System.err.println(e.getMessage());
}
return rs;
} 这个方法是用做条件查询的,但是查询SQL取的不对吧,是不是应该这样getSql =getSql+ " and m_name ='"+e_name+"'";还有里面的第一个条件应该没有"and";
此外BEAN里方法感觉都是分散的,没有联合起来工作啊。也许我的水平低,总是感觉的代码都是问题
回复
jimsons 2004-08-31
public ResultSet getStaff()
{
String sql="select * from employees";
ResultSet rs = this.executeQuery(sql);
...
上面为什么是 this.executeQuery(sql);
是应该
Statement stm=con.createStatement();
ResultSet rs=stm.executeQuery(sql);
回复
zmybest 2004-08-31
你把private String e_name;
private String e_id;
这几个属性名称的下划线去掉,试试,估计是不符合bean的规范。
回复
magie16036936 2004-08-31
没有错误提示!
就是!数据显示不到页面上!

回复
wangwei8117 2004-08-31
错误提示是什么啊!弄出来看看啊,写的好乱啊!
回复
magie16036936 2004-08-31
改过来也显示不出来数据!!
回复
caiyi0903 2004-08-30
<jsp:useBean id="Staff" scope="page" class="test.Staff">
<jsp:setProperty name="staff" property="*"/>
这个地方大小写不一样,所以出错了!
回复
顽皮小熊 2004-08-30
我晕 有问题
回复
发帖
Web 开发
创建于2007-09-28

8.0w+

社区成员

Java Web 开发
申请成为版主
帖子事件
创建了帖子
2004-08-30 06:22
社区公告
暂无公告