在线注册

注册页面完成得差不多了。做个纪念吧。

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ include file="/entity/common/taglibs.jsp"%>
<html>
	<head>
		<title>${webname}-报名界面</title>
		<%@ include file="/entity/common/artDialog.jsp"%>
		<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
		<meta http-equiv="description" content="This is my page">
		<script type="text/javascript" src="/js/common/Data_location.js"></script>
		<script type="text/javascript" src="/js/My97DatePicker/WdatePicker.js"></script>
		<link rel="stylesheet" href="/js/jquery/plugins/validform/style.css" type="text/css" media="all" />
		<link rel="stylesheet" href="/css/index.css" type="text/css" media="all" />
		<style type="text/css">
.redfont{
	color: red;
	font-size: 15px;
}

#area_td select {
	width: 115px;
}

.lefttd {
	text-align: left;
	padding-left: 10px;
	width: 550px;
}
</style>
		<script type="text/javascript">
		//DOM加载完成后即初始化动态数据,代替onload避免图片加载时的等待		
		$(document).ready(function() {
			getAllDps();
			getAllFolks();
			getAllEducations();
			getAllProvs();
			//makeAllDatas();
		});
		function getAllEducations(){
			$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_getAllEdus.action",
        		async:true,
                dataType:"JSON",
                //error:function(){alert("error");},  
                success:function(result){
                    $.each(result.edus, function(){
                      $("#education").append("<option value="+this.id+" >"+this.name+"</option>");    
                    });
				}   
        	});
		}
		
		function getAllFolks(){
			$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_getAllFolks.action",
        		async:true,
                dataType:"JSON",  
                //error:function(){alert("error");},  
                success:function(result){
                    $.each(result.folks, function(){
                      $("#folk").append("<option value="+this.id+" >"+this.name+"</option>");    
                    });
				}   
        	});
		}
		
		function getAllDps(){
			$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_getAllDepartProperties.action",
        		async:true,
                dataType:"JSON",  
                error:function(){alert("error");},  
                success:function(result){
                    $.each(result.dps, function(){
                      $("#dp").before('<input type="radio" datatype="dept" name="peBzzRecruit.enumConstByFlagDepartProperty.id" value="'+this.id+'"/>'+this.name);
                    });
				}   
        	});
		}
		
		function makeAllDatas(){
			$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_makeAllDatas.action",
        		async:true,
                dataType:"JSON",  
                error:function(){alert("error");},  
                success:function(result){
				}   
        	});
		}
		
		function getAllProvs(){
			for(var index in location_provs){
				var prov = location_provs[index];
				$("#prov").append("<option value="+prov.c+" >"+prov.n+"</option>");
			}
			/*$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_getAllProvinces.action",
                dataType:"JSON",  
                //error:function(){alert("error");},  
                success:function(result){
                    $.each(result.provs, function(){
                      $("#prov").append("<option value="+this.code+" >"+this.name+"</option>");    
                    });
				}   
        	});*/
		}
		function getCitiesByProvCode(){
        	$("#area").empty();  
            $("#area").append("<option value=\"-1\" >请选择</option>");
            $("#city").empty();  
            $("#city").append("<option value=\"-1\" >请选择</option>");
            var prov=$("#prov option:selected").val();
            for(var index in location_cities){
				var city = location_cities[index];
				if(city.p==prov){
					$("#city").append("<option value="+city.c+" >"+city.n+"</option>");
				}
			}
        	/*$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_getCitiesByProvCode.action",
                dataType:"JSON",  
                data:"provCode="+$("#prov option:selected").val(),
                //error:function(){alert("error");},  
                success:function(result){
                	$("#city").empty();  
                    $("#city").append("<option value=\"-1\" >请选择</option>");
                    $.each(result.cities, function(){     
                      $("#city").append("<option value="+this.code+" >"+this.name+"</option>");    
                    });
				}   
        	});*/
        } 
        
        function getAreasByCityCode(){
        	$("#area").empty();  
            $("#area").append("<option value=\"-1\" >请选择</option>");
            var city=$("#city option:selected").val();
            for(var index in location_areas){
				var area = location_areas[index];
				if(area.p==city){
					$("#area").append("<option value="+area.c+" >"+area.n+"</option>");
				}
			}
        	/*$.ajax({                  
        		type:"POST",                  
        		url:"/base/baseData_getAreasByCityCode.action",
                dataType:"JSON",  
                data:"cityCode="+$("#city option:selected").val(),
                //error:function(){alert("error");},  
                success:function(result){
                	$("#area").empty();  
                    $("#area").append("<option value=\"-1\" >请选择</option>");  
                    $.each(result.areas, function(){     
                      $("#area").append("<option value="+this.code+" >"+this.name+"</option>");    
                    });
				}   
        	});*/
        }
	</script>
	</head>

	<body>
		<div class="container">
			<div id="topmenu">
				<IFRAME NAME="topm" width=100% height="217px" frameborder=0 marginwidth=0 marginheight=0 SRC="/public/head.html" scrolling=no
					allowTransparency="true"></IFRAME>
			</div>
			<div class="centent_zxzc">
				<div class="left_zxzc">
					<p>
						以下带*是必填项;已注册用户请勿重复注册,你的默认密码为:111111,请登陆后修改密码,忘记密码请联系我们。请你务必准确填写各项信息,信息的准确度将直接影响你的报名资质及后 期发票、学习资料和结业证书送达工作。
					</p>
				</div>
				<div class="right_zxzc">
					 <div class="zxzc_title"><img src="../images/zxzc_03.gif"></div>
					<form action="/register/peBzzRec_register.action" method="post" class="registerfrm">
						<%@ include file="/web/form-token.jsp"%>
						<table class="datalist3" cellpadding="0" cellspacing="0" width="680">
							<tr>
								<td width="80" rowspan="6" align="center" bgcolor="#f3f3f3">个人信息</td>
								<td width="60">
									<span class="redfont">*</span>用户名
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.ssoUser.userName" ajaxurl="/register/peBzzRec_checkUsername.action" id="loginId" class="inputxt" datatype="u3-19" errormsg="用户名4-20个汉字、字母、下划线和数字!"
										maxlength="30" size="30" />
									<span class="Validform_checktip">用于登录名。长度为4-20,只能输入字母、数字和下划线</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>姓  名
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.name" id="name" class="inputxt" datatype="t2-25" errormsg="姓名2-25个汉字、字母、下划线和数字!" maxlength="25" size="30" />
									<span class="Validform_checktip">请填写您的真实姓名,用于证书发放</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>性  别
								</td>
								<td class="lefttd">
									<input type="radio" name="peBzzRecruit.enumConstByGender.id" datatype="sex" value="402880911da481e0011da4963df60004" checked="checked" />
									男
									<input type="radio" name="peBzzRecruit.enumConstByGender.id" datatype="sex" value="402880911da481e0011da49697130005" />
									女
									<span class="Validform_checktip"></span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>民  族
								</td>
								<td class="lefttd">
									<SELECT id="folk" name="peBzzRecruit.enumConstByFlagFolk.id" datatype="folk">
										<OPTION value="-1">
											---请选择民族---
										</OPTION>
									</SELECT>
									<span class="Validform_checktip"></span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>出生日期
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.birthdayDate" datatype="birth" id="birthday" readonly="readonly" onClick="WdatePicker({maxDate:'%y-%M-%d'})" size="30" />
									<span class="Validform_checktip">请选择您的真实出生日期,用于证书发放。</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>学  历
								</td>
								<td class="lefttd">
									<select id="education" name="peBzzRecruit.enumConstByFlagEducation.id" datatype="edu">
										<option value="-1">
											---请选择学历---
										</option>
									</select>
									<span class="Validform_checktip"></span>
								</td>
							</tr>
							<tr>
								<td width="50" rowspan="9" align="center" bgcolor="#f3f3f3">通讯信息</td>
								<td>
									<span class="redfont">*</span>工作单位
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.department" id="depart" class="inputxt" datatype="t4-25" errormsg="工作单位4-25个汉字、字母、下划线和数字!" maxlength="50"
										size="30" />
									<span class="Validform_checktip">工作单位4-25个汉字、字母、下划线和数字</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>职  称
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.position" id="position" class="inputxt" datatype="t2-15" errormsg="职称2-15个汉字、字母、下划线和数字!" maxlength="30"
										size="30" />
									<span class="Validform_checktip">职称2-15个字符</span>
								</td>
							</tr>
							<tr>
								<td>
									手  机
								</td>
								<td class="lefttd">
									<input type="text" ignore="ignore" name="peBzzRecruit.mobilePhone" οnkeypress="KeyPress(this.value);" id="mobilePhone" class="inputxt mobile" datatype="m"
										errormsg="手机号为11位数字!" maxlength="30" size="30" />
									<span class="Validform_checktip">请输入11位有效手机号,方便学习联系。</span>
								</td>
							</tr>
							<tr>
								<td>
									电  话
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.phone" id="phone" class="inputxt" datatype="phone" errormsg="手机与固话至少填写一项!" nullmsg="手机与固话至少填写一项!" maxlength="30" size="30" />
									<span class="Validform_checktip">例如:0712-7827881,58731118</span>
								</td>
							</tr>
							<tr>
								<td>
									传  真
								</td>
								<td class="lefttd">
									<input type="text" ignore="ignore"  name="peBzzRecruit.fax" id="fax" class="inputxt" datatype="c" errormsg="传真格式为0712-7827881或58731118!" maxlength="30" size="30" />
									<span class="Validform_checktip">和电话号码格式一致</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>Email
								</td>
								<td class="lefttd">
									<input type="text" name="peBzzRecruit.email" id="email" class="inputxt" datatype="e" errormsg="邮箱格式不正确!" maxlength="30"
										size="30" />
									<span class="Validform_checktip">请输入真实邮件地址,用于发送您的报名信息。</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>邮政编码
								</td>
								<td class="lefttd">
									<input type="text" ignore="ignore" name="peBzzRecruit.zipcode" id="zipcode" οnkeypress="KeyPress(this.value);" class="inputxt" datatype="p" errormsg="邮政编码6个数字!" maxlength="30"
										size="30" />
									<span class="Validform_checktip">请输入6位邮政编码</span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>所在地区
								</td>
								<td class="lefttd" id="area_td" colspan="3">
									<select id="prov" name="provcode" οnchange="getCitiesByProvCode();" datatype="city">
										<option value="-1">
											请选择
										</option>
									</select>
									<select id="city" name="citycode" οnchange="getAreasByCityCode();" style="margin-left: 20px;" datatype="city">
										<option value="-1">
											请选择
										</option>
									</select>
									<select id="area" name="peBzzRecruit.peEnterprise.code" style="margin-left: 20px;" datatype="city">
										<option value="-1">
											请选择
										</option>
									</select>
									<span class="Validform_checktip"></span>
								</td>
							</tr>
							<tr>
								<td>
									<span class="redfont">*</span>详细地址
								</td>
								<td class="lefttd" colspan="3">
									<input type="text" name="peBzzRecruit.address" id="address" maxlength="25" size="30" class="inputxt" datatype="t4-25"
										errormsg="地址4-25个汉字、字母、下划线和数字!" maxlength="30" />
									<span class="Validform_checktip">上面选择省市,此处仅写除省市外的详细地址</span>
								</td>
							</tr>
							<tr>
								<td bgcolor="#f3f3f3">
									单位属性
								</td>
								<td class="lefttd" colspan="3">
									<span class="redfont">*</span>
									<span id="dp" class="Validform_checktip">请选择您的单位属性</span>
								</td>
							</tr>
						</table>
						<div style="padding-right: 200px;">
							<input style="display: none;" type="submit" value="提交" id="sub"/>
							<input style="display: none;" type="reset" value="重填" id="res"/>
							<div class="tijiao"><a href="javascript:void(0);" οnclick="$('#res').click();">重填</a></div>
							<div class="tijiao"><a href="javascript:void(0);" οnclick="$('#sub').click();">提交</a></div>
							<br/><br/><br/>
						</div>
					</form>
				</div>
			</div>
			<div id="bottommenu">
				<IFRAME NAME="bottomm" width=100% height="100px" frameborder=0 marginwidth=0 marginheight=0 SRC="/public/bottom.html" scrolling=no
					allowTransparency="true" align="center"></IFRAME>
			</div>
		</div>
	</body>
	<script type="text/javascript" src="/js/jquery/plugins/validform/Validform.js"></script>
	<script type="text/javascript">
