请教用jquery的ajax方法和struts2整合进行一对多查询的源码例子

 我来答
我不是他舅
推荐于2016-08-17 · TA获得超过138万个赞
知道顶级答主
回答量:29.6万
采纳率:79%
帮助的人:32.7亿
展开全部
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"><html><head><script src="jquery.js"></script><script>function sub(){var value1 = $("#id1").val();var value2 = $("#id2").val();if(value1!="" && value2!=""){$.ajax({url:'a.action',type:'post',data:'value1='+value1+'&value2='+value2//data:{value1:value1,value2:value2},dataType:'text',success:function(text){alert(text);}})}}</script></head><body><form id="form1" name="form1"><input type="text" id="id1"/><br /><input type="text" id="id2"/><br /><input type="button" value="提交" onclick="sub();"/></form></body></html>struts.xml:<action name="a" class="com.test.a.action" method="test"></action>a.action:private String value1;private String value2;private String text;get()...set()...public void test()throws Exception{//do somethings HttpServletResponse response = ServletActionContext.getResponse();     response.setContentType("application/json;charset=UTF-8");     response.setCharacterEncoding("UTF-8"); try{   PrintWriter pw  = response.getWriter();   boolean flag = XXXService(value1,value2);   String text = "";   if(flag)   text = "执行成功!";   else   text = "执行失败!";   pw.write(text);   pw.flush();   }catch(Exception e){   e.printStackTrace();   throw new Exception("执行异常!");   }}
推荐律师服务: 若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询

为你推荐:

下载百度知道APP,抢鲜体验
使用百度知道APP,立即抢鲜体验。你的手机镜头里或许有别人想知道的答案。
扫描二维码下载
×

类别

我们会通过消息、邮箱等方式尽快将举报结果通知您。

说明

0/200

提交
取消

辅 助

模 式