我的动态网络项目中的response.jsp没有显示数据库的结果。下面是我的代码部分,建立连接没有任何问题
OrderController.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);
}
}
的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没有显示db结果?
答案 0 :(得分:1)
在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>