http://blog.sina.com.cn/s/blog_4c925dca01009xrb.html
通常,我们在一些网站上,都会有注册功能,在注册的时候,我们通常要判断,该用户名是否已经存在,在用户输入完后,离开时触发事件onblur,数据库中如该用户存在,会有提示信息,不存在,也会有提示信息,那么这个功能是如何实现的呢?
<wbr><wbr><wbr><wbr>下面,阿堂结合单位的一个考试系统中,判断出“试卷”时,该试卷标题是否存在,给出相应信息.</wbr></wbr></wbr></wbr>这里阿堂给出两种方法,一种方法是用ajax,一种方法是用dwr框架(实际上也是对ajax的封装),阿堂认为用dwr框架会更简单
<wbr><wbr><wbr></wbr></wbr></wbr>效果如下
<wbr></wbr>
<wbr><wbr><wbr>两者的优缺点 ajax:配置少,js代码写得多<wbr>;dwr配置多,js代码很少<wbr>,其实配置也得很简单的,朋友们如有建议,欢迎给阿堂留言</wbr></wbr></wbr></wbr></wbr>
<wbr><wbr><wbr><wbr></wbr></wbr></wbr></wbr>第一种情况:用ajax 技术
main.jsp文件(主要代码,下面同上,不再作说明)
<wbr><td width="17%" bgcolor="#6666FF"><strong><font color="#FFFFFF" size="2">试卷标题</font></strong></td><br><wbr><td width="83%"><input name="title" type="text" id="title" onblur="return checkTitle(this.value)"></td><br><wbr><wbr><wbr></tr><br><wbr><wbr><wbr><tr bgcolor="#FFFFFF"><br><wbr><wbr><wbr><wbr><wbr><td bgcolor="#6666FF"><strong><font size="2" color="#FFFFFF">试题组别</font></strong></td><br><wbr><wbr><wbr><wbr><wbr><td> <font size="2" ><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><select name="examgroup" id="examgroup"><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="ISH3仓务组X-SVR" selected>ISH3仓务组X-SVR</option><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="ISH3仓务组P-SVR">ISH3仓务组P-SVR</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH3进货组">ISH3进货组</option><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="ISH3L/S组">ISH3L/S组</option><br><wbr><wbr><option value="ISH3RPR组">ISH3RPR组</option><br><wbr><wbr><option value="ISH1仓务组">ISH1仓务组</option><br><wbr><wbr><option value="ISH2仓务组">ISH2仓务组</option><br><wbr><wbr><option value="PM仓务组">PM仓务组</option><br><wbr><wbr><option value="德宝MBL仓务组">德宝MBL仓务组</option><br><wbr><wbr><option value="德宝其它客户仓务组">德宝其它客户仓务组</option><br><wbr><wbr><option value="ISH1进货组">ISH1进货组</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH2进货组">ISH2进货组</option><br><wbr><wbr><option value="ISH1RPR组">ISH1RPR组</option><br><wbr><wbr><option value="ISH2RPR组">ISH2RPR组</option><br><wbr><wbr><option value="德宝RPR组">德宝RPR组</option><wbr><br><wbr><wbr><wbr><wbr><wbr><option value="ISH1L/S组">ISH1L/S组</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH2L/S组">ISH2L/S组</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH2调度组">ISH2调度组</option><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="沙井综合物流仓务组">沙井综合物流仓务组</option><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr></select><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr></font></td></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr>对应的js代码</wbr>
<wbr><script language="javascript"><br><wbr><wbr>var XMLHttpReq;<wbr><wbr><br><wbr><wbr>// alert(x);<br><wbr><wbr>// onblur="return checkTitle(this.value);"<br><wbr><wbr>//创建XMLHttpRequest对象<wbr><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr>function createXMLHttpRequest()<br><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr>if(window.XMLHttpRequest) { //Mozilla 浏览器<br><wbr><wbr><wbr><wbr>XMLHttpReq = new XMLHttpRequest();<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr>else if (window.ActiveXObject) { // IE浏览器<br><wbr><wbr><wbr><wbr>try {<br><wbr><wbr><wbr><wbr><wbr>XMLHttpReq = new ActiveXObject("Msxml2.XMLHTTP");<br><wbr><wbr><wbr><wbr>} catch (e) {<br><wbr><wbr><wbr><wbr><wbr>try {<br><wbr><wbr><wbr><wbr><wbr><wbr>XMLHttpReq = new ActiveXObject("Microsoft.XMLHTTP");<br><wbr><wbr><wbr><wbr><wbr>} catch (e) {}<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr>}<br><wbr><wbr>}<br><wbr><wbr><br><wbr><wbr>function processResponse() {<br><wbr><wbr><wbr>// alert(XMLHttpReq.responseText);<br><wbr><wbr><wbr><wbr><wbr>if (XMLHttpReq.readyState == 4) { // 判断对象状态<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>if (XMLHttpReq.status == 200) { // 信息已经成功返回,开始处理信息<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>replaceContent();<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>} else { //页面不正常<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>window.alert("您所请求的页面有异常。");<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>window.alert(XMLHttpReq.status);<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr><br><wbr><wbr>function checkTitle(value)<br><wbr><wbr>{<br><wbr><wbr><wbr>var i = document.getElementByIdx("examgroup").selectedIndex;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>var x = document.getElementByIdx("examgroup").options[i].value;<br><wbr><wbr><wbr><wbr><wbr><wbr>var url = "</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr><a href="http://localhost:8081/ishexam/checkTitle.jsp?title=" +value+"&remark="+x" style="text-decoration: none; color: rgb(62, 110, 43); ">http://localhost:8081/ishexam/checkTitle.jsp?title="+value+"&remark="+x;
<wbr><wbr><wbr><wbr><wbr><wbr>// alert(url); 此处传值正常<br><wbr><wbr><wbr><wbr><wbr><wbr>createXMLHttpRequest();<wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr>XMLHttpReq.onreadystatechange = processResponse;<br><wbr><wbr><wbr><wbr><wbr><wbr>XMLHttpReq.open("GET", url, true);<br><wbr><wbr><wbr><wbr><wbr><wbr>XMLHttpReq.send(null);<wbr><br><wbr><wbr>}<br><wbr><wbr><br><wbr><wbr><wbr>function replaceContent()<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr>// alert(XMLHttpReq.responseText);<br><wbr><wbr><wbr>var content=XMLHttpReq.responseText;<br><wbr><wbr><wbr>var str=content.substr(0,3);<br><wbr><wbr><wbr>// alert(content);<wbr><br><wbr><wbr><wbr>if (str=="yes")<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr>alert("对不起,这个组的这套试题已经出过,请重新出");<br><wbr><wbr><wbr><wbr>document.getElementByIdx("title").focus();<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr></script></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
checkTitle.jsp文件
<%@ page language="java" import="java.util.*,com.ish.struts.util.*" pageEncoding="gbk"%>
<%
<wbr>Tools tool=new Tools();<br><wbr>request.setCharacterEncoding("GBK");<br><wbr>String title = new String(request.getParameter("title").trim().getBytes("iso8859-1"),"GBK");<br><wbr>String remark = new String(request.getParameter("remark").trim().getBytes("iso8859-1"),"GBK");<br><wbr>String tempstr;<br><wbr><br><wbr>if(tool.isExistTitleAndRemark(title,remark))<br><wbr>{<br><wbr><wbr>tempstr="yes";</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr>}<br><wbr>else<br><wbr>{<br><wbr><wbr>tempstr="no";</wbr></wbr></wbr></wbr></wbr>
<wbr>}<br><wbr>out.clear();<br><wbr>out.print(tempstr.trim());<br><wbr><br><wbr>%></wbr></wbr></wbr></wbr></wbr>
Tools.java文件中的调用方法
<wbr>//查询exam_paper表是否存在如下title和remark的记录<br><wbr>public boolean isExistTitleAndRemark(String title,String remark)<br><wbr>{<br><wbr><wbr>boolean flag=false;<br><wbr><wbr>conn=gd.getConnection();<wbr><wbr><br><wbr><wbr>String sql="select * from exam_paper where title=? and<wbr>remark=?";<br><wbr><wbr>//String sql1="select title,remark from exam_paper where title='ISH12仓' and<wbr>remark='德宝MBL仓务组'";<br><wbr><wbr>try<br><wbr><wbr>{<br><wbr><wbr><wbr><br><wbr><wbr><wbr>ps=conn.prepareStatement(sql);<br><wbr><wbr><wbr>ps.setString(1, title.trim());<br><wbr><wbr><wbr>ps.setString(2, remark.trim());<br><wbr><wbr><wbr>ResultSet rs=ps.executeQuery();<br><wbr><wbr><wbr>if(rs.next())<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr>flag=true;<br> //<wbr><wbr><wbr><wbr>System.out.println(rs.getString(1));<br> //<wbr><wbr><wbr><wbr>System.out.println(rs.getString(2));<wbr><br><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr>}<br><wbr><wbr>}<br><wbr><wbr>catch(Exception e)<br><wbr><wbr>{<br><wbr><wbr><wbr>e.printStackTrace();<br><wbr><wbr>}<br><wbr><wbr>finally<br><wbr><wbr>{<br><wbr><wbr><wbr>try{<br><wbr><wbr><wbr><wbr>if(conn!=null)<br><wbr><wbr><wbr><wbr><wbr>conn.close();<br><wbr><wbr><wbr>}catch(Exception ex){<br><wbr><wbr><wbr><wbr><wbr>ex.printStackTrace();<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr>}<br><wbr><wbr><br><wbr><wbr>return flag;<br><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
<wbr><span style="color:#0000FF; word-wrap:normal; word-break:normal; line-height:21px"><strong>第二种方法。用dwr来实现<span style="color:#FF0000; word-wrap:normal; word-break:normal; line-height:21px">(导入dwr.jar)</span></strong></span><br></wbr>main.jsp文件
<wbr><wbr><wbr><tr bgcolor="#FFFFFF"><br><wbr><wbr><wbr><wbr><wbr><td width="17%" bgcolor="#6666FF"><strong><font color="#FFFFFF" size="2">试卷标题</font></strong></td><br><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><td width="83%"><input name="title" type="text" id="title" onblur="return checkTitle1(this.value)"></td><br><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr></tr><br><wbr><wbr><wbr><tr bgcolor="#FFFFFF"><br><wbr><wbr><wbr><wbr><wbr><td bgcolor="#6666FF"><strong><font size="2" color="#FFFFFF">试题组别</font></strong></td><br><wbr><wbr><wbr><wbr><wbr><td> <font size="2" ><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><select name="examgroup" id="examgroup"><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="ISH3仓务组X-SVR" selected>ISH3仓务组X-SVR</option><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="ISH3仓务组P-SVR">ISH3仓务组P-SVR</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH3进货组">ISH3进货组</option><wbr><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="ISH3L/S组">ISH3L/S组</option><br><wbr><wbr><option value="ISH3RPR组">ISH3RPR组</option><br><wbr><wbr><option value="ISH1仓务组">ISH1仓务组</option><br><wbr><wbr><option value="ISH2仓务组">ISH2仓务组</option><br><wbr><wbr><option value="PM仓务组">PM仓务组</option><br><wbr><wbr><option value="德宝MBL仓务组">德宝MBL仓务组</option><br><wbr><wbr><option value="德宝其它客户仓务组">德宝其它客户仓务组</option><br><wbr><wbr><option value="ISH1进货组">ISH1进货组</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH2进货组">ISH2进货组</option><br><wbr><wbr><option value="ISH1RPR组">ISH1RPR组</option><br><wbr><wbr><option value="ISH2RPR组">ISH2RPR组</option><br><wbr><wbr><option value="德宝RPR组">德宝RPR组</option><wbr><br><wbr><wbr><wbr><wbr><wbr><option value="ISH1L/S组">ISH1L/S组</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH2L/S组">ISH2L/S组</option><br><wbr><wbr><wbr><wbr><wbr><option value="ISH2调度组">ISH2调度组</option><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><option value="沙井综合物流仓务组">沙井综合物流仓务组</option><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr></select><br><wbr><wbr><wbr><wbr><wbr><wbr><wbr></font></td></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr><span style="color:#000000; word-wrap:normal; word-break:normal; line-height:21px">对应的js代码</span><br><wbr><script type='text/javascript' src='/ishexam/dwr/interface/tools.js'></script><br><wbr><script type='text/javascript' src='/ishexam/dwr/engine.js'></script><br><wbr><script type='text/javascript' src='/ishexam/dwr/util.js'></script><br><wbr><wbr><script><br><wbr><wbr><wbr>function checkTitle1(value)<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr>var i = document.getElementByIdx("examgroup").selectedIndex;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>var x = document.getElementByIdx("examgroup").options[i].value;<br><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr><wbr>tools.isExistTitleAndRemark1(value,x,callBackResult);<br><wbr><wbr><wbr>}<br><wbr><wbr><wbr><br><wbr><wbr><wbr>function callBackResult(data)<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr>if(data!="")<br><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr>alert(data);<br><wbr><wbr><wbr><wbr><wbr><wbr>document.getElementByIdx("title").focus();<br><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr><wbr><wbr>else<br><wbr><wbr><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr><wbr><wbr>}<br><wbr><wbr><wbr>}<br><wbr><wbr><br><wbr></script></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
Tools.java文件中对应的方法如下
<wbr>public String isExistTitleAndRemark1(String title,String remark)<br><wbr>{<br><wbr><wbr>String flag="";<br><wbr><wbr>conn=gd.getConnection();<wbr><wbr><br><wbr><wbr>String sql="select * from exam_paper where title=? and<wbr>remark=?";<br><wbr><wbr>//String sql1="select title,remark from exam_paper where title='ISH12仓' and<wbr>remark='德宝MBL仓务组'";<br><wbr><wbr>try<br><wbr><wbr>{<br><wbr><wbr><wbr><br><wbr><wbr><wbr>ps=conn.prepareStatement(sql);<br><wbr><wbr><wbr>ps.setString(1, title.trim());<br><wbr><wbr><wbr>ps.setString(2, remark.trim());<br><wbr><wbr><wbr>ResultSet rs=ps.executeQuery();<br><wbr><wbr><wbr>if(rs.next())<br><wbr><wbr><wbr>{<br><wbr><wbr><wbr><wbr>flag="对不起,这个组的这套试题已经出过,请重新出";<br> //<wbr><wbr><wbr><wbr>System.out.println(rs.getString(1));<br> //<wbr><wbr><wbr><wbr>System.out.println(rs.getString(2));<wbr><br><wbr><wbr><wbr><wbr><br><wbr><wbr><wbr>}<br><wbr><wbr>}<br><wbr><wbr>catch(Exception e)<br><wbr><wbr>{<br><wbr><wbr><wbr>flag="";<br><wbr><wbr><wbr>e.printStackTrace();<br><wbr><wbr>}<br><wbr><wbr>finally<br><wbr><wbr>{<br><wbr><wbr><wbr>try{<br><wbr><wbr><wbr><wbr>if(conn!=null)<br><wbr><wbr><wbr><wbr><wbr>conn.close();<br><wbr><wbr><wbr>}catch(Exception ex){<br><wbr><wbr><wbr><wbr><wbr>ex.printStackTrace();<br><wbr><wbr><wbr><wbr>}<br><wbr><wbr>}<br><wbr><wbr><br><wbr><wbr>return flag.trim();<br><wbr>}</wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
<wbr></wbr>
<wbr><span style="color:#000000; word-wrap:normal; word-break:normal; line-height:21px">web.xml文件中配置</span><br><wbr><servlet><br><wbr><wbr><wbr><wbr><wbr><servlet-name>dwr-invoker</servlet-name><br><wbr><wbr><wbr><wbr><wbr><servlet-class> org.directwebremoting.servlet.DwrServlet </servlet-class><br><wbr><wbr><wbr><init-param><br><wbr><wbr><wbr><wbr><wbr><param-name>debug</param-name><br><wbr><wbr><wbr><wbr><wbr><param-value>true</param-value><br><wbr><wbr><wbr><wbr><wbr><wbr></init-param><br><wbr></servlet><br><wbr><br><wbr><servlet-mapping><wbr><wbr><wbr><br><wbr><wbr><wbr><servlet-name>dwr-invoker</servlet-name><br><wbr><wbr><wbr><url-pattern>/dwr/*</url-pattern><br><wbr></servlet-mapping></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
<wbr>在web-inf目录下生成一个<strong>dwr.xml</strong>文件,配置如下</wbr>
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE dwr PUBLIC "-//GetAhead Limited//DTD Direct Web Remoting
2.0//EN" "http://www.getahead.ltd.uk/dwr/dwr20.dtd">
<wbr><br> <dwr><br><wbr><allow><br><wbr><wbr><wbr><create creator="new" javascript="tools"><br><wbr><wbr><wbr><wbr><wbr><param name="class" value="com.ish.struts.util.Tools" /><br><wbr><wbr><wbr></create><br><wbr></allow><br> </dwr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr></wbr>
<wbr></wbr>
导入包dwr.jar包