为什么从Netbeans运行我的应用程序时会出现空白页面?

时间:2015-02-18 18:48:41

标签: javascript netbeans jstl

昨天一切正常,但是今天每当我尝试从IDE运行我的应用程序时,我都会遇到这个烦人的空白页。

我的服务器是Glassfish/port4848,然后从IDE http://localhost:8080/ecommerce/

运行

问题似乎是当我在页面顶部添加这两个库引用时:

<!DOCTYPE html>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>

Sql statetments

<sql:query var="selectedCategory" dataSource="jdbc/ecommerce">
    SELECT name FROM category WHERE id = ?

<sql:param value="${pageContext.request.queryString}"/>
</sql:query>

<sql:query var="categoryProducts" dataSource="jdbc/ecommerce">
    SELECT * FROM product WHERE category_id = ?
    <sql:param value="${pageContext.request.queryString}"/>
</sql:query>

当我从顶部删除SQL语句时,当我在本地浏览器中请求时,页面加载完全正常。事情是我需要库来运行这些JSTL:

类别页面/左栏(垂直菜单栏)

<c:forEach var="category" items="${categories.rows}">

        <c:choose>
            <c:when test="${category.id == pageContext.request.queryString}">
                <div class="categoryButton" id="selectedCategory">
                    <span class="categoryText">
                        ${category.name}
                    </span>
                </div>
            </c:when>
            <c:otherwise>
                <a href="category?${category.id}" class="categoryButton">
                    <div class="categoryText">
                        ${category.name}
                    </div>
                </a>
            </c:otherwise>
        </c:choose>
    </c:forEach>

在表格中显示产品(右栏/产品容器)

<c:forEach var="product" items="${categoryProducts.rows}" varStatus="iter">

    <tr class="${((iter.index % 2) == 0) ? 'lightBlue' : 'white'}">
        <td>
            <img src="${initParam.productImagePath}${product.name}.png"
                alt="${product.name}">
        </td>
        <td>
            ${product.name}
            <br>
            <span class="smallText">${product.description}</span>
        </td>
        <td>
            &euro; ${product.price} / unit
        </td>
        <td>
            <form action="addToCart" method="post">
                <input type="hidden"
                       name="productId"
                       value="${product.id}">
                <input type="submit"
                       value="add to cart">
            </form>
        </td>
    </tr>

</c:forEach>

我想确切地说我的索引页面也没有问题,该索引页面也包含JSTL和顶部的两个引用。问题出在我的类别页面上。

完整类别源代码:

<!DOCTYPE html>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql"%>

<%-- 
    Document   : category
    Created on : Feb 01, 2015, 7:56:19 PM
    Author     : PC
--%>


<sql:query var="categories" dataSource="jdbc/ecommerce">
    SELECT * FROM category
</sql:query>

        <sql:query var="selectedCategory" dataSource="jdbc/ecommerce">
    SELECT name FROM category WHERE id = ?
    <sql:param value="${pageContext.request.queryString}"/>
</sql:query>

    <sql:query var="categoryProducts" dataSource="jdbc/ecommerce">
    SELECT * FROM product WHERE category_id = ?
    <sql:param value="${pageContext.request.queryString}"/>
</sql:query>


<html>
  <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

        <title>Ecommerce | Online Shopping</title>

        <script src="//code.jquery.com/jquery-1.11.2.min.js"></script>
        <script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>

        <link rel="stylesheet" type="text/css" href="css/category.css"/>
        <link rel="stylesheet" type="text/css" href="css/header.css"/>
        <link rel="stylesheet" type="text/css" href="css/footer.css"/>
    </head>

    <body style="margin: 0pt auto; padding: 0pt; max-width: 100%; width: 100%;">


        <div id="store_container">
<div id="store">
<div style="text-align: center;" id="category">
<div id="items">categories
</div>
<div class="cat_row">
<div style="text-align: left;"><span style="font-weight: bold;"><span style="background-color: rgb(239, 239, 239);">Brand new
products</span><br>
</span><span style="font-weight: normal;"></span><span style="font-weight: bold; background-color: rgb(239, 239, 239);">Items
on Sale</span><br>
<span style="text-decoration: underline;"></span></div>
</div>
<div class="cat_row">
<div style="text-align: left;"><span style="text-decoration: underline;">Shop
by technology</span><br>
<br>
<c:forEach var="category" items="${categories.rows}">

        <c:choose>
            <c:when test="${category.id == pageContext.request.queryString}">
                <div class="categoryButton" id="selectedCategory">
                    <span class="categoryText">
                        ${category.name}
                    </span>
                </div>
            </c:when>
            <c:otherwise>
                <a href="category?${category.id}" class="categoryButton">
                    <div class="categoryText">
                        ${category.name}
                    </div>
                </a>
            </c:otherwise>
        </c:choose>

    </c:forEach>
