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

📄 webutils.java

📁 本文论述了一个前台笔记本销售系统的开发过程
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
		while (set.hasNext()) {
			Object obj = set.next();
			if (obj instanceof GenericValueObject) {
				temp = (GenericValueObject) obj;
				key = temp.getItemString(keyField);
				if (!"".equals(temp)) {
					value = temp.getItemString(valueField);
					while (true) {
						if (value.length() * 6 >= 100) {
							break;
						}
						value += " ";
					}
					String isDefault = temp.getItemString("ISDEFAULT");
					String isNeed = temp.getItemString("ISNEED");
					buffer.append("<input name='").append(name).append(
							"' type='").append(type).append("' id='").append(
							name).append("' value='").append(key).append("'");
					if (!"".equals(isDefault) && "1".equals(isDefault)) {
						buffer.append(" checked");
					}
					if (isNeed.equals("1")) {
						buffer.append(" disabled=true");
					}
					buffer.append(">");
					buffer.append(value);
					if (i != 0 && ++j % i == 0) {
						buffer.append("&nbsp;&nbsp;<br>");
					}
				}
			}
		}
		return buffer.toString();
	}

	public static String getSelectList(String name, List ht, String keyField,
			String valueField, String type, String onClick) {
		if (null == ht) {
			return "";
		}
		StringBuffer buffer = new StringBuffer();
		Iterator set = ht.iterator();
		GenericValueObject temp;
		String key, value;
		while (set.hasNext()) {
			Object obj = set.next();
			if (obj instanceof GenericValueObject) {
				temp = (GenericValueObject) obj;
				key = temp.getItemString(keyField);
				if (!"".equals(temp)) {
					value = temp.getItemString(valueField);
					buffer.append("<input  name='").append(name).append(
							"' type='").append(type).append("' id='").append(
							name).append("' value='").append(key).append(
							"' onClick='").append(onClick).append("'>");
					buffer.append(value);
				}
			}
		}
		return buffer.toString();
	}

	// public static String getDropDownList(List list,String []fieldName) {
	// if(null==list)
	// return "";
	// if(fieldName.length<3)
	// return "";
	// StringBuffer buffer = new StringBuffer();
	// Iterator it = list.iterator();
	// for(;it.hasNext();) {
	// Object obj = it.next();
	// buffer.append("<option
	// value='").append((String)obj).append("'>").append(ht.get(obj)).append("</option>");
	// }
	// return buffer.toString();
	// }

	/**
	 * 页面生成下拉时间列表,def为默认值
	 * 
	 * @param def
	 *            String
	 * @return String
	 */
	public static String getTimeDropList(String def) {
		StringBuffer buffer = new StringBuffer();
		String time[] = { "00:00", "00:30", "01:00", "01:30", "02:00", "02:30",
				"03:00", "03:30", "04:00", "04:30", "05:00", "05:30", "06:00",
				"06:30", "07:00", "07:30", "08:00", "08:30", "09:00", "09:30",
				"10:00", "10:30", "11:00", "11:30", "12:00", "12:30", "13:00",
				"13:30", "14:00", "14:30", "15:00", "15:30", "16:00", "16:30",
				"17:00", "17:30", "18:00", "18:30", "19:00", "19:30", "20:00",
				"20:30", "21:00", "21:30", "22:00", "22:30", "23:00", "23:30" };
		for (int i = 0; i < time.length; i++) {
			if (def != time[i]) {
				buffer.append("<option value=" + time[i] + ">" + time[i]
						+ "</option>\n");
			} else {
				buffer.append("<option selected value=" + time[i] + ">"
						+ time[i] + "</option>\n");
			}
		}
		return buffer.toString();
	}

	public static String getPagerString(int totalPage, int pageNo) {
		StringBuffer buffer = new StringBuffer();

		if ((totalPage <= 1) || (pageNo == 1)) {
			buffer.append("<u>第一页</u>&nbsp;&nbsp;");
		} else {
			buffer
					.append("<A class =\"clsa1\"   id=\"FirstPage\" onclick=\"onFirstPage();\">第一页</A>&nbsp;&nbsp;");
		}

		if (totalPage <= 1 || pageNo == 1) {
			buffer.append("<u>上一页</u>&nbsp;&nbsp;");
		} else {
			buffer
					.append("<A class =\"clsa1\"  id=\"bPreviousPage\" onclick=\"onPreviousPage();\">上一页</A>&nbsp;&nbsp;");
		}

		if (totalPage <= 1 || pageNo == totalPage) {
			buffer.append("<u>下一页</u>&nbsp;&nbsp;");
		} else {
			buffer
					.append("<A class =\"clsa1\" id=\"bNextPage\" onclick=\"onNextPage();\">下一页</A>&nbsp;&nbsp;");
		}

		if ((totalPage <= 1) || (totalPage == pageNo)) {
			buffer.append("<u>最后一页</u>&nbsp;&nbsp;");
		} else {
			buffer
					.append("<A class =\"clsa1\"  id=\"LastPage\" onclick=\"onLastPage();\">最后一页</A>&nbsp;&nbsp;");
		}

		buffer
				.append("跳转到第&nbsp;        <input  type=\"text\" name=\"ctlGoPageNo\" maxlength=\"3\" size=\"2\" value=\""
						+ pageNo
						+ "\" onkeypress=\"onGoPageNo();\">&nbsp;        页&nbsp;共"
						+ totalPage + "&nbsp;页");
		return buffer.toString();
	}

	public static String getGooglePagerString(int totalPage, int pageNo) {
		StringBuffer buffer = new StringBuffer();

		if (pageNo > 6) {
			buffer
					.append("<A onclick=\"onGoTo(1)\" style=\"cursor:hand \">首页</a>&nbsp;");
		}
		if (totalPage <= 1 || pageNo == 1) {
			buffer.append("<span>");
		} else {
			buffer
					.append("<span> <A id=\"bPreviousPage\" onclick=\"onPreviousPage();\" style=\"cursor:hand \">上一页</A>&nbsp;");
		}
		int lowCnt = pageNo - 5;
		int highCnt = pageNo + 5;
		if (pageNo < 6) {
			highCnt = 10;
		}
		if (pageNo > totalPage - 5) {
			lowCnt = totalPage - 9;
		}

		for (int i = lowCnt; i <= highCnt; i++) {
			if (i > 0 && i <= totalPage) {
				if (i == pageNo) {
					buffer.append("<span style=\"color:#0000FF\" ><u> [" + i
							+ "]</u></span>&nbsp");
				} else {
					buffer.append("<A onclick=\"onGoTo(" + i
							+ ")\" style=\"cursor:hand \">[" + i
							+ "]</a>&nbsp;");
				}
			}
		}

		if (totalPage <= 1 || pageNo == totalPage) {
		} else {
			buffer
					.append("<A id=\"bNextPage\" onclick=\"onNextPage();\" style=\"cursor:hand\">下一页</A>&nbsp;");
		}
		if (pageNo < totalPage - 5) {
			buffer.append("<A onclick=\"onGoTo(" + totalPage
					+ ")\" style=\"cursor:hand \">末页 </a>&nbsp;");
		}
		buffer.append("&nbsp;共" + totalPage + "页");
		buffer.append("</span>");
		return buffer.toString();
	}

	public static String getTreeHTML(String nodeName, int depth,
			String basePath, boolean hasChild) {
		StringBuffer buffer = new StringBuffer();
		String minusImg = "<img align='absmiddle' src='" + basePath
				+ "admin_tree_minusmiddle.gif'>";
		String plusImg = "<img align='absmiddle' src='" + basePath
				+ "admin_tree_plusmiddle.gif'>";
		String empty = "<img align='absmiddle' src='" + basePath
				+ "admin_tree_empty.gif'>";
		String folder = "<img align='absmiddle' src='" + basePath
				+ "admin_tree_folder.gif'/>";
		String line = "<img align='absmiddle' src='" + basePath
				+ "admin_tree_line.gif'/>";
		if (depth > 0) {
			buffer.append(line);
		}
		for (int i = 0; i < depth - 1; i++) {
			buffer.append(empty);
		}

		if (hasChild) {
			buffer.append(minusImg);
		} else {
			buffer.append(plusImg);

		}
		buffer.append(folder);
		buffer.append(nodeName);
		return buffer.toString();
	}

	public static String getTreeHTML2(String nodeName, int depth,
			boolean hasChild) {
		StringBuffer buffer = new StringBuffer();
		String minusImg = " -";
		String plusImg = " +";
		String empty = "_";
		String line = "| ";
		if (depth > 0) {
			buffer.append(line);
		}
		for (int i = 0; i < depth - 1; i++) {
			buffer.append(empty);
		}

		if (hasChild) {
			buffer.append(minusImg);
		} else {
			buffer.append(plusImg);

		}
		buffer.append(nodeName);
		return buffer.toString();
	}

	private static String getTree(String name, int depth, String id) {
		boolean hasChild = false;
		return com.set.utils.WebUtils.getTreeHTML2(name, depth, hasChild);
	}

	public static String genTreeDropDown(List channelList) {

		StringBuffer sb = new StringBuffer();

		try {
			Iterator e = channelList.iterator();
			int i = 0;
			String id, name, depth;

			while (e.hasNext()) {
				GenericValueObject gvo = (GenericValueObject) e.next();

				id = gvo.getItemString("ID");
				name = gvo.getItemString("NAME");
				depth = gvo.getItemString("DEPTH");
				sb.append("<option value=\"" + id + "\">");
				sb.append(getTree(name, Integer.parseInt(depth), id));
				sb.append("</option>");

				i++;

			}
		} catch (Exception e) {
			System.out.println(e.toString() + "\n");
		}
		return sb.toString();
	}

	public static void copyURL(String weburl, String fileOutput)
			throws Exception {
		String args[] = { weburl, fileOutput };
		try {
			URL url = new URL(args[0]);

			InputStream is = url.openStream();

			FileOutputStream fos = null;

			if (args.length < 2) {
				String localFile = null;
				// Get only file name
				StringTokenizer st = new StringTokenizer(url.getFile(), "/");

				while (st.hasMoreTokens()) {
					localFile = st.nextToken();
				}
				fos = new FileOutputStream(localFile);
			} else {
				fos = new FileOutputStream(args[1]);

			}
			int oneChar, count = 0;
			// System.out.println("TEST: begin copy :[" + args[0] + "] to [" +
			// args[1] + "]");
			while ((oneChar = is.read()) != -1) {
				fos.write(oneChar);
				count++;
			}
			// System.out.println("TEST: end copy :[" + args[0] + "] to [" +
			// args[1] + "]");

			is.close();
			fos.close();
		} catch (MalformedURLException e) {
			System.err.println(e.toString());
		} catch (IOException e) {
			System.err.println(e.toString());
		}
	}

	// 根据情况添加或修补了'http://' 前缀后的网址
	public static String getFullWebsite(String url) {
		String pre = "http://";
		if (!"".equals(url)) {
			if (!url.startsWith(pre)) {
				url = pre + url;
			}
		}
		if (url.length() > (4 + pre.length())) {
			return url;
		}
		return "";
	}

	/**
	 * 取得较短的网址路径,即去除 http:// 字样
	 * 
	 * @return String
	 */
	public static String getShortWebsite(String url) {
		String pre = "http://";
		if (!"".equals(url)) {
			if (url.startsWith(pre)) {
				url = url.substring(pre.length(), url.length());
			}
		}
		return url;
	}

	private static ArrayList toList(String array[], boolean isTrim) {
		ArrayList list = new ArrayList();
		String tmp = "";
		for (int i = 0; i < array.length; i++) {
			tmp = array[i];
			if (isTrim) {
				tmp = tmp.trim();
			}
			list.add(tmp);
		}

		return list;
	}


	public static String getRequestUrl(HttpServletRequest request) {
		String result = "";
		String url = request.getRequestURL().toString();

		int index = url.indexOf("?");
		if (index < 0) {
			result = url;
		} else {

		}
		return url;
	}
}

⌨️ 快捷键说明

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