jsp怎么给输入框赋值

2019年5月18日20:31:49 发表评论 18 浏览

本篇文章将介绍几种JSP页面赋值给input方法,供大家作为参考。

jsp怎么给输入框赋值

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怎么给输入框赋值的详细内容,更多请关注洋洋博客其它相关文章!

jsp怎么给输入框赋值

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: