⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 baseaction.java

📁 本代码是一个权限管理系统源代码
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
				return false;

			if (i != 0 && sNum.equals("-"))
				return false;

			int flag = NUMBER.indexOf(sNum);

			if (flag == -1)
				return false;
		}

		return true;
	}

	/**
	 * 判断字符串是否为整数
	 * @param param 待判断字符串
	 * @return true 是字符串  false 不是字符串
	 */
	public boolean isPositiveInteger(String param) {
		//为空打回
		if (this.check(param))
			return false;

		//整句出现 - 号打回
		if (param.indexOf("-") != -1)
			return false;

		//整句出现 . 号打回
		if (param.indexOf(".") != -1)
			return false;

		//判断是否以 . 开始,- 未出现在第一位置,不在数字界限内,错误打回
		for (int i = 0; i < param.length(); i++) {
			String sNum = param.substring(i, i + 1);

			int flag = BaseAction.POSITIVEINTNUMBER.indexOf(sNum);

			if (flag == -1)
				return false;
		}

		return true;
	}

	/**
	 * 判断参数字符串数组是否为数字
	 * @param param 待判断参数字符串
	 * @return true 是数字  false 不是字符串
	 */
	public boolean isNum(String[] param) {
		if (this.check(param))
			return false;

		for (int i = 0; i < param.length; i++) {
			boolean flag = this.isNum(param[i]);

			if (!flag)
				return false;
		}

		return true;
	}

	/**
	 * 检测是否为数字,不是的话转为 0
	 * @param param 待判断的数字
	 * @return true 是数字 false 非数字
	 */
	public boolean numToChange(String[] param) {
		boolean return_flag = true;

		for (int i = 0; i < param.length; i++) {
			boolean flag = this.isNum(param[i]);

			if (!flag) {
				param[i] = "0";
				return_flag = false;
			}
		}

		return return_flag;
	}

	public int str_to_int(String param) {
		return Integer.parseInt(param);
	}

	public int[] str_to_int(String[] param) {
		int[] temp_int = new int[param.length];

		if (this.isNum(param)) {
			for (int i = 0; i < param.length; i++) {
				temp_int[i] = Integer.parseInt(param[i]);
			}

			return temp_int;
		} else {
			return null;
		}

	}

	public float str_to_float(String param) {
		return Float.parseFloat(param);
	}

	public boolean[] str_to_boolean(String[] param) {
		boolean[] b_param = new boolean[param.length];

		for (int i = 0; i < b_param.length; i++)
			b_param[i] = (new Boolean(param[i])).booleanValue();

		return b_param;
	}

	/**
	 * 初始化 Action,将 request 对象传入以简化操作
	 * @param request HttpServletRequest 对象
	 * @param className 类名称
	 */
	public void initializeAction(HttpServletRequest request, String className) {
		try {
			this.request = request;
			this.session = request.getSession();
			this.session.setMaxInactiveInterval(-1);
			this.className = className;

			if (encodingFlag == 1) {
				request.setCharacterEncoding("UTF-8");
			} else if (encodingFlag == 2) {
				request.setCharacterEncoding("GB2312");
			}

			this.print("进入 [" + className + "] Action.");
		} catch (Exception e) {
			e.printStackTrace();
			this.print("设置编码异常! ");
		}
	}

	/**
	 * 初始化 Action ,参数 notChangeEncoding 作为是否转码的标志,
	 * 这主要是为了解决特定情况下不需要转码的问题
	 * @param request HttpServletRequest 对象
	 * @param changeEncoding 转码标志
	 * @param className 类名称
	 */
	public void initializeAction(HttpServletRequest request, boolean changeEncoding, String className) {
		try {
			this.request = request;
			this.session = request.getSession();
			this.className = className;

			if (changeEncoding) {
				if (encodingFlag == 1) {
					request.setCharacterEncoding("UTF-8");
				} else if (encodingFlag == 2) {
					request.setCharacterEncoding("GB2312");
				}
			}

			this.print("进入 [" + className + "] Action.");

		} catch (Exception e) {
			e.printStackTrace();
			this.print("设置编码异常! ");
		}
	}

	public String getParameter(String paramName) {
		String paramValue = request.getParameter(paramName);

		paramValue = this.exchangeStrParam(paramValue);

		this.print("从 request 接受参数 - " + paramName + " 为 : " + paramValue);

		return paramValue;
	}

	public String[] getParameterValues(String paramName) {
		String[] paramValue = request.getParameterValues(paramName);

		paramValue = this.exchangeStrParam(paramValue);

		if (paramValue != null) {
			for (int i = 0; i < paramValue.length; i++)
				this.print("从 request 接受数组参数 - " + paramName + "[" + i + "] 为 : " + paramValue[i]);
		} else
			paramValue = new String[0];

		return paramValue;
	}

	public Object getAttribute(String paramName) {

		Object obj = this.session.getAttribute(paramName);

		if (obj instanceof String) {
			String paramValue = (String) obj;

			paramValue = this.exchangeStrParam(paramValue);

			this.print("从 session 接受参数 - " + paramName + " 为 : " + paramValue);

			return paramValue;
		} else if (obj instanceof String[]) {
			String[] paramValue = (String[]) obj;

			paramValue = this.exchangeStrParam(paramValue);

			if (paramValue != null) {
				for (int i = 0; i < paramValue.length; i++)
					this.print("从 session 接受数组参数 - " + paramName + "[" + i + "] 为 : " + paramValue[i]);
			}

			return paramValue;
		} else {
			return obj;
		}
	}

	public void setAttribute(String paramName, Object paramValue) {
		this.session.setAttribute(paramName, paramValue);
	}

	public void setAttribute2(String paramName, Object paramValue) {
		
		this.request.setAttribute(paramName, paramValue);
		
		
		
	}

	public void removeAttribute(String paramName) {
		this.session.removeAttribute(paramName);
	}

	private String exchangeStrParam(String paramValue) {

		if (!this.check(paramValue)) {
			paramValue = pc.exchangeParam(paramValue);
			paramValue = paramValue.trim();
		} else {
			paramValue = "";
		}

		return paramValue;
	}

	private String[] exchangeStrParam(String[] paramValue) {
		if (!this.check(paramValue)) {
			for (int i = 0; i < paramValue.length; i++) {
				paramValue[i] = pc.exchangeParam(paramValue[i]);
			}

			paramValue = this.trim(paramValue);
		} else {
			paramValue = new String[0];
		}

		return paramValue;
	}

	public void setCharacterEncoding(HttpServletRequest request) {
		try {
			this.request = request;
			this.session = request.getSession();

			if (encodingFlag == 1) {
				request.setCharacterEncoding("UTF-8");
			} else if (encodingFlag == 2) {
				request.setCharacterEncoding("GB2312");
			}
		} catch (Exception e) {
			e.printStackTrace();
			this.print("设置编码异常! ");
		}
	}
	public boolean regularEmailCheck(String ss){//
	   StringBuffer sb=null;
	   boolean b;
	   int i=0;
	   Matcher m=null; //
	   Pattern p=null; //
	   p = Pattern.compile("[a-zA-Z0-9._-~&$#*]+@[a-zA-Z0-9-_~&$#]+(.[a-zA-Z0-9-_~&$#*]+)[.[a-zA-Z0-9-_~&$#*]+]+");
	   m = p.matcher(ss);
	   b = m.matches();

	   return b;
	 }
	 
	 
	 
	 public boolean isNull(String str){
	 	
	 	if(str!=null&&str.length()>0)
	 				return true;
	 	
	 	return            false;
	 
	 }
	 
	 public int toInt(String str1,String str2){
	 
	 	if(str1.equals(str2))
	 			return 1;
	 			return 0;
	 			
	 
	 }
	 
	 public BigDecimal StringToBigDecimal(String str1){
	 	
	 	return new BigDecimal(str1);
	 
	 }

	//  public static void main(String args[])
	//  {
	//	BaseAction ba = new BaseAction();
	//	System.out.println(ba.isPositiveInteger("-123123312323"));
	//  }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -