----------------goodsList.jsp 红色处没有显示数据
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
page Size : ${numbers}
<c:forEach items="${goodsList}" var="good">
${good.nnn}
</c:forEach>
--------------GoodListServlet.java
package soyo.shopping.servlet.admin;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import soyo.shopping.services.*;
import soyo.shopping.entity.Good;
public class GoodListServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
int numbers;
public GoodListServlet() {
super();
// TODO Auto-generated constructor stub
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
GoodServices goodServices=new GoodServices();
numbers = goodServices.getRecordNumber();
List<Good> result=goodServices.getRecordAll();
PrintWriter out = response.getWriter();
request.setAttribute("goodsList", result);
request.setAttribute("numbers", numbers);
RequestDispatcher dispatcher=request.getRequestDispatcher("goodsList.jsp");
dispatcher.forward(request, response);
}
}
---------------Good.java
package soyo.shopping.entity;
public class Good {
private String nnn;
public Good(){
}
public Good(String nnn)
{
setGoodsNNN(nnn);
}
public String getGoodsNNN() {
return nnn;
}
public void setGoodsNNN(String nnn) {
this.nnn = nnn;
}
}
报错信息为:
javax.servlet.jsp.el.ELException: Unable to find a value for "nnn" in object of class "soyo.shopping.entity.Good" using operator "."
不知道如何修改goodsList.jsp代码,望解答。
问题补充:
----------GoodServices.java
package soyo.shopping.services;
import java.util.List;
import soyo.shopping.dao.GoodDAO;
import soyo.shopping.entity.Good;
public class GoodServices {
GoodDAO goodDAO;
public GoodServices() {
goodDAO=new GoodDAO();
}
public int getRecordNumber(){
return goodDAO.getRecordNumber();
}
public List<Good> getRecordAll(){
List<Good> result=goodDAO.getRecordAll();
return result;
}
}
-----------------------GoodDAO.java
package soyo.shopping.dao;
import java.sql.CallableStatement;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.Statement;
import java.util.LinkedList;
import java.util.List;
import soyo.shopping.entity.Good;
public class GoodDAO {
Connection conn;
public GoodDAO(){
Init init=new Init();
conn=init.connent();
}
public int getRecordNumber(){
int count=0;
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select count(*) from goods");
System.out.println("PaginationDAO.getRecordNumber 12");
while(rs.next()){
count=rs.getInt(1);
break;
}
//destroy();
} catch (Exception e) {
System.err.println("PaginationDAO.getRecordNumber ERROR ## "+e.getMessage());
}
return count;
}
public List<Good> getRecordAll(){
List<Good> result=new LinkedList<Good>();
try {
Statement stmt = conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from goods");
while(rs.next()){
Good good = new Good(rs.getString("nnn"));
result.add(good);
break;
}
//destroy();
} catch (Exception e) {
System.err.println("PaginationDAO.getRecordNumber ERROR ## "+e.getMessage());
}
return result;
}
}
问题补充:
List<Good> result=goodServices.getRecordAll();
if(result.size()>0){
response.setHeader("Pragma","No-cache");
response.setDateHeader("Expires",0);
response.setHeader("Cache-Control","no-cache");
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<h1>Hello,World!</h1>");
out.println(result);
out.println("<h1>Hello,World2!</h1>");
}
输出的结果是:
Hello,World!
[soyo.shopping.entity.Good@1e0512a]
Hello,World2!