ssi2+ajax实现唯一性验证+showModalDialog刷新父页面

前端之家收集整理的这篇文章主要介绍了ssi2+ajax实现唯一性验证+showModalDialog刷新父页面前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

最近研究了strust2和ajax结合实现方法

先看一下页面

<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<%@	taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglibprefix="fn"uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDXHTML1.01Transitional//EN">
<html>
<head>

<%@includefile="noCache.jsp"%>
<linkrel="stylesheet"type="text/css"href="css/content.css">
<scripttype="text/javascript"src="js/jquery-1.3.2.js"></script>
<styletype="text/css">
.tipclass{
width:150px;
height:30px;
}
</style>
<scripttype="text/javascript">
	
	functionxiugaitextidone(num){
		if(confirm("确认修改吗?")){
			if("报告号可用"==$("#tip").html()){
				document.pageForm.submit();
				setTimeout("doClose()","500");
			}else{
				alert("报告号已存在");
			}
		}
		
	}
	functiondoClose(){
		window.returnValue=1;
		window.close();
	}
	functionfuncheck(){
		$.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><imgsrc='"+$("#path").val()+"/images/onError.gif'/>"+data.str+"</span>");
			}else{
				$("#tip").html(data.str);
			}
		},error:function(){
			alert("错误");
		}
	});
	}
	
</script>
</head>
<basetarget="iframe1"/>
<body>
<inputvalue="${pageContext.request.contextPath}"id="path"type="hidden">
<iframename="iframe1"style="display:none"></iframe>
	<divid="biaoti"class="tbtitle01">
		<b>修改报告号</b>
	</div>
	<divclass="space_h_10"></div>
	<s:formaction="FunctionsAction_updatetextid"
		name="pageForm"method="post">

		<tablewidth="100%"border="0"cellpadding="6"cellspacing="0"
			class="tb_list1">
			<tr>
				<th>样品号</th><td><s:propertyvalue="s.sample_number"/><inputtype="hidden"name="s.sample_number"id="samplenumber"value="${s.sample_number}"/></td>
			</tr>
			<tr><th>报告号</th><td><inputname="s.text_id"id="textid"value="${s.text_id}"onblur="funcheck()"/><divid="tip"class="tipclass"></div></td></tr>
			<tr><th>样品名称</th><td><s:propertyvalue="s.x_prodnm"/></td></tr>
			<tr><th>委托单位</th><td><s:propertyvalue="s.x_orgname"/></td></tr>
			<tr>
				<tdcolspan="4">
					<inputtype="button"value="修改"onclick="xiugaitextidone('<s:propertyvalue="s.sample_number"/>')"/>
<!--					<inputtype="button"value="关闭"onclick="doClose()"/>-->
				</td>
			</tr>
		</table>
	</s:form>
</body>
<c:iftest="${msgnenull}">
		<script>
			alert('${msg}');
		</script>
	</c:if>
</html>

再看一下页面

<%@pagelanguage="java"import="java.util.*"pageEncoding="utf-8"%>
<%@taglibprefix="s"uri="/struts-tags"%>
<%@	taglibprefix="c"uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglibprefix="fn"uri="http://java.sun.com/jsp/jstl/functions"%>
<!DOCTYPEHTMLPUBLIC"-//W3C//DTDXHTML1.01Transitional//EN">
<html>
<head>

<%@includefile="noCache.jsp"%>
<linkrel="stylesheet"type="text/css"href="css/content.css">
<scripttype="text/javascript"src="js/jquery-1.3.2.js"></script>
<scripttype="text/javascript">
functionxiugaitextid(num){
	varreturnValue=window.showModalDialog("FunctionsAction_selectTextidOne?num="+num+"&date="+newDate(),"detail","dialogHeight=450px;dialogWidth=600px;resizable=yes");
	if(returnValue=="1"){
//		window.location.reload();
		varsample_number=$("#sample_number").val();
		vartext_id=$("#text_id").val();
		varpage=pageForm.page.value;
		varpageSize=pageForm.pageSize.value;
		varurl="FunctionsAction_selectSampleBySamplenumberOrTextid?"+
				"sample_number="+sample_number+"&text_id="+text_id+"&page="+page+"&pageSize="+pageSize+"&fromPage=true";
		window.location.href=url;
	}
	
}
functiontoUpperCase(obj){
	varval=$(obj).val();
	$(obj).attr("value",val.toUpperCase());
}
$(document).ready(function(){
	
		$("#sample_number").focus();
	
})

</script>
</head>
<body>
	<divid="biaoti"class="tbtitle01">
		<b>修改报告号</b>
	</div>
	<divclass="space_h_10"></div>
	<s:formaction="FunctionsAction_selectSampleBySamplenumberOrTextid"name="pageForm"method="post">
		样品号:<s:textfieldname="s.sample_number"id="sample_number"></s:textfield>
		报告号:<s:textfieldname="s.text_id"id="text_id"onkeyup="toUpperCase(this)"></s:textfield>
		<s:submitvalue="查询"></s:submit>
	<tablewidth="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:iteratorvalue="samplelist"status="i">
			<tr>
			<td><s:propertyvalue="#i.index+1"/></td>
				<td><s:propertyvalue="sample_number"/></td>
				<td><s:propertyvalue="text_id"/></td>
				<td><s:propertyvalue="x_prodnm"/></td>
				<td><s:propertyvalue="x_orgname"/></td>
				<td><inputtype="button"value="修改"onclick="xiugaitextid('<s:propertyvalue="sample_number"/>')"/></td>
			</tr>
	</s:iterator>
	</table>
	${page}
	</s:form>
	
</body>

</html>

最后看一下后台

publicStringcheckTextid(){
		response.setContentType("text/html;charset=UTF-8");
		Stringtext_id=request.getParameter("text_id");
		Stringsample_number=request.getParameter("sample_number");
		Samplesampleall=this.sampleService.getSampleOne(
				Integer.parseInt(sample_number),Department.ALL);
		inti=0;
		i=this.sampleService.selectByText_id(text_id,Department.getDepartmentFromSample(sampleall));
		Stringdata;
		if(i>0){
			data="{'str':'报告号已存在'}";
			
		}else{
			data="{'str':'报告号可用'}";
		}
		try{
			PrintWriterout=response.getWriter();
			out.print(JSONObject.fromObject(data));
			out.flush();
			out.close();
		}catch(IOExceptione){
			//TODOAuto-generatedcatchblock
			e.printStackTrace();
		}

		returnnull;

	}

说明:后台使用的是json方式,jar包在后面附件里

猜你在找的Ajax相关文章