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

📄 netservlet.java

📁 derby database source code.good for you.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
			printErrorForm(localUtil, request, e, returnMessage);		}		return retval;	}	/**	 *	Turn logging of connections on	 *	 * @param localUtil	LocalizedResource to use to translate messages	 * @param request HttpServetRequest for  forms	 * @param returnMessage	localized continue message for continue button on error form		 * @return true if succeeded; false; otherwise	 */	private boolean logging(LocalizedResource localUtil, boolean val,		HttpServletRequest request, String returnMessage)	{		boolean retval = false;		try {			server.logConnections(val);			retval = true;		} catch (Exception e) 		{			printErrorForm(localUtil, request, e, returnMessage);		}		return retval;	}	/**	 *	Change tracing for all sessions 	 *	 * @param localUtil	LocalizedResource to use to translate messages	 * @param val	if true, turn tracing on, if false turn it off	 * @param request HttpServetRequest for  forms	 * @param returnMessage	localized continue message for continue button on error form		 * @return true if succeeded; false; otherwise	 */	private boolean traceAll(LocalizedResource localUtil, boolean val,		HttpServletRequest request, String returnMessage)	{		boolean retval = false;		try {			server.trace(val);			retval = true;		} catch (Exception e) 		{			printErrorForm(localUtil, request, e, returnMessage);		}		return retval;	}	/**	 *	Change tracing for a given session	 *	 * @param localUtil	LocalizedResource to use to translate messages	 * @param val	if true, turn tracing on, if false turn it off	 * @param session	session to trace	 * @param request HttpServetRequest for  forms	 * @param returnMessage	localized continue message for continue button on error form		 * @return true if succeeded; false; otherwise	 */	private boolean traceSession(LocalizedResource localUtil, boolean val, int session,		HttpServletRequest request, String returnMessage)	{		boolean retval = false;		try {			server.trace(session, val);			retval = true;		} catch (Exception e) 		{			printErrorForm(localUtil, request, e, returnMessage);		}		return retval;	}	/**	 * Set trace directory	 *	 * @param localUtil	LocalizedResource to use to translate messages	 * @param traceDirectory	directory for trace files	 * @param request 			HttpServetRequest for  forms	 * @param returnMessage		localized continue message for continue 	 *							button on error form		 * @return true if succeeded; false; otherwise	 */	private boolean traceDirectory(LocalizedResource localUtil, String traceDirectory,		HttpServletRequest request, String returnMessage)	{		boolean retval = false;		if ((traceDirectory == null) || traceDirectory.equals("")) {			printErrorForm(localUtil, request,				localUtil.getTextMessage("SRV_MissingParam",				localUtil.getTextMessage("SRV_TraceDir")), returnMessage);			return retval;		}		try {			server.setTraceDirectory(traceDirectory);			retval = true;		} catch (Exception e) 		{			printErrorForm(localUtil, request, e, returnMessage);		}		return retval;	}	/**	 * Set Network server parameters	 *	 * @param localUtil	LocalizedResource to use to translate messages	 * @param max				maximum number of threads	 * @param slice				time slice for each connection	 * @param request 			HttpServetRequest for  forms	 * @param returnMessage		localized continue message for continue 	 *							button on error form		 * @return true if succeeded; false; otherwise	 */	private boolean setNetParam(LocalizedResource localUtil, int max, int slice,		HttpServletRequest request, String returnMessage)	{		boolean retval = false;		try {			server.setMaxThreads(max);			server.setTimeSlice(slice);			retval = true;		} catch (Exception e) 		{			printErrorForm(localUtil, request, e, returnMessage);		}		return retval;	}	/** 	 * Set defaults for logging and tracing (both off)	 */	private void setDefaults()	{		logStatus = false;		traceStatus = false;	}	/**	 * Get an integer parameter	 *	 * @param request 			HttpServetRequest for  forms	 * @param name				parameter name	 * @param fieldKey			Key for the name of the field we're reading.	 * @param localUtil				LocalizedResource to use in localizing messages	 * @param returnMessage		localized continue message for continue 	 *							button on error form		 */	private int getIntParameter(HttpServletRequest request,			String name, String fieldKey, LocalizedResource localUtil, String returnMessage)	{		String val = request.getParameter(name);		int retval;		if (val == null || val.equals(""))			return NOT_GIVEN;		try {		 	retval = (new Integer(val)).intValue();		} catch (Exception e) {			printErrorForm(localUtil, request,localUtil.getTextMessage("SRV_InvalidVal",				val, localUtil.getTextMessage(fieldKey)), returnMessage);			return INVALID;		}		if (retval < 0) {		// negative integers not allowed for the parameters we're getting.			printErrorForm(localUtil, request, localUtil.getTextMessage("SRV_InvalidVal",				val, localUtil.getTextMessage(fieldKey)), returnMessage);			return INVALID;		}		return retval;	}	/**	 * Print Derby Network Server banner	 */	private void printBanner(LocalizedResource localUtil)	{		out.println("<a href=\"#navskip\">[ " +		localUtil.getTextMessage("SRV_SkipToContent") + " ]</a>");		out.println("  -  <a href=\"" + SERVLET_ADDRESS + "\">[ " +		localUtil.getTextMessage("SRV_BackToMain") + " ]</a>");		out.println( "<html>" );				out.println( "<title>"+localUtil.getTextMessage("SRV_Banner")+"</title>" );		out.println( "<body>" ); 			out.println( "<hr>" );		out.println( "<h1>"+localUtil.getTextMessage("SRV_Banner")+"</h1>" );		out.println( "<hr>" );	}	/**	 * Determine the locale file needed for this browsers preferences	 * Defaults to the settings for derby.locale and derby.codeset if set	 *		English otherwise if browsers preferences can't be found	 *	 * @param request 			HttpServetRequest for forms	 * @return the appUI which fits the browsers preferences	 */	private LocalizedResource getCurrentAppUI(HttpServletRequest request)	{		LocalizedResource localUtil;		String acceptLanguage = request.getHeader("Accept-Language");		localUtil = new LocalizedResource(null,null,SERVLET_PROP_MESSAGES);		// if no language specified use one set by derby.locale, derby.codeset		locale = null;		if (acceptLanguage == null)		{			return localUtil;		}		// Use a tokenizer ot separate acceptable languages		StringTokenizer tokenizer = new StringTokenizer(acceptLanguage, ",");		while (tokenizer.hasMoreTokens())		{			//Get the next acceptable language			String lang = tokenizer.nextToken();			lang = getLocStringFromLanguage(lang);			int langindex = translationAvailable(lang);			// have we found one			if (langindex != -1)			{				localUtil.init(null, lang, SERVLET_PROP_MESSAGES);				// locale will be passed to server, server routines will get set appropriately				locale = lang;				return localUtil;			}		}		// nothing worked use defaults		return localUtil;			}	/**	 * Get locale string from language which may have qvalue set	 * 	 * @param lang	language string to parse	 *	 * @return stripped language string to use in matching	 */	private String getLocStringFromLanguage(String lang)	{		int semi;		// Cut off any q-value that might come after a semi-colon		if ((semi = lang.indexOf(';')) != -1)		{			lang = lang.substring(0, semi);		}		// trim any whitespace		lang = lang.trim();				return lang;	}	/**	 * Check if the required translation is available	 *	 * @param lang	language we are looking for	 * 	 * @return index into language array if found, -1 otherwise;	 */	private int translationAvailable(String lang)	{		for (int i = 0; i < knownLang.length; i++)			if (knownLang[i].toUpperCase(Locale.ENGLISH).equals(lang.toUpperCase(Locale.ENGLISH)))				return i;		return -1;	}	/**	 * get an HTML labelled message from the resource bundle file, according to	 * the given key.	 */	public String getHtmlLabelledMessageInstance(LocalizedResource localUtil, String key, String id) {		if (id == null)			id = "";		return ("<label for='" + id + "'>" + localUtil.getTextMessage(key) +			"</label>");	}	/**	 * Print the received string as a header.	 * @param str The string to be printed as a header.	 */	private void printAsContentHeader(String str) {		out.println("<a name=\"navskip\"></a><h2>" + str + "</h2>");		return;	}	/**	 * If the received string has one or more single quotes	 * in it, replace each one with the HTML escape-code	 * for a single quote (apostrophe) so that the string 	 * can be properly displayed on a submit button.	 * @param str The string in which we want to escape	 *  single quotes.	 */	private String escapeSingleQuotes(String str) {		if ((str == null) || (str.indexOf("'") < 0))			return str;		char [] cA = str.toCharArray();		// Worst (and extremely unlikely) case is every 		// character is a single quote, which means the		// escaped string would need to be 4 times as long.		char [] result = new char[4*cA.length];		int j = 0;		for (int i = 0; i < cA.length; i++) {			if (cA[i] == '\'') {				result[j++] = '&';				result[j++] = '#';				result[j++] = '3';				result[j++] = '9';			}			else				result[j++] = cA[i];		}		return new String(result, 0, j);	}	private static boolean isServerStarted(NetworkServerControl server, int ntries)	{		for (int i = 1; i <= ntries; i ++)		{			try {				Thread.sleep(500);				server.ping();				return true;			}			catch (Exception e) {				if (i == ntries)					return false;			}		}		return false;	}	}

⌨️ 快捷键说明

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