0

Java アプリケーションの eInvoice アプリケーションに取り組んでいます。アプリの目的は、eInvoices を追加し、追加した eInvoices を表示することです (ここまでは問題なく動作します)。ただし、請求書を表示するときに、会社名をハイパーリンクして、リンクをクリックした後、特定の請求書の詳細を Jsp ページに表示する必要があります。サーブレットに情報を渡していることに注意してください。次に、ゲッターとセッターを使用してJavaクラスに情報を保存しています。複数のレコードが Arraylist オブジェクトに格納されます。これを行う方法を見つけることができないようです。どんな助けでも大歓迎です。

<%
float bigTotal=0;
try
{
    @SuppressWarnings("unchecked")
    ArrayList<UserInvoice> myVal = (ArrayList<UserInvoice>)session.getAttribute("eInvoice");
    out.write("<table border='0'>");
    out.write("<th width='200'>Invoice No.</th><th width='300'>Client Name</th>  <th width='200'>Total</th><th width='200'>Payment Due Date</th>");
    for(UserInvoice invoices:myVal)
    {
        out.write("<tr>");
        out.write("<td height='25'>");
        out.write(""+invoices.getInvoiceNo());
        out.write("</td>");

        out.write("<td>");
        out.write(invoices.getClientName());
        out.write("</td>");

        out.write("<td>");
        out.write(String.valueOf(invoices.getTotal()));
        out.write("</td>");

        out.write("<td>");
        out.write(invoices.getPayDueDate());
        out.write("</td>");

        out.write("</tr>");
        bigTotal = bigTotal+invoices.getTotal();

    }
    out.write("</table>");
}
catch(Exception ex)
{
out.write("<h1>Looks like you haven't added any invoices yet.</h1>");
}
4

1 に答える 1

1

JSTL foreachを使用できます。

<%@ page pageEncoding="UTF-8" contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<% request.setAttribute("eInvoices", eInvoices); %>

<table>
 <c:forEach items="${eInvoices}" var="value">
  <tr><td><c:out value="${value.name}"/></td></tr>
 </c:forEach>
</table>

AJAXを使用して詳細を取得します。

(請求書名をクリックすると、詳細を取得するためにページに対して HTTP 要求が行われます。これらの詳細は、コンテンツ タイプが の HTML として返されます'text/html')

例:

于 2013-10-21T18:16:09.237 に答える