ssi2+ajax实现唯一性验证+showModalDialog刷新父页面
最近研究了strust2和ajax结合实现方法
先看一下页面①
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.01 Transitional//EN"> <html> <head> <%@ include file="noCache.jsp"%> <link rel="stylesheet" type="text/css" href="css/content.css"> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <style type="text/css"> .tipclass{ width: 150px; height:30px; } </style> <script type="text/javascript"> function xiugaitextidone(num) { if(confirm("确认修改吗?")){ if("报告号可用"==$("#tip").html()){ document.pageForm.submit(); setTimeout("doClose()","500"); }else{ alert("报告号已存在"); } } } function doClose(){ window.returnValue = 1; window.close(); } function funcheck(){ $.ajax({ type : ‘post‘, url : ‘FunctionsAction_checkTextid‘, dataType:‘json‘, data : { "text_id":$("#textid").val(), "sample_number":$("#samplenumber").val() }, success : function(data) { if("报告号已存在"==data.str){ $("#tip").html("<span ><img src=‘"+$("#path").val()+"/images/onError.gif‘ />"+data.str+"</span>"); }else{ $("#tip").html(data.str); } }, error:function(){ alert("错误"); } }); } </script> </head> <base target="iframe1"/> <body> <input value="${pageContext.request.contextPath}" id="path" type="hidden"> <iframe name="iframe1" style="display:none"></iframe> <div id="biaoti" class="tbtitle01"> <b>修改报告号</b> </div> <div class="space_h_10"></div> <s:form action="FunctionsAction_updatetextid" name="pageForm" method="post"> <table width="100%" border="0" cellpadding="6" cellspacing="0" class="tb_list1"> <tr> <th>样品号</th><td><s:property value="s.sample_number" /><input type="hidden" name="s.sample_number" id="samplenumber" value="${s.sample_number }"/></td> </tr> <tr><th>报告号</th><td><input name="s.text_id" id="textid" value="${ s.text_id}" onblur="funcheck()" /><div id="tip" class="tipclass"></div></td></tr> <tr><th>样品名称</th><td><s:property value="s.x_prodnm" /></td></tr> <tr><th>委托单位</th><td><s:property value="s.x_orgname" /></td></tr> <tr> <td colspan="4"> <input type="button" value="修改" onclick="xiugaitextidone(‘<s:property value="s.sample_number" />‘)" /> <!-- <input type="button" value="关闭" onclick="doClose()"/> --> </td> </tr> </table> </s:form> </body> <c:if test="${msg ne null }"> <script> alert(‘${msg}‘); </script> </c:if> </html>
再看一下页面②
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%> <%@ taglib prefix="s" uri="/struts-tags"%> <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%> <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD XHTML 1.01 Transitional//EN"> <html> <head> <%@ include file="noCache.jsp"%> <link rel="stylesheet" type="text/css" href="css/content.css"> <script type="text/javascript" src="js/jquery-1.3.2.js"></script> <script type="text/javascript"> function xiugaitextid(num){ var returnValue = window.showModalDialog("FunctionsAction_selectTextidOne?num="+num+"&date="+new Date(), "detail","dialogHeight=450px;dialogWidth=600px;resizable=yes"); if(returnValue=="1"){ // window.location.reload(); var sample_number=$("#sample_number").val(); var text_id=$("#text_id").val(); var page = pageForm.page.value; var pageSize = pageForm.pageSize.value; var url = "FunctionsAction_selectSampleBySamplenumberOrTextid?"+ "sample_number="+sample_number+"&text_id="+text_id+"&page="+page+"&pageSize="+pageSize+"&fromPage=true"; window.location.href=url; } } function toUpperCase(obj){ var val = $(obj).val(); $(obj).attr("value",val.toUpperCase()); } $(document).ready(function(){ $("#sample_number").focus(); }) </script> </head> <body> <div id="biaoti" class="tbtitle01"> <b>修改报告号</b> </div> <div class="space_h_10"></div> <s:form action="FunctionsAction_selectSampleBySamplenumberOrTextid" name="pageForm" method="post"> 样品号:<s:textfield name="s.sample_number" id="sample_number"></s:textfield> 报告号:<s:textfield name="s.text_id" id="text_id" onkeyup="toUpperCase(this)"></s:textfield> <s:submit value="查询"></s:submit> <table width="100%" border="0" cellpadding="6" cellspacing="0" class="tb_list1"> <tr> <th>序号</th> <th>样品号</th> <th>报告号</th> <th>样品名称</th> <th>委托单位</th> <th>操作</th> </tr> <s:iterator value="samplelist" status="i"> <tr> <td><s:property value="#i.index+1" /></td> <td><s:property value="sample_number" /></td> <td><s:property value="text_id" /></td> <td><s:property value="x_prodnm" /></td> <td><s:property value="x_orgname" /></td> <td><input type="button" value="修改" onclick="xiugaitextid(‘<s:property value="sample_number" />‘)"/> </td> </tr> </s:iterator> </table> ${page } </s:form> </body> </html>
最后看一下后台
public String checkTextid() { response.setContentType("text/html;charset=UTF-8"); String text_id = request.getParameter("text_id"); String sample_number = request.getParameter("sample_number"); Sample sampleall = this.sampleService.getSampleOne( Integer.parseInt(sample_number), Department.ALL); int i = 0; i = this.sampleService.selectByText_id(text_id, Department.getDepartmentFromSample(sampleall)); String data; if (i > 0) { data = "{‘str‘:‘报告号已存在‘}"; } else { data = "{‘str‘:‘报告号可用‘}"; } try { PrintWriter out = response.getWriter(); out.print(JSONObject.fromObject(data)); out.flush(); out.close(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return null; }
说明:后台使用的是json方式,jar包在后面附件里
郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。