???????????????????????????????????????????????дfindClass??????
???????JDK?????loadClass?????а??????????ClassLoader???????????????loadClass???????????????????loadClass?????????findClass?????????????????????????д?÷??????ɡ???????????????????????дloadClass????????????????API??ClassLoader??loadClass??????

?????????????????NetworkClassLoader????????????????class???
????package classloader;
????import java.io.ByteArrayOutputStream;
????import java.io.InputStream;
????import java.net.URL;
????/**
????*????????class??ClassLoader
????*/
????public class NetworkClassLoader extends ClassLoader{
????private String rootUrl;
????public NetworkClassLoader(String rootUrl){
????this.rootUrl=rootUrl;
????}
????@Override
????protected Class<?>findClass(String name)throws ClassNotFoundException{
????Class clazz=null;//this.findLoadedClass(name);//?????????
????//if(clazz==null){//?????????????????
????byte[]classData=getClassData(name);//?????????????????????class??????????????
????if(classData==null){
????throw new ClassNotFoundException();
????}
????clazz=defineClass(name??classData??0??classData.length);//??class????????????????Class??????
????//}
????return clazz;
????}
????private byte[]getClassData(String name){
????InputStream is=null;
????try{
????String path=classNameToPath(name);
????URL url=new URL(path);
????byte[]buff=new byte[1024*4];
????int len=-1;
????is=url.openStream();
????ByteArrayOutputStream baos=new ByteArrayOutputStream();
????while((len=is.read(buff))!=-1){
????baos.write(buff??0??len);
????}
????return baos.toByteArray();
????}catch(Exception e){
????e.printStackTrace();
????}finally{
????if(is!=null){
????try{
????is.close();
????}catch(IOException e){
????e.printStackTrace();
????}
????}
????}
????return null;
????}
????private String classNameToPath(String name){
????return rootUrl+"/"+name.replace("."??"/")+".class";
????}
????}
??????????
????package classloader;
????public class ClassLoaderTest{
????public static void main(String[]args){
????try{
????/*ClassLoader loader=ClassLoaderTest.class.getClassLoader();//???ClassLoaderTest?????????????
????while(loader!=null){
????System.out.println(loader);
????loader=loader.getParent();//????????????????
????}
????System.out.println(loader);*/
????String rootUrl="http://localhost:8080/httpweb/classes";
????NetworkClassLoader networkClassLoader=new NetworkClassLoader(rootUrl);
????String classname="org.classloader.simple.NetClassLoaderTest";
????Class clazz=networkClassLoader.loadClass(classname);
????System.out.println(clazz.getClassLoader());
????}catch(Exception e){
????e.printStackTrace();
????}
????}
????}
????????????

????????????????web??????????????

??????????web???????ж????????????????????????????web?????????μ????jar??class?????磺Weblogic??Jboss??tomcat???????????Tomcat?????????web??????????????Щ???????????
????1????????web????httpweb
????2????????ClassLoaderServletTest????????web?????е?ClassLoader??ν?

????import java.io.IOException;
????import java.io.PrintWriter;
????import javax.servlet.ServletException;
????import javax.servlet.http.HttpServlet;
????import javax.servlet.http.HttpServletRequest;
????import javax.servlet.http.HttpServletResponse;
????public class ClassLoaderServletTest extends HttpServlet{
????public void doGet(HttpServletRequest request??HttpServletResponse response)
????throws ServletException??IOException{
????response.setContentType("text/html");
????PrintWriter out=response.getWriter();
????ClassLoader loader=this.getClass().getClassLoader();
????while(loader!=null){
????out.write(loader.getClass().getName()+"<br/>");
????loader=loader.getParent();
????}
????out.write(String.valueOf(loader));
????out.flush();
????out.close();
????}
????public void doPost(HttpServletRequest request??HttpServletResponse response)
????throws ServletException??IOException{
????this.doGet(request??response);
????}
????}
????3??????Servlet???????????
????<?xml version="1.0"encoding="UTF-8"?>
????<web-app version="2.4"
????xmlns="http://java.sun.com/xml/ns/j2ee"
????xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
????xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
????http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
????<servlet>
????<servlet-name>ClassLoaderServletTest</servlet-name>
????<servlet-class>ClassLoaderServletTest</servlet-class>
????</servlet>
????<servlet-mapping>
????<servlet-name>ClassLoaderServletTest</servlet-name>
????<url-pattern>/servlet/ClassLoaderServletTest</url-pattern>
????</servlet-mapping>
????<welcome-file-list>
????<welcome-file>index.jsp</welcome-file>
????</welcome-file-list>
????</web-app>
????4??????Servlet???????????


????