JSP中的checked如何在页面刷新后还保存的用户的沟选状态
如题目所说
<input type= "checkbox " value= "1 " <%if(queryType != 2){%> checked= "checked " <%}else{%> <%}%> name= "txtLike " id= "like " />
<label for= "like "> 模糊匹配 </label>
我这是默认第一次进入该页面就是沟选上的 在else里应该怎么写才能保存住用户是否沟选上了 这个选项
------解决方案--------------------参考一下:
<%@ page language= "java " import= "java.util.* " pageEncoding= "GBK "%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN ">
<html>
<head>
<title> 课时 </title>
<%
int queryType[] = { 1, 0 };
String flag = request.getParameter( "flag ");
if (flag != null && flag.equals( "true ")) {
String query[] = request.getParameterValues( "txtLike ");
if (query != null && query.length > 0) {
for (int i = 0; i < query.length; i++)
queryType[i] = Integer.parseInt(query[i]);
} else {
queryType[0] = 0;
queryType[1] = 0;
}
}
%>
</head>
<body>
<center>
<form action= " " method= "post ">
<input type= "checkbox " value= "1 "
<% for(int i=0; i < queryType.length ; i++) if(queryType[i]==1) out.print( "checked ");%>
name= "txtLike " id= "like " />
默认选中
<input type= "checkbox " value= "2 "
<%for(int i=0; i < queryType.length ; i++) if(queryType[i]==2) out.print( "checked ");%>
name= "txtLike " id= "like " />
其他
<br>
<input type= "hidden " name= "flag " value= "true ">
<input type= "submit " value= "提交 ">
</form>
</center>
</body>
</html>