$(function() {
	$(".registerfrm").Validform({
		tiptype:function(msg,o,cssctl){
			if(!o.obj.is("form")){//验证表单元素时o.obj为该表单元素,全部验证通过提交表单时o.obj为该表单对象;
				//var objtip=$("#Validform_checktip");
				var objtip=o.obj.siblings(".Validform_checktip");//指定错误提示控件
				cssctl(objtip,o.type);
				objtip.text(msg);
			}
		},
		showAllError:true,//一次性提示所有错误,正式和测试可用
		datatype:{//传入自定义datatype类型
			"u2-4" : /^[0-9a-zA-Z]{1}\w{2,4}$/,//数字和字母开头,后面可以有下划线u2-4和后面的{2,4}数字保持一致
			"c":/^(\d{3,4}-)?\d{7,8}$/,//传真或电话
			"t2-4" : /([\u4E00-\u9FA5\uf900-\ufa2d]|\w){2,4}$/,//中文,字母,下划线和数字
			"phone":function(gets,obj,curform,regxp){
				/*参数gets是获取到的表单元素值,obj为当前表单元素,curform为当前验证的表单,regxp为内置的一些正则表达式的引用。*/
				var reg1=regxp["m"],
					reg2=/(^(\d{3,4}-)?\d{7,8})$/,//电话号码3-4位前,7-8位尾
					mobile=curform.find(".mobile");
				//如果手机和电话号码都不为空
				if(mobile.val()!=""&&gets!=""){
					if(reg1.test(mobile.val())){
						if(reg2.test(gets)){
							return true;
						}else{
							return "电话号码格式不正确。";
						}
					}else{
						return "手机号码格式不正确。";
					}
				}
				if(reg2.test(gets)){
					if(mobile.val()!=""&&mobile.val().replace(/(^\s*)|(\s*$)/g, "")==""){
						return "手机号码不能为空或空格";
					}else{
						return true;
					}
				}
				if(reg1.test(mobile.val())){
					if(gets!=""&&gets.replace(/(^\s*)|(\s*$)/g, "")!=""){
						return "电话号码不能为空或空格";
					}else{
						return true;
					}
				}
				return false;
			},
			"sex":function(gets,obj,curform,regxp){
					numselected=curform.find("input[name='"+obj.attr("name")+"']:checked").length;
				return  numselected == 1 ? true : "请选择性别!";
			},
			"dept":function(gets,obj,curform,regxp){
				numselected=curform.find("input[name='"+obj.attr("name")+"']:checked").length;
				return  numselected == 1 ? true : "请选择单位属性!";
			},
			"city":function(gets,obj,curform,regxp){
				var prov=$("#prov option:selected").val();
	        	if(prov==-1){
	        		return "请选择省份!";
	        	}else{
	        		var c=$("#city").find("option");
		        	if(c.length>1){
		        		var city=$("#city option:selected").val();
		        		if(city==-1){
		        			return "请选择市!";
		        		}else{
		        			var a=$("#area").find("option");
				        	if(a.length>1){
				        		var area=$("#area option:selected").val();
				        		if(area==-1){
				        			return "请选择县!";
				        		}
		        			}
		        		}
	        		}
	        	}
	        	return true;
			},
			"edu":function(gets,obj,curform,regxp){
				var edu=$('#education option:selected').val();
				if(edu=='-1'){
					return "请选择学历!";
				}
				return true;
			},
			"folk":function(gets,obj,curform,regxp){
				var edu=$('#folk option:selected').val();
				if(edu=='-1'){
					return "请选择民族!";
				}
				return true;
			},
			"birth":function(gets,obj,curform,regxp){
				var birth=$('#birthday').val();
				if(birth==''){
					return "请选择出生日期!";
				}
				return true;
			}
		}
	});
})
</script>
</html>

