首页 > 解决方案 > 需要一种方法来获取填充数据的显示方法以在jsp上显示

问题描述

我正在处理银行申请。我的大部分业务对象都正常工作,尽管我似乎无法弄清楚如何让显示方法打印到客户端而不是服务器日志。这对大多数人来说似乎很容易,但我有点卡住了。

这是jsp:

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@page import= "business.AccountList" %>
<%@page import= "business.Customer" %><!--Space between =" makes the String orange-->
<%@page import= "business.Account" %><!--Space between =" makes the String orange
                                       or black.--> 
<!DOCTYPE html>
<!--
To change this license header, choose License Headers in Project Properties.
To change this template file, choose Tools | Templates
and open the template in the editor.
-->

    <html lang="en-US">
<head>
      <meta charset="UTF-8" />
      <meta name="description" content="Display Accounts Page" />
      <meta name="keywords" content="HTML, Java" />
      <meta name="author" content="Robert McGuire " />
      <!--<meta http-equiv="refresh" content="30" />-->
      <meta name="viewport" content="width=device-width, initial-scale=1.0" />
      <title>Display Accounts Page</title>
      <!--<link rel="stylesheet" type="text/css" href="style_General.css" />-->
      <!--[if lt IE 9]>
        <script src="/js/html5shiv.js"></script>
      <![endif]-->
</head>
    <body>
        <%
            Customer c1 = (Customer)session.getAttribute("c1");
            out.println("Customer object from session:"+c1);
            //Account a1 = (Account)session.getAttribute("a1");
            //out.println("Account object from session:"+a1);
            //c1.display();
            //c1.list.arr[0].display();
            int c =c1.list.count;
            for(int i =0; i<c;i++){
                c1.list.arr[i].display();
            }
            %>

            <h1>Welcome <%=c1.getCustFirstName()%>    <%=c1.getCustLastName()%> .</h1>
            <p>Address : <%=c1.getAddress()%> </p>
            <p>Email : <%=c1.getEmail()%> </p>

            <h2>Your Account details are listed here.</h2>
        <!--Form Section.-->
        <div>

          <!--  <form action="http://localhost:8080/WebApplication12/AccountLookupServlet" method="post">
                <pre>
                Account No: <input type="text" name="accountNumber" placeholder="Account ##"><br>
                Customer ID:<input type="text" name="custId" placeholder="Customer ID"/><br>
                Type:       <input type="text" name="type" placeholder="Account Type"/><br/>
                Balance:    <input type="text" name="balance" placeholder="Balance"/>
                <br/>        
                            <input type="submit" value="Retrieve" /><input type="reset" value="Clear" />
                </pre>
            </form>-->
        </div>
        <!--putting the acct info back into the page not into the textboxes. -->
        <div>
            <table>
                <thead>Account Information</thead>
                <hr/>
                <br/>  
                <tr>Account Number:<%= c1.list.arr[c]%></tr><br/>
           <tr> _________Display___________</tr><br/>
           <tr> Customer Id:<%c1.getCustId(); %></tr><br/>
<%--            <tr> Account Type:<%c1.getAccounts() %> --%>

<!-- Info:   Account Type: Checking -->
<!-- Info:   Account Balance: 1000.0 -->
            </table>


        </div>
             <%
             //Putting the objects back into the session . 
             session = request.getSession();
             //session.setAttribute("a1", a1);
             session.setAttribute("c1", c1);



             %>



        <hr />
      <!--Footer section with all the navigation links.-->
        <footer>
            <a href="index.jsp" style="text-decoration: none">Homepage</a>
            <a href="login.jsp" style="text-decoration: none">Login Page</a> 
        </footer>
    </body>
</html>

控制台显示工作......我只是不知道如何将数据从 Account 对象获取到 jsp。

我尝试将 JspWriter 添加为 display () 接受的参数。我无处可去。我一直在阅读有关此 JspWriter 的信息,但不了解如何正确使用它。我想要做的就是访问:

 public void display() {
        System.out.println("_________Display___________");
        System.out.println("                           ");
        System.out.println("Account Number: " + getAccountNo());
        System.out.println("Customer Id:" + getCustomerID());
        System.out.println("Account Type: " + getAccountType());
        System.out.println("Account Balance: " + getBalance());

这来自提供的jsp页面。我不知道如何使用 JspWriter 来完成这项任务。

真诚的感谢。

ps.在我了解其他技术之前,我将使用 scriptlet 标签。我从未被告知使用 scriptlet 标签是不好的做法。

标签: javajsp

解决方案


推荐阅读