在index.jsp用一个input存放存储过程的变量,用AJAX发送此input内容到bets.jsp页面,第一次bets.jsp能执行存储过程,如果第二次点击input换另外内容的话,存储过程就不执行了,找了很久找不到原因,下面是代码源码:
index.jsp部分代码
- HTML code
var url = "bets.jsp?v_guess="+document.getElementById("max1").name +"&v_bets="+document.getElementById("bets1").value +"&v_gameman="+document.getElementById("gameman").innerHTML; XMLHttpReq.open("GET", url, true); XMLHttpReq.send(null); // 发送请求
bets.jsp代码
- HTML code
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%><%@ page import="javax.naming.Context"%><%@ page import="javax.naming.InitialContext"%><%@ page import="java.sql.*"%><% Statement stmt = null; ResultSet rst = null; Context ctx = new InitialContext(); javax.sql.DataSource ds = (javax.sql.DataSource) ctx .lookup("oracledatesource");//建立数据库 java.sql.Connection conn = ds.getConnection(); stmt = conn.createStatement();//获取index传过来的值 String v_guess = request.getParameter("v_guess"); String v_bets = request.getParameter("v_bets"); String v_gameman = request.getParameter("v_gameman"); //执行存储过程 String procedure1 = "{call game_button('"+v_gameman+"')}"; CallableStatement cstmt1 = conn.prepareCall(procedure1); cstmt1.executeUpdate(); //执行存储过程 String procedure = "{call game_js("+v_bets+","+v_guess+",'"+v_gameman+"')}"; CallableStatement cstmt = conn.prepareCall(procedure); cstmt.executeUpdate(); out.close(); rst.close(); conn.close();%>
------解决方案--------------------------------------------------------
如果用的是IE的话,因为是get方式,可以尝试在url后面添加一个随机数,你试下就知道了,比如用js的Math.random(),或者当前时间,总之使url每次不同就可以了。希望对你有帮助。