简体   繁体   English

如何在jsp页面中显示所选数据

[英]how to display selected data in jsp page

My requirement is explain below, 我的要求如下

I am having Arraylist in "DAO" class which contains n number of customer names.and I have set that ArrayList in "domain object" and using that "domain object" in jsp page to display the customer name. 我在“ DAO”类中拥有Arraylist,该类包含n个客户名称。我已经在“域对象”中设置了ArrayList,并在jsp页面中使用该“域对象”来显示客户名称。

I am using session scope in jsp page like below, 我在jsp页面中使用会话范围,如下所示,

<c:set var="listCustomer" value="${ItemDataResponse.dataItemsList[0].listCustomers}" 
scope="session"/>
<c:set var="CustomerData" value="${ItemDataResponse.dataItemsList[1]}" scope="session"/>


  <div  id="my_jpmorgan">

    <table border="0" width="100%" bgcolor="">
       <tr valign="top" class="lnav">
         <td width=100%">
            <table width="100%" border="0" cellspacing="0" cellpadding="0" class="paddingLeft" bgcolor="">
         <tr>
             <td>
                  <table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="">
                    <tr>
                       <td valign="top" height="1px" align="left">
                             <span class="pageHeading_DarkBlue">
                                <c:out value="${CustomerData.customerName[0]}"/>
                             </span>
            </td>

          </tr>
         <tr>
          <td align="right"> 
            <select name="singleSelect" onchange="javascript:onchangeFun(this);"> 
              <c:forEach var="Customer" items="${listCustomer}" >
                  <option value=""> <c:out value="${Customer}" /></option>
               </c:forEach>
             </select>      
           </td>
         </tr>
       </td>
     </tr>
 </table>
</div>

While logging the application every first time the first customer name from ArrayList should display in top of jsp page. 每次第一次登录应用程序时,ArrayList的第一个客户名称应显示在jsp页面顶部。 and then after loading jsp page 然后加载jsp页面后

The thing is i have to display customer name in top of jsp page when i click anyone of the customer name from the drop down menu (ie.. if i click xxx customer in drop down menu that selected xxx customer name should display in top of jsp page). 事情是当我从下拉菜单中单击任何一个客户名称时,我必须在jsp页面顶部显示客户名称(即,如果我在下拉菜单中单击xxx客户,则所选xxx客户名称应显示在顶部jsp页面)。

I am able to display drop down menu with all the cusotmers name inside it(names getting from ArrayList) but not able to display the customer name in top of jsp page when i select customer name from drop down menu.. 我能够在下拉菜单中显示所有用户名称(从ArrayList获取名称),但是当我从下拉菜单中选择客户名称时,无法在jsp页面顶部显示客户名称。

please modify my pasted code if necessary. 请根据需要修改我的粘贴代码。 and also if possible send me some sample codes 如果可能的话,还给我发送一些示例代码

Note: i am using JSTL tags (my requirement is that). 注意:我正在使用JSTL标记(我的要求是)。

In above jsp code 在上面的jsp代码中

                     <c:out value="${CustomerData.customerName[0]}"/>

line should display customer name in top of jsp page when i selected from dropdown menu(currently not working fine) and below lines display drop down window with customers name from ArrayList(working fine) 当我从下拉菜单中选择时,行应在jsp页面顶部显示客户名称(当前无法正常工作),而下面的行将显示具有ArrayList中的客户名称的下拉窗口(工作正常)

  <select name="singleSelect" onchange="javascript:onchangeFun(this);"> 
    <c:forEach var="Customer" items="${listCustomer}" >
         <option value=""> <c:out value="${Customer}" /></option>
               </c:forEach>
             </select> 

It look like that your problem is the unawareness of how HTML forms and JavaScript work. 看来您的问题是对HTML表单和JavaScript的工作方式一无所知。

There are two ways: 有两种方法:

  1. Submit the form with the dropdown to the server side. 将带有下拉列表的表单提交到服务器端。 The selected customer will be set as request parameter with the name singleSelect (the dropdown's name). 所选客户将被设置为请求参数,名称为singleSelect (下拉列表的名称)。

     <form> <select name="singleSelect" onchange="this.form.submit()"> ... 

    And display the selected customer accordingly: 并相应地显示所选客户:

     <c:out value="${param.singleSelect}" /> 
  2. Use JavaScript to get the selected customer and set it in the HTML element you'd like to display the customer name in. 使用JavaScript获取选定的客户,并将其设置在您要在其中显示客户名称的HTML元素中。

     <select name="singleSelect" onchange="showSelectedCustomer(this)"> 

    with this JS function 这个JS功能

     function showSelectedCustomer(dropdown) { var selectedCustomer = dropdown.options[dropdown.selectedIndex].value; var currentCustomer = document.getElementById('currentCustomer'); currentCustomer.firstChild.nodeValue = selectedCustomer; } 

    and this placeholder where you'd like to show the selected customer in: 以及您要在其中显示所选客户的此占位符:

     <span id="currentCustomer"></span> 

See also: 也可以看看:

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM