将 DB2 查询结果从 Java Servlet 打印到 JSP



响应.jsp在我的动态Web项目中不显示来自数据库的结果。下面是我的代码部分,连接已建立,没有任何问题

订单控制器.java

package com.whs.reporting.controller;
import java.io.IOException;
import java.sql.SQLException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.waitrose.reporting.dao.OrderDao;
/**
* Servlet implementation class OrderC
*/
@WebServlet(name="OrderServlet",urlPatterns={"/OrderController"})
public class OrderController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public OrderController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
OrderDao dao = new OrderDao();
try {           
request.setAttribute("orders",dao.getallorders());          
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
RequestDispatcher view = request.getRequestDispatcher("Response.jsp");
view.forward(request, response);        
}
}

响应.jsp

<%@ page language="java" contentType="text/html; charset=EUC-KR" pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Show Order Result</title>
</head>
<body>
<table border=1>
<thead>
<tr>
<th>Order Number</th>
<th>Service Type</th>                
<th>Delivery Date</th> 
<th>Branch Number</th>               
<th>Total</th>               
</tr>
</thead>
<tbody>
<c:forEach items="${orders}" var="order">
<tr>
<td>${order.ordernumber}</td>
<td>${order.service}</td>
<td>${order.deliverydate}</td>
<td>${order.branch}</td>
<td>${order.total}</td>                    
</tr>
</c:forEach>
</tbody>
</table>
</body>
</html>

任何人都可以让我知道我在这里缺少什么以及为什么 jsp 不显示数据库结果?

response.jsp中包含以下链接

<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/xml" %>

因为您使用的是标签库,所以您需要在使用 jstl 标签的 jsp 中提供它。

<%@ page language="java" contentType="text/html; charset=EUC-KR" 
pageEncoding="EUC-KR"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/xml" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-KR">
<title>Show Order Result</title>
</head>
<body>
<table border=1>
<thead>
<tr>
<th>Order Number</th>
<th>Service Type</th>                
<th>Delivery Date</th> 
<th>Branch Number</th>               
<th>Total</th>               
</tr>
</thead>
<tbody>
<c:forEach items="${orders}" var="order">
<tr>
<td>${order.ordernumber}</td>
<td>${order.service}</td>
<td>${order.deliverydate}</td>
<td>${order.branch}</td>
<td>${order.total}</td>                    
</tr>
</c:forEach>
</tbody>
</table>

这可以帮助参考

最新更新