我的DAO:
public class OperateDb {
private static Connection conn = null; // 声明数据库连接对象
public OperateDb(){}
public List<Goods> queryhot(){
int i;
String sql = "select goodsname,image from goods where classes=1 order by adtime desc";
DataBaseConnection dbc=new DataBaseConnection();
conn=dbc.getConnection();
List<Goods> hotgoods=new ArrayList<Goods>();
try {
Statement sta = conn.createStatement();
ResultSet res = sta.executeQuery(sql);
for (i=0;i<3;i++) {
String goodsname = res.getString(1);
String image=res.getString(2);
hotgoods.add(new Goods(goodsname,image));
}
res.close();
sta.close();
} catch (SQLException e) {
e.printStackTrace();
}
return hotgoods;
}
}我的servlet:private OperateDb dao1;public void init() throws ServletException {
dao1=new OperateDb();
}
private void queryNewGoods(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Goods> hotgs=dao1.queryhot();
Goods g1=hotgs.get(1);
request.setAttribute("NO1", g1.getGoodsname());
request.getRequestDispatcher("/index.jsp").forward(request,response);
}
这样写在JSP页面显示为NULL;
请问正确的写法是怎样的呢,就是我想在JSP页面显示从数据库取到的集。
PS:MYeclipse的debug怎么用的啊,我设置了断点,也把tomcat设置了DEBUG模式。但是启动服务后没有任何反应啊,或者在哪里能看到服务器端的显示啊,我在DAO里用main函数也显示不了。
public class OperateDb {
private static Connection conn = null; // 声明数据库连接对象
public OperateDb(){}
public List<Goods> queryhot(){
int i;
String sql = "select goodsname,image from goods where classes=1 order by adtime desc";
DataBaseConnection dbc=new DataBaseConnection();
conn=dbc.getConnection();
List<Goods> hotgoods=new ArrayList<Goods>();
try {
Statement sta = conn.createStatement();
ResultSet res = sta.executeQuery(sql);
for (i=0;i<3;i++) {
String goodsname = res.getString(1);
String image=res.getString(2);
hotgoods.add(new Goods(goodsname,image));
}
res.close();
sta.close();
} catch (SQLException e) {
e.printStackTrace();
}
return hotgoods;
}
}我的servlet:private OperateDb dao1;public void init() throws ServletException {
dao1=new OperateDb();
}
private void queryNewGoods(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
List<Goods> hotgs=dao1.queryhot();
Goods g1=hotgs.get(1);
request.setAttribute("NO1", g1.getGoodsname());
request.getRequestDispatcher("/index.jsp").forward(request,response);
}
这样写在JSP页面显示为NULL;
请问正确的写法是怎样的呢,就是我想在JSP页面显示从数据库取到的集。
PS:MYeclipse的debug怎么用的啊,我设置了断点,也把tomcat设置了DEBUG模式。但是启动服务后没有任何反应啊,或者在哪里能看到服务器端的显示啊,我在DAO里用main函数也显示不了。
解决方案 »
- 关于hibernate tomcat连接池问题
- 想用JSP+MYSQL做个在线防伪验证系统,求思路呀。。
- 关于FCKEditor一些问题,急,急,急!
- 菜鸟提问:关于JSP环境安装配置,请大家不要笑话
- 这样的二维数据 怎么提交数据库?
- 调查:各位做JSP的朋友门,你们都会做美工吗?
- java调用WebService接口调用的问题。
- 如何使Html代码无效
- 哪里有《JSP web编程指南》的书籍下载?
- 表单中用复选框判断表中的记录是否被选中(带程序),然后修改、删除选中的记录!谢谢!!
- 关于tomcat,每次开机都要重装,可以在eclipse中start,但http://localhost:8080打不开
- jsp页面设置不缓存IE有效opera无效
while (res.next()) {然后再看有没有其他问题。
2.迭代结果集res不当,
for (i=0;i<3;i++) {//用while(res.hasnext)还是while(res.next)记不清了
String goodsname = res.getString(1);
String image=res.getString(2);
hotgoods.add(new Goods(goodsname,image));
}
3.res.close();
sta.close();
conn最好关了
4.这是主要问题,servlet要么重写service要么写在doGet,要么doPost里面,private void queryNewGoods(HttpServletRequest 自定义方法名不行
5.打了断电,用debug模式启动,不是直接运行,小爬虫图标