Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
400 views
in Technique[技术] by (71.8m points)

java - 在jsp页面中动态添加按钮和文本框(Adding button and textbox dynamically in jsp page)

<form:form action="approveAccount.html" method="GET">
<input type="submit" value="approvAll"/>
<p>Following Accounts are Pending to approve</p>    
<c:forEach items="${accountIdList}" var="val">
<li>${val}</li>                               
</c:forEach>        
</form:form>

val is the value that is fetched from database, I want to add a submit button and want to use this fetched value to do some stuffs, how many value get fetched is dynamically decided, how todo that.. here in this scenario, I am getting account id which admin needs to approv, so by adding textbox, admin can assign the role to the this account and then submit the to the database and this all happen with that clk of button(val是从数据库中获取的值,我想添加一个提交按钮,并要使用此获取的值来做一些事情,要动态确定要获取多少值,该如何做..在这种情况下,我获取管理员需要批准的帐户ID,因此,通过添加文本框,管理员可以将角色分配给该帐户,然后将角色提交给数据库,所有这些操作都通过该按钮来实现)

  ask by Khan translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Suppose, in your service class, you have list of accountIds like this(假设在您的服务类中,您具有诸如此类的accountId列表)

ArrayList<Integer> accountIdList = new ArrayList<>();
accountIdList.add(1);
accountIdList.add(2);
accountIdList.add(3);

& you have added this list into HTTP Session object for further use like(&您已将此列表添加到HTTP Session对象中,以供进一步使用,例如)

session.setAttribute("accountIds",accountIdList);

In your JSP, you can then use JSTL for-each loop to create dynamic buttons & textboxes as below(然后,在您的JSP中,可以使用JSTL for-each loop创建动态按钮和文本框,如下所示)

<c:forEach var="ids" items="${session.accountIds}" varStatus="loop">
    <input type="text" name="role${loop.index}" />
    <input type="submit" value="<c:out value=${ids} />" /> 
</c:forEach>

I hope this helps.(我希望这有帮助。)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...