jsp中设计性别和年龄的添加和修改

添加.jsp

<form action="insert" method="post">

性别<input type="radio" name="sex" value="man" checked="checked"><input type="radio" name="sex" value="woman"><br>
<!--value是action传递走的值,下同 -->

年龄<select name="age" >
<option>请选择</option>
<c:forEach var="i" begin="6" end="100"><!--相当于for(i=6;i<=100;i++) -->
<option value="${i }" >${i }</option><!--取i的值 -->
</c:forEach>
</select>
</form>

 

运行结果:

 

修改.jsp

<form action="update" method="post">
性别<c:choose > <c:when test="${data.sex=='man' }"> <input type="radio" name="sex" value="man" checked="checked" ><input type="radio" name="sex" value="woman"><br> </c:when> <c:otherwise> <input type="radio" name="sex" value="man"><input type="radio" name="sex" value="woman" checked="checked" ><br> </c:otherwise> </c:choose> 年龄<select name="age" > <option>请选择</option> <c:forEach var="i" begin="6" end="100">   <c:choose>   <c:when test="${data.age==i }"><!-- 相当于if(${data.age==i})-->   <option value="${i }" selected="selected">${i }</option>   </c:when>   <c:otherwise><!--相当于else-->    <option value="${i }" >${i }</option>   </c:otherwise>   </c:choose> </c:forEach> </select>
</form>

运行结果(带有性别、年龄的默认选择):

 

posted @ 2017-02-20 16:37  囧雪诺  阅读(2473)  评论(0编辑  收藏  举报