gpt4 book ai didi

java - 如何显示一个表中下拉框的第一个值以及另一个表中相同下拉框的其他值

转载 作者:行者123 更新时间:2023-11-29 17:56:10 24 4
gpt4 key购买 nike

I have display the data from database into textbox and drop down box from users table. I have one display button,when I click on display button then the list of employees appear into textbox perfectly,but it is not working perfectly into drop down box.I am fetching values of dropdown from another table also,but I want to display the respective value of employee department into the drop down box first.

<td><select name="Department" value="<%=pList.get(4)%>" style="width:150px">
<%
Statement statement1 = con.createStatement() ;
resultset1 =statement1.executeQuery("select Department from users") ;
while(resultset1.next()){ %>
<option><%= resultset1.getString(1)%></option>

<% } %>
</select></td>

I am getting first value of data from drop down box,but I want to display the data of employee's department as first value into drop down box .I have display the data of employee from users table and department from department table into drop down box,but I want to Display the data from users table as first value into dropdown box,and then I can select another value and update the data.I am not getting ,How can I implement these.

最佳答案

根据我的理解,您希望在下拉列表和文本框中显示记录。所以回答你的第一个问题:你在代码中错过了“option”标签

Try out below code :

<td><select name="Department1" value="<%=pList.get(4)%>" style="width:150px">
<%
Statement statement1 = con.createStatement() ;
resultset1 =statement1.executeQuery("select Department from users") ;
while(resultset1.next()){ %>
<option>
<%= resultset1.getString(1)%>
</option>

<% } %>

回答你的第二个问题:你想先显示用户数据,然后显示员工数据:

我建议在列表中获取用户记录,然后在同一列表中添加员工记录。

尽量避免在 JSP 中使用 JAVA 代码。

在 JSP 中编写 JAVA 代码不是一个好的做法。

关于java - 如何显示一个表中下拉框的第一个值以及另一个表中相同下拉框的其他值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48803353/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com