<br>
</div>
</div>
<div class="cat_row">
</div>
</div>
<div style="text-align: center;" id="thumbnails">
<div id="items"> Featured Items | ${selectedCategory.rows[0].name}
</div>
<br>
<div style="text-align: left;">
<div class="item_col">pages 1-2-3-4-5-6-7-8-10...<br>
</div>
<div style="text-align: left;" class="item_col2">24 per
page&nbsp;&nbsp; 48 per page&nbsp;&nbsp; 96 per page&nbsp;&nbsp; View
All<br>
</div>
</div>
<br>

<div id="thumb_container">
<table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">

    <c:forEach var="product" items="${products}" varStatus="iter">
    <tbody>
    <tr>
      <td style="vertical-align: top; width: 275px;"><img src="${initParam.productImagePath}${product.name}.png"
                    alt="${product.name}"></td>
      <td style="vertical-align: top; width: 275px;"><img src="${initParam.productImagePath}${product.name}.png"
                    alt="${product.name}"></td>
      <td style="vertical-align: top; width: 275px;"><img src="${initParam.productImagePath}${product.name}.png"
                    alt="${product.name}"></td>
    </tr>
    <tr>
      <td style="vertical-align: top; width: 275px;">${product.name}<br>
      </td>
      <td style="vertical-align: top; width: 275px;">${product.name}<br>
      </td>
      <td style="vertical-align: top;">${product.name}<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top; width: 275px;">&cad; ${product.price} / unit<br>
      </td>
      <td style="vertical-align: top;">&cad; ${product.price} / unit<br>
      </td>
      <td style="vertical-align: top;">&cad; ${product.price} / unit<br>
      </td>
    </tr>
    <tr>
      <td style="vertical-align: top; width: 275px;">
      <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
        <tbody>
          <tr>
            <td style="vertical-align: top; width: 50%;"><form action="addToWishlist" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Wishlist">
                </form><br>
            </td>
            <td style="vertical-align: top;"><form action="addToCart" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Cart">
                </form><br>
            </td>
          </tr>
        </tbody>
      </table>
      <br>
      </td>
      <td style="vertical-align: top;">
      <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">

          <tbody>
            <td style="vertical-align: top; width: 50%;"><form action="addToWishlist" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Wishlist">
                </form><br>
            </td>
            <td style="vertical-align: top;"><form action="addToCart" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Cart">
                </form></td>
          </tr>
        </tbody>
      </table>
      <br>
      </td>
      <td style="vertical-align: top;">
      <table style="text-align: left; width: 100%;" border="0" cellpadding="0" cellspacing="0">
        <tbody>
          <tr>
            <td style="vertical-align: top; width: 50%;"><form action="addToWishlist" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Wishlist">
                </form><br>
            </td>
            <td style="vertical-align: top;"><form action="addToCart" method="post">
                    <input type="hidden"
                           name="productId"
                           value="${product.id}">
                    <input type="submit"
                           value="Add To Cart">
                </form></td>
          </tr>

        </tbody>
         </c:forEach>
      </table>
      <br>
      </td>
    </tr>
  </tbody>
</table>
<br>
<br>
</div>
</div>
</div>
</div>

    </body>
</html>

有什么想法吗?

非常感谢!

1 个答案:

答案 0 :(得分:2)

正确显示页面与 taglib 无关。

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

主要是错误的选择陈述原因。

您的代码与变量不匹配!
因此,带有<c:forEach的{​​{1}}将永远无法运行且您的网页空白。

  • query var =&#34; selectedCategory&#34;从未使用过。
  • rowcount == 0从未经过测试。

使用look here

测试${pageContext.request.queryString}
${pageContext.request.queryString}
  • <sql:query var="selectedCategory" dataSource="jdbc/ecommerce"> SELECT name FROM category WHERE id = ? <sql:param value="${pageContext.request.queryString}"/> </sql:query> 使用<c:forEach!它来自哪里?

${categories.rows}

<c:forEach var="category" items="${categories.rows}"> 替换为已知值。

param value="a valid ID"

<sql:query var="selectedCategory" dataSource="jdbc/ecommerce"> SELECT name FROM category WHERE id = ? <sql:param value="a valid ID"/> </sql:query> <c:forEach var="category" items="${selectedCategory.rows}"> <div class="categoryButton" id="selectedCategory"> <span class="categoryText"> ${category.name} </span> </div> </c:forEach> 也不匹配任何sql查询。

items="${products}"