我正在通过ajax从jsp页面向servlet发送一个orderid,如果订单表的orderid不匹配,它将在同一个jsp页面中显示一条错误消息,通过该页面可以正常发出请求。现在我的问题是,当我发送有效的 orderid 时,它应该通过 servlet 将页面转发到另一个 jsp 页面,该页面没有发生并且也没有显示任何错误
jsp页面
<input type="hidden" name=cmd value="single"/> Enter Order No <input type="text" name="oid" id="oidss" /><input type="button" value="Search" id="finduy" />
jQuery代码
$('#finduy').click(函数(事件){
$.ajax({
type:'POST',
url:"Order",
style:"full",
maxRows:12,
dataType:"json",
data:{"cmd":"single","oid":encodeURIComponent($('#oidss').val())},
beforeSend:function(){/*alert("data is sending")*/},
//problem is here
success:function(data,textStatus,jqXHR){
if(data.success){
}
else
{
alert("invalid Order No");
$('#oidss').val("");
$('#oidss').focus();
}
},
error:function(jqXHR, textStatus, errorThrown){
console.log('textStatus:' + textStatus);
console.log('errorThrown:' + errorThrown);
console.log("Something really bad happened " + textStatus);
console.log("jqXHR.responseText " +jqXHR.responseText);
$("#ajaxResponse").html(jqXHR.responseText);
}
});
小服务程序代码
if(!(cmd==null)&&cmd.equalsIgnoreCase("single")){
OrderDB odb = new OrderDB();
Order orders = new Order() ;
List<OrderDetail> odetaillist = new ArrayList<OrderDetail>();
List<Order> ordercustlist = new ArrayList<Order>();
String orderids = request.getParameter("oid");
try {
orders = odb.getOrdersById(orderids);
odetaillist = odb.getOrdersDetailsByOrderId(orderids);
ordercustlist = odb.getOrderFromCustomer(orderids);
Customer customerinfo = odb.getOrderCustomer(orderids);
request.setAttribute("OrderSingle", orders);
request.setAttribute("OrderDetail", odetaillist);
request.setAttribute("OrderCust", ordercustlist);
request.setAttribute("CustomerInfo", customerinfo);
redirect=orderinfo;
RequestDispatcher view = request.getRequestDispatcher(redirect);
view.forward(request, response);
if(orders.getOrderid() == null){
JsonObject myobj = new JsonObject();
myobj.addProperty("success", false);
PrintWriter out = response.getWriter();
out.print(myobj);
out.close();
return;
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}