zoukankan      html  css  js  c++  java
  • jSP的3种方式实现radio ,checkBox,select的默认选择值。

    jSP的3种方式实现radio ,checkBox,select的默认选择值。
    以radiao 为例:
    第一种方式:在jsp中使用java 脚本,这个方法最直接,不过脚本太多,不容易维护
    <%String state = request.getParrameter("state" )%>

     <td width="27"><input type="radio" name="state" value="AL" 〈%if(state.equal("AL")) out.print("checked")%〉/>

     <td width="27"><input type="radio" name="state" value="MT" 〈%if(state.equal("MT")) out.print("checked")%〉/>
     </td>
    第二种方式:使用jsp标准标签库jstl:
    首先需要加入库文件
    <%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    其次为:
    <td width="27">
    <c:choose>
                         <c:when test="${state=='AL'}">
                         <input type="radio" name="state" value="AL"  checked />
                         </c:when>
                         <c:otherwise
    >
                          <input type="radio" name="state" value="AL"  />
                         </c:otherwise>
                         </c:choose>
                        <c:choose>


     <td width="27">
    <c:when test="${state=='MT'}">
                         <input type="radio" name="state" value="MT"  checked />
                         </c:when>
                         <c:otherwise>
                          <input type="radio" name="state" value="MT"  />
                         </c:otherwise>
                         </c:choose>
                        <c:choose>
     </td>

    其中state应该在request,session,等中赋值。
    第三种方式:使用EL表达式:
    <td width="27"><input type="radio" name="state" value="AL" ${(state=='AL')?'checked' : ''}/>

     <td width="27"><input type="radio" name="state" value="MT" ${(state=='MT')?'checked' : ''}/>
     </td>

    显然使用EL表达式这种方式最简洁,不用写多余的代码。

  • 相关阅读:
    ArcGIS Server GP服务发布与测试(基础版)
    【转】arcgis server site 快速恢复与重建
    ArGIS Server 服务的更新
    ArcMap中,如何查看当前工具是否在执行?如何将工具调到前台来执行?
    【转】ArcGIS 创建切片缓存方法工具总结
    ArcGIS Server 增加缓存路径
    修改ArcGIS Server Account / 站点管理员的 账号、密码
    ArcGIS Server 创建站点失败
    ArcGIS Server,4000端口被占用
    JS 中如何判断字符串类型的数字
  • 原文地址:https://www.cnblogs.com/Mr-Rocker/p/3658335.html
Copyright © 2011-2022 走看看