artDialog.jsp:封装好的通用消息弹出窗口,用于提示功能。

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ include file="/entity/common/taglibs.jsp"%>
<html>
	<head>
		<title>${webname}-封装的通用提示界面</title>
		<!--5.0之后使用的方法
			<link id="artDialog-skin" href="/js/jquery/plugins/artDialog/skins/aero.css" rel="stylesheet" />
		<script src="/js/jquery/plugins/artDialog/artDialog.js" type="text/javascript"></script>
		4.0兼容ie6.0+,支持iframe等
		-->
		<script src="/js/jquery/core/jquery-1.8.2.min.js" type="text/javascript"></script>
		<script src="/js/jquery/plugins/artDialog/artDialog.js?skin=green" type="text/javascript"></script>
		<script src="/js/jquery/plugins/artDialog/plugins/iframeTools.js" type="text/javascript"></script>
		<script type="text/javascript">
		function KeyPress(objTR) {
			//只允许录入数据字符 0-9 和小数点 
			//var objTR = element.document.activeElement;		
			var txtval=objTR.value;	
			var key = event.keyCode;
		
			if((key < 48||key > 57)&&key != 46)	{		
				event.keyCode = 0;
				artAlert("只能输入数字");
			} else {
				if(key == 46) {
					if(txtval.indexOf(".") != -1||txtval.length == 0)
						event.keyCode = 0;
				}
			}
		}
		function artAlert(msg,type,lock){
			var icon='';
			if(type=='s'){
				icon='succeed';//成功
			}else if(type=='e'){
				icon='error';
			}else if(type=='q'){
				icon='question';
			}else{
				icon='warning';
			}
			var lo=true;
			if(lock!=true){
				lo=false;
			}
			var dialog=art.dialog({
				//id:'only-one',
				focus:true,//按钮聚焦
				content:msg,
				opacity: 0.37,	// 透明度
				fixed: true,//静止定位,用户滚动窗体时依然居中显示
				lock:lo,//锁屏
				icon:icon,
				ok: function () {
		    	}
			});
		}
		
		function artConfirm(msg,callBack,cancleCallBack){
			var dialog=art.dialog({
				//id:'only-one',
				focus:true,//按钮聚焦
				content:msg,
				opacity: 0.37,	// 透明度
				fixed: true,//静止定位,用户滚动窗体时依然居中显示
				lock:true,//锁屏
				icon:'question',
				ok: function () {
					callBack();
		    	},
				close: function () {//关闭前跳转,避免用户点击右上角的x而停在界面
		    	}
			});
		}
