1
<% String username = request.getParameter("username");
String authority = request.getParameter("authority");
%>
<form action="UserLoginServlet" method="post">
username: <input type="text" name="username" value='<%= null == username ? "" : username %>'><br>
password: <input type="password" name="password"><br>
authority:
<select name="authority">
<option value="1" <%= "1".equals(authority) ? "selected='selected'" : ""%>>common user</option>
<option value="2" <%= "2".equals(authority) ? "selected='selected'" : "" %>>administrator</option>
</select>
<br>
<input type="submit" value="submit">
</form>
2 select默认选中第一项,所以不用做默认值判断
radio默认不选中,所以用个三元表达式
<input type="radio" name="abc" value="0" <%= null==cssType?"checked='checked'":(0==Integer.parseInt(cssType)?"checked='checked'":"") %> />1 <input type="radio" name="abc" value="1" <%= null==cssType?"":(1==Integer.parseInt(cssType)?"checked='checked'":"") %>/>2
当然,最好用equal方法代替==,可以不用转换类型