gpt4 book ai didi

java - jsp servlet表单获取复选框/选择表达式语言的值

转载 作者:行者123 更新时间:2023-12-01 11:48:20 26 4
gpt4 key购买 nike

我使用 jsp 和 servlet 创建一个 Web 应用程序。

<p>
<label>UserName:</label>
<input name="userName" type="text" value="${param.userName}">
</p>

通常我使用表达式语言,以免丢失表单中输入的信息(以防在另一个字段中输入错误)。

也可以将此方法与选择和复选框结合使用吗?

或者您还有其他想法吗?我实际上试图避免这种情况:

Servlet:

  if( request.getParameterValues("active") != null){
request.setAttribute("vActive", "");
}

JSP:

<input name="active" type="checkbox" <%  if ( request.getAttribute("vActive") != null ) { out.print(" checked=\"checked\""); }%> value="">

最佳答案

如果您只想根据请求范围中的某个值预先选择一个复选框,那么您可以在 EL 中这样做

<input name="active" type="checkbox" value="Car" ${vActive != null ? "checked" : ""} />

关于java - jsp servlet表单获取复选框/选择表达式语言的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28968178/

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