</script>
	</head>
	<body>
	</body>
</html>

taglib.jsp:

<%@ page language="java" pageEncoding="UTF-8" contentType="text/html;charset=utf-8"%>
<%@ taglib prefix="s" uri="/struts-tags"  %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<c:set var="webname" value="全国公共机构节能管理员网络课堂"/>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

之前用过的一个baseDataAction,后来首页静态化后被废弃:

makeAllDatas是生成首页省市县JS数据的方法!非常有用。使用JSON生成。

package com.whaty.platform.entity.web.action.basic;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStreamWriter;
import java.io.UnsupportedEncodingException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.sf.json.JSONArray;

import org.apache.commons.lang.StringUtils;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import com.whaty.platform.entity.bean.EnumConst;
import com.whaty.platform.entity.bean.PeEnterprise;
import com.whaty.platform.entity.exception.EntityException;
import com.whaty.platform.entity.web.action.MyBaseAction;
import com.whaty.platform.util.JsonUtil;

/**
 * @name:BaseDataAction.java
 * @desc:封装所有基本数据,经常使用的数据请使用缓存减少对数据库的读取
 * @author:lizhuang
 * @createTime:2012-10-27 18:58:26
 */
@SuppressWarnings( { "serial", "unchecked" })
public class BaseDataAction extends MyBaseAction {
	@Override
	public void initGrid() {
	}

