zhengdl126 2009-09-16 11:31
浏览 211
已采纳

请教:servlet/jsp 问题

----------------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!
  • 写回答

6条回答 默认 最新

  • iteye_18973 2009-09-16 13:58
    关注

    public class Good {
    private String nnn;

    public Good(){
    
    }
    
    public Good(String nnn)
    {
        setNnn(nnn);
    }
    
    public String getNnn() {
        return nnn;
    }
    public void setNnn(String nnn) {
        this.nnn = nnn;
    }
    

    }

    把bean改成这样,你set和get好象有问题
    这样后你.nnn
    试下

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 ansys fluent计算闪退
  • ¥15 有关wireshark抓包的问题
  • ¥15 需要写计算过程,不要写代码,求解答,数据都在图上
  • ¥15 向数据表用newid方式插入GUID问题
  • ¥15 multisim电路设计
  • ¥20 用keil,写代码解决两个问题,用库函数
  • ¥50 ID中开关量采样信号通道、以及程序流程的设计
  • ¥15 U-Mamba/nnunetv2固定随机数种子
  • ¥15 vba使用jmail发送邮件正文里面怎么加图片
  • ¥15 vb6.0如何向数据库中添加自动生成的字段数据。