我的動態Web項目中的response.jsp未顯示數據庫結果。下面是我的代碼的一部分,沒有任何問題建立的連接從Java Servlet將DB2查詢結果打印到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不顯示數據庫結果?
您應該只發布你所面臨的問題與最相關的代碼,除非有人明確要求看到更多的代碼。 – Abubakkar
您是否檢查過您的代碼沒有生成任何異常? – Abubakkar
謝謝,我用servelet和response.jsp更新了這個問題,我在生成的代碼中沒有任何例外 –