JavaWeb学习(四)期中考试总结(方框形式超链接,对修改页面进行优化,多条件模糊查询、输入长度的判断)
一、方框形式超链接
<input type="button" value="注册" onclick="location.href='zhuce.jsp'"/>
二、对修改页面进行优化
<tr>
<td>活动主题 (不超过20个汉字)</td>
<td>
<label>
<input type="text" name="zhu_ti" value="${requestScope.active.zhu_ti}"/>
</label>
</td>
</tr>
三、多条件模糊查询
String sql = "select * from active where ";
int num=0;
if (zhu_ti != "") {
sql += "zhu_ti like '%" +zhu_ti+ "%' ";
num++;
}
if (lei_xing != "") {
if(num != 0)
sql += "and lei_xing like '%" +lei_xing+ "%' ";
else
sql += " lei_xing like '%" +lei_xing+ "%' ";
num++;
}
if (shi_jian != "") {
if( num !=0 )
sql += "and shi_jian like '%" +shi_jian+ "%' ";
else
sql += " shi_jian like '%" +shi_jian+ "%' ";
num++;
}
if (di_dian != "") {
if(num != 0)
sql += "and di_dian like '%" +di_dian+ "%' ";
else
sql += " di_dian like '%" +di_dian+ "%' ";
num++;
}
//如果不输入,默认查询全部
if(num == 0)
{
sql = "select * from active";
}
Statement state = null;
state = connection.createStatement();
ResultSet rs = state.executeQuery(sql);
四、输入长度的判断
if( zhu_ti.length > 20) { alert('活动主题超出规定长度'); // name.focus(); return false; }
五、模糊查询升级 , 使用Prepared
String sql = "select * from active where zhu_ti like ? and lei_xing like ? and shi_jian like ? and di_dian like ? "; pstmt = connection.prepareStatement(sql); pstmt.setString(1,"%"+zhu_ti+"%"); pstmt.setString(2,"%"+lei_xing+"%"); pstmt.setString(3,"%"+shi_jian+"%"); pstmt.setString(4,"%"+di_dian+"%"); ResultSet rs = pstmt.executeQuery();