新增页面中,设置一个隐藏域的作用?
从网上看到的项目代码中,在jsp页面中是这样的:
..........
<form action="add.action" method="post">
<table width="500" align="center">
<caption>ADD USER INFORMATION</caption>
<tr height="26px">
<td width="150px" align="right">UNAME</td>
<td width="350px">[/code]
<input type="hidden" name="param" value="1"/>
<input type="text" name="user.uname" value="${user.uname }"/>
</td>
</tr>
<tr height="26px">
<td align="right">PASSWORD</td>
<td><input type="password" name="user.password" value="${user.password }"/></td>
</tr>
后台代码中,新增对象的逻辑是这样的:
public String doAdd(){
String result = "";
try {
String param = getParam("param");
if(Integer.parseInt(param) > 0){
user.setId(0);
userService.addUser(user);
result = doQuery();
}else
result = "addUser";
} catch (Exception e) {
e.printStackTrace();
}
return result;
}
代码中有一个判断隐藏input值的语句,如果大于0才执行;否则直接返回。
这样写的意义何在?