1、模糊查询的参数问题?
一般思路:
String sql = "select * from product where pname like‘%’+ ? +‘%’";
(写法有问题)
正确写法:
String sql = "select * from product where pname like ?";
return qr.query(sql, new BeanListHandler<Product>(Product.class), "%"+productname+"%");
2、jsp表单中的序号自增长的问题
<c:forEach items="${cartList }" var="cartItem" varStatus="status">
<td class="tab_1">${status.index+1 }</td>
</c:foreEach>
3、jsp表单中数组长度问题
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%>
<c:when test="${empty cart or fn:length(cart.cartItems) eq 0}">
<h1>您的购物车,空空如也!!!</h1>
</c:when>
4、后台(servlet)获取下拉框中的值
<select name="select">
<option value="sh" selected="selected">上海</option>
</select>
request.getParameter("select")
获取的只能是option中的value值
5、javascript获取表单中下拉框的值
var province = document.getElementById("province");
var pname = province.options[province.delectedIndex].text/value;
6、清空下拉列表的值
var city = document.getElementById("city");
city.innerHTML = "<option>---请选项---</option>";
7、运用反射得到当前方法的method对象
//Method method = clazz.getDeclaredMethid("方法名称", 参数类型的class对象, ... );
Method method = clazz.getDeclaredMethid("account", String.class, int.class);
8、后台对页面中运用循环遍历出来的商品信息的数量进行获取
String[] counts = request.getParameterValues("count");
9、button按钮控制提交表单提交(顺带实现不同的提交路径)
<form id="form" action="" method="post">
<input type="button" id="querrybyid" value="ID查询" onclick="is_submit(1)"/>
<input type="button" id="querrybyname" value="片名查询" onclick="is_submit(2)" />
</form>
<script type="text/javascript">
function is_submit(value) {
var form1 = $("#form1");
if (value == 1) {
var id = $("#id").val();
form1.action = "/Test/querrybyid?id="+id;
$("#form1").attr("action",form1.action);
form1.submit();
}
if (value == 2) {
var title = $("#title").val();
form1.action = "/Test/querrybyname?title=" + title;
$("#form1").attr("action", form1.action);
form1.submit();
}
}
</script>