Home >Java >javaTutorial >How to assign value to input box in jsp

How to assign value to input box in jsp

(*-*)浩
(*-*)浩Original
2019-05-18 20:31:4911698browse

Jsp method of assigning value to the input box: 1. Direct assignment through value; 2. Assign value to the input box through param, which is the assignment method when the name is different from the attribute name; 3. Through "*" Method assignment, this method is to assign all values ​​with the same name and attribute name.

How to assign value to input box in jsp

This article will introduce several JSP page assignments to input methods for your reference.

1.value
Description: The most direct way to assign 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
Description: When name and attribute Assignment method when the names are different

<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.*
Description: Assign all values ​​with the same name and attribute 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 directive The difference from action elements

The encoding format must be consistent, otherwise there will be garbled characters

1.The include directive is called a static include; the include action element is called a dynamic include

2. The include instruction cannot pass parameters, and an error will be reported; the include action element can

3. The attributes are different, the include instruction is file; the include action element is page, flush

4. The include directive file contains only one servlet and class generated; the include action element generates respective servlets and classes

5. The introduction time is different, the include directive is introduced at startup; the include action element is triggered when It will be introduced only when

6. The two files of the include directive share one request; the include action element has two requests

The above is the detailed content of How to assign value to input box in jsp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn