jsp給輸入框賦值的方法:1、透過value直接賦值;2、透過param方式給輸入框賦值,是當name與屬性名不相同時的賦值方式;3、透過“*”方式賦值,此方式是賦值所有name與屬性名稱相同的值。
本篇文章將介紹幾個JSP頁面賦值給input方法,供大家作為參考。
1.value
說明:最直接的賦值方式
value赋值<br/> <jsp:useBean id="ls" class="model.Employee" scope="session" /> <jsp:setProperty property="id" name="ls" value="1002"/> <jsp:setProperty property="name" name="ls" value="李四"/> <jsp:setProperty property="departmentName" name="ls" value="人事部"/> 员工编号:<jsp:getProperty property="id" name="ls"/><br/> 员工姓名:<jsp:getProperty property="name" name="ls" /><br/> 员工部门:<jsp:getProperty property="departmentName" name="ls" />
2.param
說明:當name與屬性名不相同的時候的賦值方式
<jsp:useBean id="employee" class="model.Employee" scope="session" /> <form action="<%=request.getContextPath()%>/jsp/test_getValue.jsp"> 员工编号<input value="" name="id_text" /><br/> 员工姓名<input value="" name="name_text" /><br/> 员工部门<input value="" name="departmentName_text" /><br/> <input type="submit" value="提交" /> </form>
<jsp:useBean id="employee" class="model.Employee" scope="session" /> param赋值<br/> <jsp:setProperty property="id" name="employee" param="id_text"/> <jsp:setProperty property="name" name="employee" param="name_text"/> <jsp:setProperty property="departmentName" name="employee" param="departmentName_text"/> 员工编号:<jsp:getProperty property="id" name="employee" /><br/> 员工姓名:<jsp:getProperty property="name" name="employee" /><br/> 员工部门:<jsp:getProperty property="departmentName" name="employee" /><hr/>
3.*
說明:賦值所有name與屬性名稱相同的值
<jsp:useBean id="employee" class="model.Employee" scope="session" /> <form action="<%=request.getContextPath()%>/jsp/test_getValue.jsp"> 员工编号<input value="" name="id" /><br/> 员工姓名<input value="" name="name" /><br/> 员工部门<input value="" name="departmentName" /><br/> <input type="submit" value="提交" /> </form>
<jsp:useBean id="employee" class="model.Employee" scope="session" /> <jsp:setProperty property="*" name="employee"/> 员工编号:<jsp:getProperty property="id" name="employee" /><br/> 员工姓名:<jsp:getProperty property="name" name="employee" /><br/> 员工部门:<jsp:getProperty property="departmentName" name="employee" />
#include指令和動作元素的區別
要求編碼格式一致,不然會有亂碼
1.include指令被稱為靜態include;include動作元素被稱為動態include
#2.include指令不可以傳參,會報錯;include動作元素可以
#3.屬性不一樣,include指令是file;include動作元素是page、flush
# 4.include指令檔包含只產生一個servlet和class;include動作元素產生各自的servlet和class
5.引入時間不一樣,include指令在啟動的時候就引入了;include動作元素在觸發的時候才會引入
6.include指令的兩個檔案共用一個request;include動作元素有兩個reques
以上是jsp怎麼給輸入框賦值的詳細內容。更多資訊請關注PHP中文網其他相關文章!