	@Override
	public void setEntityClass() {
	}

	@Override
	public void setServletPath() {
		this.servletPath = "/base";
	}
	
	//生成省市县JS的方法!此方法用于维护数据字典,非必要时期不要使用。截止2012-12-03系统共3600条省市县数据。 lizhuang
	public void makeAllDatas(){
		DetachedCriteria pe = DetachedCriteria.forClass(PeEnterprise.class);
		pe.createCriteria("peEnterprise", "peEnterprise",DetachedCriteria.LEFT_JOIN);
		pe.addOrder(Order.asc("code"));//排序一下排版更好看一些
		List<PeEnterprise> list = null;
		JSONArray array_provs = new JSONArray();
		JSONArray array_cities = new JSONArray();
		JSONArray array_areas = new JSONArray();
		StringBuffer sb=new StringBuffer();
		try {
			list = this.getGeneralService().getDetachList(pe);
			for (PeEnterprise p : list) {
				if (p.getLevel() == 1) {
					if(!StringUtils.isNumeric(p.getCode())){
						sb.append("数据库异常:"+p.getName()+"的code为空或不是数字!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					Map map = new HashMap();
					map.put("n", p.getName());
					map.put("p", 0);
					map.put("c", Integer.valueOf(p.getCode()));
					//map.put("l", p.getLevel());
					array_provs.add(map);
				} else if (p.getLevel() == 2) {
					if(p.getPeEnterprise()==null){
						sb.append("数据库异常:"+p.getName()+"的父级为空!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					String pcode=p.getPeEnterprise().getCode();
					if(!StringUtils.isNumeric(pcode)){
						sb.append("数据库异常:"+p.getName()+"的父级code为空或不是数字!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					if(!StringUtils.isNumeric(p.getCode())){
						sb.append("数据库异常:"+p.getName()+"的code为空或不是数字!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					Map map = new HashMap();
					map.put("n", p.getName());
					map.put("p",Integer.valueOf(pcode));
					map.put("c", Integer.valueOf(p.getCode()));
					//map.put("l", p.getLevel());
					array_cities.add(map);
				} else if (p.getLevel() == 3) {
					if(!StringUtils.isNumeric(p.getCode())){
						sb.append("数据库异常:"+p.getName()+"的code为空或不是数字!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					if(p.getPeEnterprise()==null){
						sb.append("数据库异常:"+p.getName()+"的父级为空!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					String pcode=p.getPeEnterprise().getCode();
					if(!StringUtils.isNumeric(pcode)){
						sb.append("数据库异常:"+p.getName()+"的父级code为空或不是数字!ID:"+p.getId()+",LEVEL:2");
						continue;
					}
					Map map = new HashMap();
					map.put("n", p.getName());
					map.put("p",Integer.valueOf(pcode));
					map.put("c", Integer.valueOf(p.getCode()));
					//map.put("l", p.getLevel());
					array_areas.add(map);
				}
			}
			String provs = "var location_provs =" + array_provs.toString() + ";";
			String cities = "var location_cities =" + array_cities.toString() + ";";
			String areas = "var location_areas =" + array_areas.toString() + ";";
			System.out.println(provs);
			System.out.println(cities);
			System.out.println(areas);
			OutputStreamWriter osw = null;
			FileOutputStream fos = null;
			try {
				fos = new FileOutputStream("d:\\Data_location.js", false);
				osw = new OutputStreamWriter(fos, "UTF-8");
				osw.write(provs);
				osw.write(System.getProperty("line.separator")+cities);//换行,不要用/r/n这是无效的,也不规范
				osw.write(System.getProperty("line.separator")+areas);
				osw.flush();
			} catch (UnsupportedEncodingException e) {
				e.printStackTrace();
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			} finally {
				try {
					if (osw != null) {
						osw.close();
					}
					if (fos != null) {
						fos.close();
					}
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		} catch (EntityException e) {
			e.printStackTrace();
			getOut().println("0");// 加载数据出错。
		}
		if(sb.length()==0){
			sb.append("生成成功!");
		}
		getOut().println(sb.toString());
	}
	// 获取所有民族
	@SuppressWarnings("unchecked")
	public String getAllFolks() {
		DetachedCriteria pe = DetachedCriteria.forClass(EnumConst.class);
		pe.add(Restrictions.eq("namespace", "FlagFolk"));
		List<PeEnterprise> list = null;
		try {
			list = this.getGeneralService().getDetachList(pe);
		} catch (EntityException e) {
			e.printStackTrace();
			getOut().println("0");// 加载数据出错。
			return null;
		}
		Map map = new HashMap();
		map.put("folks", list);
		this.setJsonString(JsonUtil.toJSONString(map));
		return "json";
	}

	// 获取所有学历
	@SuppressWarnings("unchecked")
	public String getAllEdus() {
		DetachedCriteria pe = DetachedCriteria.forClass(EnumConst.class);
		pe.add(Restrictions.eq("namespace", "FlagEducation"));
		List<PeEnterprise> list = null;
		try {
			list = this.getGeneralService().getDetachList(pe);
		} catch (EntityException e) {
			e.printStackTrace();
			getOut().println("0");// 加载数据出错。
			return null;
		}
		Map map = new HashMap();
		map.put("edus", list);
		this.setJsonString(JsonUtil.toJSONString(map));
		return "json";
	}

	// 获取所有单位属性
	@SuppressWarnings("unchecked")
	public String getAllDepartProperties() {
		DetachedCriteria pe = DetachedCriteria.forClass(EnumConst.class);
		pe.add(Restrictions.eq("namespace", "FlagDepartProperty"));
		List<PeEnterprise> list = null;
		try {
			list = this.getGeneralService().getDetachList(pe);
		} catch (EntityException e) {
			e.printStackTrace();
			getOut().println("0");// 加载数据出错。
			return null;
		}
		Map map = new HashMap();
		map.put("dps", list);
		this.setJsonString(JsonUtil.toJSONString(map));
		return "json";
	}

	// 获取所有省份
	@SuppressWarnings("unchecked")
	public String getAllProvinces() {
		DetachedCriteria pe = DetachedCriteria.forClass(PeEnterprise.class);
		pe.add(Restrictions.isNull("parentCode"));// 查找一级省份,父级为空
		List<PeEnterprise> list = null;
		try {
			list = this.getGeneralService().getDetachList(pe);
		} catch (EntityException e) {
			e.printStackTrace();
			getOut().println("0");// 加载数据出错。
			return null;
		}
		Map map = new HashMap();
		map.put("provs", list);
		this.setJsonString(JsonUtil.toJSONString(map));
		return "json";
	}

	// 级联更新时根据省份查找市级
	@SuppressWarnings("unchecked")
	public String getCitiesByProvCode() {
		String provid = request().getParameter("provCode");
		DetachedCriteria city = DetachedCriteria.forClass(PeEnterprise.class);
		city.add(Restrictions.eq("parentCode", provid));
		List<PeEnterprise> list = null;
		try {
			list = this.getGeneralService().getDetachList(city);
		} catch (EntityException e) {
			e.printStackTrace();
			getOut().println("0");// 加载数据出错。
			return null;
		}
		Map map = new HashMap();
		map.put("cities", list);
		this.setJsonString(JsonUtil.toJSONString(map));
		return "json";
	}

	// 根据市级查找县级单位
	@SuppressWarnings("unchecked")
	public String getAreasByCityCode() {
		String cityid = request().getParameter("cityCode");
		DetachedCriteria area = DetachedCriteria.forClass(PeEnterprise.class);
		area.add(Restrictions.eq("parentCode", cityid));
		List<PeEnterprise> list = null;
		try {
			list = this.getGeneralService().getDetachList(area);
		} catch (EntityException e) {
			e.printStackTrace();
		}
		Map map = new HashMap();
		map.put("areas", list);
		this.setJsonString(JsonUtil.toJSONString(map));
		return "json";
	}
}


上几张图片吧。








  • 3
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 4
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 4
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值