ssi2+ajax實現唯一性驗證+showModalDialog重新整理父頁面

來源:互聯網
上載者:User

標籤:ajax

最近研究了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 blocke.printStackTrace();}return null;}

說明:後台使用的是json方式,jar包在後面附件裡

ssi2+ajax實現唯一性驗證+showModalDialog重新整理父頁面

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.