JSP動態選擇單選按鈕(男或女) 通過JSTL實現
分享一下我老師大神的人工智慧教程!零基礎,通俗易懂!http://blog.csdn.net/jiangjunshow
也歡迎大家轉載本篇文章。分享知識,造福人民,實現我們中華民族偉大復興!
基礎知識:在JSP頁面如何使用JSTL表示式?首先需要往web工程匯入兩個jar包,
一個是jstl.jar,另一個是standard.jar,在MyEclipse中,已經自動幫我們匯入了,方便吧。
--------------------------------------------------------------------------------------------------------------------------------------
匯入jar後,就可以在JSP頁面使用以下標籤來匯入JSTL相應的標籤庫了。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %> //JSTL核心標籤庫
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>//JSTL I18N格式標籤庫
<%@ taglib prefix="sql" uri="http://java.sun.com/jsp/jstl/sql" %>//JSTL SQL標籤庫
<%@ taglib prefix="xml" uri="http://java.sun.com/jsp/jstl/xml" %>//JSTL XML標籤庫
--------------------------------------------------------------------------------------------------------------------------------------
是情是這樣的,我有一個JSP頁面提交表單,表單程式碼如下:
<form method="post" action="result.jsp">
<input type="text" name="sex" value="男">
<input type="submit" value="submit">
</form>
//截圖如下
---------------------------------------------------------------------------------------------------------------------------------------
JSP表單接收頁面result.jsp主要程式碼如下:
<form method="post" action="">
<input type="radio" name="sex" >男
<input type="radio" name="sex">女
</form>
截圖如下:
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
我想要實現的功能是,當表單提交頁面提交的資料是【男】時,那麼接收頁面result.jsp中的單選按鈕【男】就被選中,
如果表單提交頁面提交的資料是【女】,那麼接收頁面result.jsp中的單選按鈕【女】就處於選中狀態,
如何才能實現我想要的功能呢?
--------------------------------------------------------------------------------------------------------------------------------------------------------------------------
功能實現,把接收頁面的表單程式碼改成下面這樣既可:
<form method="post" action="">
<input type="radio" name="sex" <c:if test="${param.sex== '男'}">checked="checked"</c:if>>男
<input type="radio" name="sex" <c:if test="${param.sex== '女'}">checked="checked"</c:if>>女
</form>
</center>
友情提醒:記得在JSP頁面引入JSTL的核心標籤庫哈。
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
---------------------------------------------------------------------------------------------------------------------------------------------------------------------------
效果截圖如下:
//提交頁面
//接收頁面
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
您的十分滿意是我追求的宗旨。
您的一點建議是我後續的動力。