2017-07-19 76 views
-1

我的動態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不顯示數據庫結果?

+0

您應該只發布你所面臨的問題與最相關的代碼,除非有人明確要求看到更多的代碼。 – Abubakkar

+0

您是否檢查過您的代碼沒有生成任何異常? – Abubakkar

+0

謝謝,我用servelet和response.jsp更新了這個問題,我在生成的代碼中沒有任何例外 –

回答

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> 

this can be help ful for reference

+0

我已經添加了標籤,但得到錯誤「javax.servlet.ServletException:java.lang.NoClassDefFoundError:javax/servlet/jsp/jstl/core/LoopTag」我還在web應用程序庫中添加了jstl.jar。但仍然無法正常工作 - –

+0

@ChimbuDurai嘗試清理並重新部署到您的Tomcat中,或者嘗試以下[方法](https://stackoverflow.com/a/19731101/2749470)和此[方法](https://stackoverflow.com/ a/21678762/2749470) –

+0

增加了jstl-1.2.jar,它現在可以工作。非常感謝!! –