Spring MVC 从jsp页面传值到Controller方法里

我的后台代码
@RequestMapping("/query")
public String queryByOrderId(HttpServletRequest request,@RequestParam(value="orderId",required=false) Long orderId , Model model) throws ParseException{
DataOrder order = biz.getById(orderId);
String points = "该订单不存在!";
if(order == null){
request.setAttribute("points", points);
}else{
List<DataOrder> listDataOrder = biz.queryorderByOrderId(orderId);
model.addAttribute("listDataOrder", listDataOrder);
}
return ACTION + "listOrders.jsp" ;
}

前台
<strong>订单号:</strong>
<input type="submitQuery" id="queryTxt" name="orderId"/>

<a href="<%=basePath%>dataOrder/queryorder.do?orderId=${orderId}">搜索</a>

报错信息
org.springframework.jdbc.UncategorizedSQLException: Error setting null parameter. Most JDBC drivers require that the JdbcType must be specified for all nullable parameters. Cause: java.sql.SQLException: 无效的列类型
; uncategorized SQLException for SQL []; SQL state [null]; error code [17004]; 无效的列类型; nested exception is java.sql.SQLException: 无效的列类型
说是orderId为空,应该怎么改,求教

orderId 不能为空。

前端 orderId 的获取不能用 ${orderId}. 应该用javascript的 document.getElementById("queryTxt") 获取到 input 对象框,然后 input.value的方式去取orderId的值,最后点击url时把它传到后端。

温馨提示:答案为网友推荐,仅供参考
第1个回答  2013-09-04

${orderId} 这个没取到标签的值吧,建议用按钮<button onclick="fuc()">

再写个

fuc(){
    var vv = document.getElementById("queryTxt").value;
    window.open("<%=basePath%>dataOrder/queryorder.do?orderId="+vv) ;
}

这样就可以了

追问

你说的我试过了,值是可以取到了,window.open是打开新的页面,我就想在原有的页面显示结果,应该怎么弄

本回答被提问者采纳
相似回答