页面树结构

版本比较

标识

  • 该行被添加。
  • 该行被删除。
  • 格式已经改变。

...

代码块
var ItemLimitAddr = function() {
 	this.itemName = "限制访问的地址";
 	this.dbKey = "NEW_SYSTEM_CONFIG_ItemLimitAddr";
};
lang.extend(ItemLimitAddr, 'freequery.config.configitem.AbstractSystemConfigItem');
// 进行初始化化动作并返回一个 tr 元素
ItemLimitAddr.prototype.init = function() {
	this.tr = document.createElement("tr");
	this.tr.height = "30";
	this.td1 = document.createElement("td");
	this.td1.align = "left";
	this.td1.width = "200px";
	this.td1.innerHTML = this.itemName + ":";
	this.tr.appendChild(this.td1);
	this.td2 = document.createElement("td");
	this.td2.innerHTML = "<input type='text' name='newConfigItemLimitAddr' id='txt' class='_txt' style='width:100%'>";
	this.tr.appendChild(this.td2);
	this.txt = domutils.findElementByClassName([ this.tr ], "_txt");
	return this.tr;
}
// 检查配置信息是否合法
ItemLimitAddr.prototype.validate = function() {
	return true;
}
// 保存配置并返回是否保存成功 ,对于从系统配置表里的获取数据的配置项来说,返回一个对象
ItemLimitAddr.prototype.save = function() {
	debugger;
	if (!this.validate())
		return false;
	var obj = {
		key : this.dbKey,
		value : this.txt.value
	};
	return obj;
}
// 对于从系统配置表里的获取数据的配置项来说,需要在初始化后根据配置信息来显示
ItemLimitAddr.prototype.handleConfig = function(systemConfig) {
	debugger;
	for ( var i in systemConfig) {
		var config = systemConfig[i];
		if (config && config.key == this.dbKey) {
			
			this.txt.value = config.value;
			break;
		}
	}
};

2.2编写ConfigurationPatch.js添加配置:

代码块
var ConfigurationPatch = {
	extensionPoints : {
		SystemConfig : {
			configItem : [ {
				tabName : "公共设置",
				groupName : "公共设置",
				itemNumber : 99999,
				className : "bof.ext.configitems.ItemLimitAddr"
			} ]
		}
	}
};

 

2.2 编写过滤器拦截处理:3 编写过滤器拦截处理:

代码块
@Override
 public void doFilter(ServletRequest servletRequest,
   ServletResponse servletResponse, FilterChain filterChain)
   throws IOException, ServletException {
  // TODO Auto-generated method stub
  System.out.println("该url正在过滤。。。。。");
  HttpServletRequest request = (HttpServletRequest) servletRequest;
  HttpServletResponse response = (HttpServletResponse) servletResponse;
  servletRequest.setCharacterEncoding("UTF-8");
  
  //获取系统选项的"限制访问的地址"的值
  ConfigClientService cs = ConfigClientService.getInstance();
  ISystemConfig sc = cs.getSystemConfig("NEW_SYSTEM_CONFIG_ItemLimitAddr");
  String value = null;
  if(sc!=null){
   value= sc.getValue();
   }
  
  //获取访问的ip地址
  String ip = request.getLocalAddr();
  LOG.info("ip:"+ip+",value:"+value);
  if (ip.equals(value)) {
   String requestHeader = request.getHeader("user-agent");
   if (LimitAddrFilter.isMobileDevice(requestHeader)) {
    System.out.println("使用手机浏览器");
    filterChain.doFilter(servletRequest, servletResponse);
   } else {
    System.out.println("使用web浏览器");
    response.sendRedirect(request.getContextPath()+"/404/404.jsp");
    return;
   }
  } else {
   filterChain.doFilter(servletRequest, servletResponse);
  }
 }

...