根据JSP页面上的数据库条目检查复选框 [英] Checking a checkbox based on a database entry on a JSP page
本文介绍了根据JSP页面上的数据库条目检查复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
这是我的复选框:
<input type="checkbox" name="headC" id="headC" value="Head">
我有一个字符串变量<%=msmtHead%>
,该变量用于根据以下逻辑确定是否选中了此复选框:If (<%=msmtHead%> !="")
检查else
不检查.
I have a String variable <%=msmtHead%>
which is used to determine if this checkbox is checked or not based on this logic: If (<%=msmtHead%> !="")
check else
don't check.
我如何进行这项工作?我有几个需要类似检查的复选框.
How do I make this work? I have several such checkboxes which need to be checked similarly.
我的研究告诉我应该使用JSTL,但是我不知道如何使用<c:if>
标记来测试字符串值.
My research tells me JSTL should be used, but I don't know how to use the <c:if>
tag to test for string values.
推荐答案
您需要让JSP相应地打印checked
属性.
You need to let JSP print the checked
attribute accordingly.
所以基本上,
<input type="checkbox" name="headC" id="headC" value="Head" <%= ("Head".equals(msmtHead) ? "checked" : "") %>>
或使用EL
<input type="checkbox" name="headC" id="headC" value="Head" ${msmtHead == 'Head' ? 'checked' : ''}>
这篇关于根据JSP页面上的数据库条目检查复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文