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

📄 gettld.jsp

📁 jsp写的一个简单的售药系统(系统需求分析).采用sql2000数据库,通过odbc连接
💻 JSP
字号:
<%@page contentType="text/html; charset=iso-8859-1" language="java" import="java.net.*,java.io.*,java.util.zip.*,java.util.*"%>

<%
	String uri = request.getParameter("uri");

	if (uri != null)
	{
		int extIndex = uri.lastIndexOf(".");
		if (extIndex != -1)
		{
			String ext		= uri.substring(extIndex+1);
			String tldData	= "";

			ServletContext svc = pageContext.getServletContext();
			uri =  svc.getRealPath(uri);

			try 
			{
				if (ext.equals("tld"))
				{
					tldData = readTLD(uri);
				}
				else if (ext.equals("jar"))
				{
					tldData = readTLDFromJar(uri);
				}
			}
			catch (Exception e)
			{
				tldData = "<ERROR";
				tldData = tldData + " Description=\"";
				String eMessage = e.getMessage();
				eMessage = eMessage.replace('"','\'');
				tldData = tldData + eMessage;
				tldData = tldData + "\"";
				tldData = tldData + " Source=\"\"";
				tldData = tldData + " Identification=\"\"";
				tldData = tldData + " HelpFile=\"\"";
				tldData = tldData + " HelpContext=\"\"";
				tldData = tldData + "></ERROR>";
				tldData = tldData + "</ERRORS>";
			}

			out.println(tldData);
		}	
	}

%>

<%!

public String uri2jarurl(String uri)
{
	 String aUrl = uri;

	 aUrl = aUrl.replace('\\','/');
	 aUrl = "jar:file:///" + aUrl;
	 aUrl = aUrl + "!";	

	 return aUrl;
}

public String readTLD(String filePath) throws Exception
{
    String fileData = "";
	try
	{
		 BufferedReader fs = new BufferedReader(new FileReader(filePath));
		 if (fs != null)
		 {
			String aLine = null;
			aLine = fs.readLine();
			while (aLine != null)
			{
				fileData = fileData + aLine;
				aLine = fs.readLine();
			}
			fs.close();
		 }	
	 }
	 catch (Exception e)
	 {
		throw(e);
	 }
	 return fileData;
}

public String readTLDFromJar(String filePath) throws Exception
{
	String fileData="";

	try 
	{
		Vector tldList = new Vector();
		//Get the list of tld from the jar files in case they may multiple.
		ZipFile zip = new ZipFile(filePath);

		if (zip != null)
		{
			for (Enumeration e = zip.entries() ; e.hasMoreElements() ;) 
			{
				 String fileName = ((ZipEntry)e.nextElement()).getName();
				 if (fileName.indexOf(".tld") != -1)
				 {
					tldList.add(fileName);
				 }
			}												
			zip.close();
		}

		//Convert the uri to jar-prefix.
		String urlprefix = uri2jarurl(filePath);
		for (int i =0 ; i < tldList.size() ; i++)
		{
			String tldFileName = (String)tldList.elementAt(i);
			tldFileName		= urlprefix + "/" + tldFileName;

			URL url  = new URL(tldFileName); 
			if (url != null)
			{
				JarURLConnection aConnection = (JarURLConnection)	url.openConnection();
				if (aConnection != null)
				{
					BufferedReader fs = new BufferedReader(new InputStreamReader(aConnection.getInputStream()));
					if (fs != null)
					{
						String aLine = null;
						aLine = fs.readLine();
						while (aLine != null)
						{
							fileData = fileData + aLine;
							aLine = fs.readLine();
						}
						fs.close();
					}
				}
			}
		}
	}
	catch (Exception e)
	{
		throw(e);
	}

	return fileData;
}

%>

⌨️ 快捷键说明

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