简体   繁体   English

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

[英]Why do I get a blank page when running my application from Netbeans?

Yesterday everything was working just fine but today I'm running into this annoying blank page whenever I try to run my application from the IDE. 昨天一切正常,但是今天每当我尝试从IDE运行应用程序时,我都会遇到这个烦人的空白页面。

My server is Glassfish/port4848 then run from the IDE http://localhost:8080/ecommerce/ 我的服务器是Glassfish/port4848然后从IDE http://localhost:8080/ecommerce/ Glassfish/port4848运行

The problem seems to be when I add these two library references at the top of the page: 问题似乎出在我在页面顶部添加以下两个库引用时:

<!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语句

<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>

When I remove the SQL statements from the top, the page loads perfectly fine when I request it in my local browser. 当我从顶部删除SQL语句时,当我在本地浏览器中请求该页面时,该页面将完美加载。 Thing is I need the libraries to be able to run these JSTL: 我需要这些库才能运行这些JSTL:

Category page/ left column (vertical menu bar) 类别页面/左列(垂直菜单栏)

<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>

Displaying the product within the table (right column/products container) 在表格中显示产品(右列/产品容器)

<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>

I'd like to precise that I don't have the issue with my index page that also contains JSTL and the two references at the top. 我想精确地说,我的索引页面没有问题,该页面也包含JSTL和顶部的两个引用。 The problem is only with my category page. 问题仅在于我的类别页面。

Full Category Source Code: 完整类别的源代码:

<!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>

Any idea? 任何想法?

Thanks a lot! 非常感谢!

To display a page correctly is not related to the taglib . 正确显示页面与taglib没有关系。

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

Mostly is a false select statement the reason. 多数是错误的选择语句的原因。

Your code does not match the variables ! 您的代码与变量不匹配!
So a <c:forEach with a rowcount == 0 will never run and your page is blank. 因此,行rowcount == 0<c:forEach将永远不会运行,并且您的页面为空白。

  • query var="selectedCategory" is never used. 查询var =“ selectedCategory”从未使用过。
  • ${pageContext.request.queryString} is never tested. ${pageContext.request.queryString}从未经过测试。

Test ${pageContext.request.queryString} with : look here 测试${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 uses ${categories.rows} ! <c:forEach使用${categories.rows} where it come from ? 它来自哪里?

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

Replace param value="a valid ID" with a known value . 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>

Also items="${products}" is not matching any sql query. 另外items="${products}"与任何SQL查询都不匹配。

<c:forEach var="product" items="${products}" varStatus="iter">

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么在 S3 上上传时得到空白 pdf? - Why do I get a blank pdf when uploaded on S3? 我只是使用gruntjs构建了AngularJS项目,但是当将结果加载到浏览器中时,我得到了一个空白页面,如何开始对此进行调试? - I just built my AngularJS project using gruntjs, but when I load the result in my browser, I get a blank page, how do I begin debugging this? 我简单的jQuery代码无效。 我运行它时会得到一个空白页面 - My simple code of jQuery is not working. I get a blank page when I run it 为什么在运行我的程序时出现错误:“日期未定义”,而日期是在外部 js 库中定义的? - why do i get an error when running my program: “dates is not defined,” when dates is defined in an external js library? 为什么当我在 Apache 上运行我的 React 构建时......只出现空白页面......? - Why is that when i run my react build on Apache...Just blank page appears..? 当我在Emberjs中刷新带有&#39;id&#39;的网址时,为什么我会得到一个空白的应用程序? - Why do I get a blank app when I refresh the url with the 'id' in the end in Emberjs? 我如何将Http获取请求文件中的Json数据显示到空白html页面上 - How would I display a Json data from my Http get request file onto a blank html page 为什么选择初始加载页面时出现错误? - Why do I get an error when choosing the initial loading page? 为什么刷新页面时localStorage条目会重置? - Why do localStorage entries get reset when I refresh the page? 为什么我在访问安全页面时没有被重定向到 /login? - Why do I not get redirected to /login when accessing a secure page?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM