Quantcast
Channel: Active questions tagged servlets - Stack Overflow
Viewing all articles
Browse latest Browse all 714

Servlet not displaying data obtained from dao [duplicate]

$
0
0

in dao

public class DAO {    Connection conn = null;    PreparedStatement ps = null;    ResultSet rs = null;    public List<Product> getAllProduct() {        List<Product> list = new ArrayList<>();        String query = "select * from product";        try {            conn = new DBContext().getConnection();            ps = conn.prepareStatement(query);            rs = ps.executeQuery();            while (rs.next()) {                list.add(new Product(rs.getInt(1),                        rs.getString(2),                        rs.getString(3),                        rs.getDouble(4),                        rs.getString(5),                        rs.getString(6)));            }        } catch (Exception e) {        }        return list;    }

check dao

public static void main(String[] args) {        DAO dao = new DAO();        List<Product> list = dao.getAllProduct();        for (Category o : list) {            System.out.println(o);        }    }

i checked, it ran successfully

in servlet

protected void processRequest(HttpServletRequest request, HttpServletResponse response)            throws ServletException, IOException {        response.setContentType("text/html;charset=UTF-8");        DAO dao = new DAO();        List<Product> list = dao.getAllProduct();        request.setAttribute("listP", list);        request.getRequestDispatcher("Home.jsp").forward(request, response);    }

and i check in Home.jsp

<c:if test="${empty requestScope.listP}"><p>List null</p></c:if>

the ouput is list null

How can I fix this, I use Apache NetBeans 17,apache-tomcat-10.1.17, jdk-17.0.9_windows-x64_bin


Viewing all articles
Browse latest Browse all 714

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>