Java Servlet API documentation (1)
Translator Foreword:
Servlet recent presentation of information found online has not in a Chinese in the Java Servlet API documentation, and the JSP is one of the book behind the Java Servlet API that was incomplete, and this documentation 2.1 a version in 1998 of November has been finalized. Therefore, I have decided a Chinese translation of the documents (some of which had little to do with the technical part has been omitted), interested readers can http://java.sun.com/products/servlet/2.1/servletspec- 2.1.zip download the original reading.
Java Servlet API documentation (a 2.1 version)
Introduction
This is a version 2.1 of the Java Servlet API documentation, as this supplementary this document, you can download to http://java.sun.com/products/servlet/index.html Below Javadoc format documents.
Who needs reading of this document
This document describes Java Servlet API version of the latest version 2.1. Therefore, this book for the development of Servlet servlet engine and the developer equally applicable.
Java Servlet API component
Java Servlet API formed by the two packages: one corresponding HTTP packages, and the other is not corresponding HTTP generic packages. These two packages at the same time there makes Java Servlet API able to adapt to the future of other requests - response to the agreement.
The documents, and mentioned Javadoc format documents describe these two packages, Javadoc format documents also describe how you should use these two packages of all the methods.
Relevant norms
Below you might be interested in these Internet norms, these norms will directly influence Servlet API development and implementation. Http://info.internet.isi.edu/7c/in-notes/rfc/.cache You can find all of these mentioned below standard RFC.
RFC 1738 Uniform Resource Locator (URL)
RFC 1808 related Uniform Resource Locator
RFC 1945 Hypertext Transfer Protocol - HTTP/1.0
RFC 2045 Multipurpose Internet Mail Extensions (Multipurpose Internet Mail expansion agreement (MIME)), Part I: Internet format of the information
RFC 2046 Multipurpose Internet Mail Extensions (Multipurpose Internet Mail expansion agreement (MIME)) Part II: media types
RFC 2047 expansion agreement Multipurpose Internet Mail (MIME) (Multipurpose Internet Mail Extensions) Part III: Message Title for the expansion of non-ASCII text
RFC 2048 Multipurpose Internet Mail Extensions (Multipurpose Internet Mail expansion agreement (MIME)) Part IV: Registration Step
RFC 2049 Multipurpose Internet Mail Extensions (Multipurpose Internet Mail expansion agreement (MIME)) PART V: consistency of standards and examples
RFC 2068 Hypertext Transfer Protocol - HTTP/1.1
An extension of HTTP RFC 2069: Abstract visit Identification
RFC 2109 HTTP State Management Mechanism
HTTP RFC 2145 version of the use and interpretation
RFC 2324 Hypertext Coffee Pot Control Protocol (HTCPCP/1.0)
CORBA experience: the use of java and C + + programming mixed (1)
1. Preface
Now many people in the CORBA learning, we all have learned that CORBA is a completely intermediate language, you can use the interface definition language (IDL) definition of the use of interface development and the achievement of the Client Server interface of the information needed by the . Client and Server code is not a concrete realization of the IDL definition of preparation, but the use of some kind of target language IDL compiler generates the necessary code stubs and helper category, Client and Server to use the real programming language to a concrete realization.
In order to ensure that different products based on the CORBA distributed object can be constructed mutual communication, Client and Server through ORB (Object Request Broker) communications. The process is generally run Client ORB sent to the request, then the request sent to the ORB Server, Server returns the results sent the ORB, ORB then returns the results sent to the Client. ORB can be said between the Client and Server translator. Even Client and Server use different programming languages, as long as they are consistent with the same IDL definition ORB can be completed mutual communication.
In all the documents that the server and client can also be a Java C + + or other languages (such as: Delphi) prepared, but no sites or books that detail how to deal with multi-language client example. "JAVA2 core technologies" that some of the above, it is only an introductory article, it downloaded omniORB304 their own, the first use of the tnameserv SUN naming service procedures, prepared with JAVA server, the client separately with JAVA and C + + (+ omniORB VC6) prepared Test hopes to operate a specific example of programming experience to understand or CORBA thinking.
Overall the preparation process is as follows:
IDL interface definitions with a document to describe the functions, it can be said that the definition of a function to achieve a template (SysProp.idl)
"IDL to Java" compiler (here IDLJ) IDL files into Java programming language in the preparation of the interface definition, generates the necessary code stubs and helper category
The use of the Java language to prepare the client and server to achieve procedures.
"IDL to C + +" compiler (here omniidl) IDL document will be translated into C + + programming language in the preparation of the interface definition, generates the necessary code stubs and helper category
Using the C + + language prepared by the client to achieve process (of course, can also be prepared by the server programs, but did not conduct this test)
Starting Naming Service tnameserv
Starting the service program written in Java
Using Java and C + + were prepared by the client calls the corresponding service
2. Operating environment settings:
Overall environment by jdk1.3 + omniORB3.0 (www.uk.research.att.comomniORBdoc3.0) + vc6 composition below specific installation.
2.1. Installation JDK1.3
SUN DOWN JDK1.3 from the company or through other means jdk1.3 be installed, then the corresponding set environment variables, in this paper, the computer test is as follows:
Acquaint JINI technology (1)
I. Introduction
Many engineers have a long time, have been looking forward to a super computing systems, the system is a network of many machines, from very large mainframe and embedded in some of the equipment on the tiny chip, cooperation from each other. All the work can be spread at any time to any place on the Internet, any kind of boost processing machines. Such a system has good flexibility, and can be continuously updated by equipment to solve more problems.
However, we agreed to the language, as well as stronger communication protocols (superprotocols), so that the many complex network members can communicate each other smoothly. But in the present case, in order to achieve this purpose it is very difficult, so we can consider a special code (genetic code) embedded in many software service, allowing members on the network can easily share their mutual resources, and this is Jini to be a target.
Jini is SUN company R & D Bill Joy made a technical. Through the use of Jini we can create a flexible, easy to manage and can be used anytime, anywhere services network computing environment. In order to let users know that the services on the Internet which can be used, we must build a coalition (federation), to take the initiative on the network by adding services. When a service to join their alliance, also equivalent to the entire network at the same time inform: "I can be used, who should I care?." Users through the Union, be able to tell what services can be used. However, are we going to be very simple, very easy to use these services on this issue, which is one of the priorities of Jini.
Let us look at how Jini is Peng do. Internet service should be able to become a member of the Union, whether it is hardware or services, software or services, must be embedded Jini code. In addition, the network must also provide JVM environment can be implemented Jini programs to obtain these services.
Jini code is the use of SUN provided by the company writing from the Jini package. Jini package is the use of the Java language, and contains many resources on the Internet dealing with the related function. For example: how to find Web services (discovery), and adding (join) Union, or to help deal with a distributed Web services leasing (leasing), transactions (transactions), and other issues. These Web services to communicate with each other, the application of technology is RMI (Java Remote Method Invocation). In short, on the network through Jini services provided by the interface to communicate with each other, cooperation, and to complete users
Second, architecture
Jini system is the basis of building (infrastructure), the programming model (programming model), services (services) posed by the three. Figure 1 below:

Jini device and its application examples (1)
Jini technology, Java makes for success in the calculation of network equipment to provide a suitable platform, more network equipment, especially under the home network of consumer electronic equipment has provided a new network computing structure, thus achieving the long-awaited plug-and-play network equipment.
Jini equipment on the hardware requirements
While Jini is a software system, but a real input system by the use of a series of Jini software and the hardware components. Obviously, the previous general electronic equipment is not directly add to the Jini system in the past. Only when we understand the full support Jini technology hardware norms, the Jini technology will be the future of a more in-depth understanding.
Jini need to structure the data in the Java language definition type services, and services to the different examples of the different approaches to achieve the data type. A service can be different types of members, allowing the example of a service to provide customers with different functions. This is a standard object-oriented software approach. Jini distributed system allows the characteristics of the Java language data types can be a software and hardware architecture to only achieved.
Achieve such a core function of thinking is very simple. Services to an interface definition, the agent interface to support customer service is visible, agents functional modules by service providers View uploading of services, and then to the customer found part of the service was downloaded to the client side. This service-related functional modules prepared by the need to ensure that the Java language portability. However, since this code is used services from the individual examples, it can be the agent of specific detail to know the details of service modules. Download the code, and this is not only aware of the software, but also know that the services of the hardware. In extreme cases, the hardware is service, and all downloadable software is a network-level device driver, having received from the client, the Java language method calls, the network connection on the other end had a hardware Calling specific hardware code.
View of services (Lookup Service) requirements
A service provider to provide the actual function of a functional entity asked for very little, in fact, Jini software services can be used in such a way to run equipment: client side downloaded Jini procedures sent directly to the hardware directly corresponding binary code enforcement. In such circumstances, Jini equipment necessary intelligence is the least. Java programs and device controller interactive manner with a local computer equipment in the general line of interaction is very similar (of course, but also in the area of network communications centre to do some modifications).
However, the provision of services is only part of Jini service requirements. Jini system should become a part of the service must also participate in the discovery of the agreement Jini, Jini View services to its own registration information.
The needs of the two are closely linked. Jini found that the main objective of the agreement is to enable equipment, services or access to local services Jini find a Jini Remote Method Invocation (RMI) are cited. Once this was invoked by service to find in the Jini service registration, allowing Jini system, and other members found and the use of this service.
TCP and UDP talk about some simple applications (1)
Network programming is the most important SOCKET, which is also the principle that monitor port. And we use a mobile phone text message exactly the same principle should be broadly (I understand this is), JAVA and the most outstanding point is "no pain networking."
The basic spirit of the network is to link up the two machines, "the party calls" the server is, "looking to the side" is called the client, so that the connecting server, the client is a relative concept the. We logo on the machines primarily through the IP address and port to the distinction.
"Transmission Control Protocol" TCP and the "User Datagram Protocol" are two different agreements, JAVA the support of these two basic agreement is the same, and their own biggest difference is sent reliability and speed, with the former than the latter is a reliable agreement, which is of course a much faster pace, we were below the demonstration with two SOCKET:
Eg1:
/ / Clients.java
Import java.io. *;
Import java.net .*;
Public class Clients
(
Public static void main (String [] args) throws Exception
(
InetAddress.getByName InetAddress addr = (null);
Socket socket = new Socket (addr, 2000);
PrintWriter out =
New PrintWriter (
New BufferedWriter (
New OutputStreamWriter (
Socket.getOutputStream ())), true);
Byte [] b = new byte [2048];
String msg = new String (b, 0, System.in.read (b));
Out.println (msg);
Socket.close ();
)
)
/ / Servers.java
Import java.io. *;
Import java.net .*;
Public class Servers
(
Public static void main (String [] args) throws Exception
(
ServerSocket s = new ServerSocket (2000);
Try (
While (true) (
Socket socket = s.accept ();
Try (
BufferedReader in =
New BufferedReader (
New InputStreamReader (
Socket.getInputStream ()));
StringBuffer sb = new StringBuffer ();
Int c;
While ((c = in.read ())! = -1) (
Char ch = (char) c;
Sb.append (ch);
)
System.out.println (sb.toString ());
) Catch (IOException e) (
Socket.close ();
Finally ()
Socket.close ();
)
) / / While
Finally ()
S.close ();
) / / Try
) / / Main
)
This program mainly used to carry out unlimited Servers monitor, and the client is sent Clients program, they all use the port in 2000.
Eg2:
/ / UDPsend.java
Import java.io. *;
Import java.net .*;
/ **
* This class sends the specified text or file as a datagram to the
* Specified port of the specified host.
** /
(Public class UDPSend
Public static final String usage =
"Usage: java UDPSend ...
"+
"Or: java UDPSend-f";
Public static void main (String args []) (
Try (
/ / Check the number of arguments
If (args.length <3)
Throw new IllegalArgumentException ( "Wrong number of args");
/ / Parse the arguments
String host = args [0];
Int port = Integer.parseInt (args [1]);
/ / Figure out the message to send.
/ / If the third argument is-f, then send the contents of the file
/ / Specified as the fourth argument. Otherwise, concatenate the
/ / Third and all remaining arguments and send that.
Byte [] message;
If (args [2]. Equals (the "-f")) (
File f = new File (args [3]);
Int len = (int) f.length (); / / figure out how big the file is
Message = new byte [len]; / / create a buffer big enough
FileInputStream in = new FileInputStream (f);
Int bytes_read = 0, n;
Do (/ / loop until we've read it all
N = in.read (message, bytes_read, len-bytes_read);
Bytes_read + = n;
) While ((bytes_read <len) & & (n! = -1));
)
Else (/ / Otherwise, just combine all the remaining arguments.
String msg = args [2];
For (int i = 3; i <args.length; i + +) = msg + "" + args [i];
Message = msg.getBytes ();
)
/ / Get the internet address of the specified host
InetAddress.getByName InetAddress address = (host);
/ / Initialize a datagram packet with data and address
DatagramPacket packet = new DatagramPacket (message, message.length,
Address, port);
/ / Create a datagram socket, and send the packet through it, close it.
DatagramSocket dsocket = new DatagramSocket ();
Dsocket.send (packet);
Dsocket.close ();
)
Catch (Exception e) (
System.err.println (e);
System.err.println (usage);
)
)
)
/ / UDPreceive.java
Import java.io. *;
Import java.net .*;
/ **
* This program waits to receive datagrams sent the specified port.
* When it receives one, it displays the sending host and prints the
* The contents of the datagram as a string. Then it loops and waits again.
** /
(Public class UDPReceive
Public static final String usage = "Usage: java UDPReceive";
Public static void main (String args []) (
Try (
If (args.length! = 1)
Throw new IllegalArgumentException ( "Wrong number of args");
/ / Get the port from the command line
Int port = Integer.parseInt (args [0]);
/ / Create a socket to listen on the port.
DatagramSocket dsocket new DatagramSocket = (port);
/ / Create a buffer to read datagrams into. If anyone sends us a
/ / Packet containing more than will fit into this buffer, the
/ / Excess will simply be discarded!
Byte buffer [] = new byte [2048];
/ / Create a packet to receive data into the buffer
DatagramPacket packet = new DatagramPacket (buffer, buffer.length);
/ / Now loop forever, waiting to receive packets and printing them.
For (;;) (
/ / Wait to receive a datagram
Dsocket.receive (packet);
/ / Convert the contents to a string, and display them
String msg = new String (buffer, 0, packet.getLength ());
System.out.println (packet.getAddress (). GetHostName () +
":" + Msg);
/ / Reset the length of the packet before reusing it.
/ / Prior to Java 1.1, we'd just create a new packet each time.
Packet.setLength (buffer.length);
)
)
Catch (Exception e) (
System.err.println (e);
System.err.println (usage);
)
)
)
UDP in the main category is DatagramSocket () and DatagramPacket (), and in UDPreceive, to accept the byte is subject to restrictions as not feeling too good, since buf is a byte array, we wonder why it is very Construction not for its own investigation to the length of the array? We can only guess the reason is that the result of C programming style, where the arrayä¸èƒ½è‡ªå·±tell us how much it.
Jini technology infrastructure (1)
Jini technology plug-and-play infrastructure agreement mainly by three groups: the View (Lookup), found (Discovery) and the accession (Join). Search services are distributed Jini the basic components of the system, provides a distributed Jini system in the central registration system services. In the Jini system, the programs can find the method of choice for service through the View services, and Search service is available to administrators and users visit various interface basis.
View the service model
Lookup Service preserved a service table, the table of representatives of each element of the system can be used in a service, which preserved a visit by the needs of the service code and a description of a series of scalable service attributes. Figuratively speaking, find services like telephone directories, Jini system of services like telephone directories in the user to find the information stored by service users is the telephone number. In other words, all need access Jini system services, we must find services that preserve the "telephone number." But many find more than a telephone directory services are the advantages, such as: Search service is a dynamic preservation of the "telephone directories" Moreover, system services can be in the "phonebook" and join in the initiative to remove their "phone numbers "and find services also fully support such a mechanism. And the content in the future, we will find more differences.
When the service to search registration services will have a notification event. System administrators can use the search service in the event callback mechanism to receive the notice. This help system administrators manage and maintain the system. And the service will be set up to provide its own user interface, the user interface as a service to the preservation of the properties of View services. Administrators can easily set up services, not everywhere busy for a variety of drivers and management software.
In the service during the period of service if they encounter problems should be brought to the attention of administrators, such as printing paper found that the shortage of services to an additional attribute to specify the problem. The results will be changes to the preservation View services. At this time, ditto above, the administrator uses the services provided by Search callback mechanism to the receipt of the notice. With such a powerful mechanism, greatly reducing the burden on the system administrator.
Discovery Protocol and accession agreement
In the network of services in the post and how to join the distributed Jini system, a Jini system of services, there are two important essential steps. Certainly the first step is to find the system's search services, this process is Discovery process, the agreement is found use agreement. The second step is to find themselves registered to the service, this process is Join process, describing this process is the agreement Join agreement. In a service after the completion of this two-step, to truly become a Jini system of a member. In order to accurately describe these two agreements, first tell us about the terminology used.
Mainframe. Have one or more of Java Virtual Machine and will be able to join the network hardware devices known as a mainframe group. Jini a group composed of a collection of services. Group name is arbitrary string, used to describe the nature of the group.
E-mail through the sharing of Java objects (1)
JDK1.1 new features - serialization interface (Serializableinterface), which simplifies the object persistence (Persistence) can be achieved. Here's how SMTPE-mail will be sent to another user object.
Abstract: Some applications require a non-real-time methods (such as travel guides, a bug report (bugreport), schedule (timesheet), etc.) and the rest of users to share objects. Java Language Development Kit (JDK) version 1.1 provides an important function: java.io.Serializable interface. The technology lets you know how sequences of an object, and then use e-mail transmission other users.
Object persistence and object sharing between users is a lot of business solutions based. For example, a company can be launched from the company's Web site Applet to a timetable for completion of the production. Similarly, the company will be able to provide expenditure reports as a travel guide, a bug report (bugreport) function Applet. Under these circumstances, from Applet users need to access the data and responsible for salaries, payments, travel booking room of people sharing. People perform these functions may be distributed in different cities and countries, and may work in different time zones, can not hope, as each staff member can work at night owl like to fill this form. The same information should not re-enter. Therefore, these can be stored and transmitted to the relevant objects in the commercial application of these applet is different from the other applet advantage.
There are many ways has been targeted to achieve a lasting, such as the use of object databases and files. The same way there are many objects can be shared, such as the data into a socket, or the realization of a line with CORBA, SOM model. Above several options has its own advantages, when you design your business solutions, it needs to seriously consider these programmes. However, there is a little cost but reliable method, it uses the Internet and Intranet users to access technical services in the world send copies of the object. It is the Simple Mail Transfer Protocol, SMTP.
E-mail Java objects
Object storage and preservation of a simple method is to target sequences of the E-mail and then send it to other users. This method has the following advantages:
Send computer or NC (network computer) without hard disk space
The use of the existing transmission system, the queue, send objects
Allows users to use the most mail clients like to receive e-mail
Provide a simple mechanism for the same object copy distributed to many people
This approach also has limitations:
E-mail transmission may be E-mail host shutdown was longer delay. All the host may be such a situation, E-mail server error recovery priority is usually lower than the database server.
E-mail transmission can not be guaranteed - in your E-mail server does not inform you sent mail, you had to email.
E-mail servers and POP client function inadequate to deal with a large number of transaction information.
These deficiencies and you use the application. For many business solutions, these deficiencies are not important. As a designer, that is a part of your work in full consideration price, performance and demand situation to determine the best overall system structure.
Using Java to achieve FTP server (1)
FTP (File Transfer Protocol file transfer protocol) is used for transmission of documents on the Internet agreement. On the Internet through FTP server can upload files (Upload) or download (Download). FTP is a real-time on-line services, in use it must be before the service with a user (user name and password), when the client must be logged in to the computer as a server side, the user should be able to search for documents and file transfer , and other related operations, such as changes in the current working directory, list of file directory, and set up transmission parameters, such as the transmission of documents. FTP can be used to transfer all types of documents, such as text files, binary executable files, image files, sound files and data compression files.
FTP commands
FTP's main operations are based on the various orders on the basis of. Common order:
â—† The transmission mode, which includes ASC â…¡ (text) and BINARY binary mode;
â—† directory operations, change or remote computer show the current directory (cd, dir / ls command);
â—† connecting operation, open orders for the establishment of the connection with the remote computer; orders for the closure of close connections;
â—† sent operation, put an order for the transmission of documents to a remote computer; mput orders for a number of documents transmitted to a remote computer;
â—† access operation, get an order to receive a document; mget order to receive multiple files.
Programming ideas
According to the working principle of FTP, in the main function of the establishment of a server socket port and wait for client requests, once the client request is accepted, the server process on the establishment of a sub-thread server, handling client orders. If the client needs and server-side file transfer, the creation of a new socket connections to the operation of complete documents.
Programming skills that
1. Main function design
In the main function, the complete server port interception and services to create threads. We use a static string variables initDir to preserve the server thread running of the working directory. The initial working directory server is running, the user input, default is the root of the C-.
Specific code as follows:
Public class ftpServer extends Thread (
Private Socket socketClient;
Private int counter;
Private static String initDir;
Public static void main (String [] args) (
If (args.length! = 0) (
InitDir = args [0];
) Else (initDir = "c:";)
Int i = 1;
Try (
System.out.println ( "ftp server started!");
/ / Monitor port on the 21st
ServerSocket s = new ServerSocket (21);
For (;;){
/ / Accept client requests
Socket incoming = s.accept ();
/ / Create a service-thread
New ftpServer (incoming, i). Start ();
I + +;
)
) Catch (Exception e) ()
)
Three steps Institute Java Socket Programming (1)
First step in fully understanding Socket
1 What is socket
Socket is usually referred to as the so-called "socket", used to describe the IP address and port, is a communications chain handle. Application procedures are usually done through the "socket" to the network response to a request or network requests.
1.3-to J2SDK example, Socket and ServerSocket class library in the java.net package. ServerSocket for server-side, Socket is establishing network connectivity to use. In a successful connection, the application will have a two ends Socket examples, examples of this operation, the necessary conversation. For a network connection, the socket is equal, and there is no difference, because the server or the client and produce different levels. Socket ServerSocket or whether their work through the categories and sub-categories SocketImpl completed.
Important Socket API:
Java.net.Socket inherited from java.lang.Object, eight Constructors, its methodology is not, Here are the three most frequently used method, the other methods we can see JDK 1.3-documents.
. Accept method for the production of "jamming" until a connection is received, and return to a client Socket object instance. "Obstruction" is a term that is running its temporary "stay" in this place, until a conversation generated, and then continue to process; normally "obstruction" by the cycle.
. GetInputStream method of access network input, and returns an object IutputStream examples.
. GetOutputStream method connect the other end will be input at the same time to return to a OutputStream object instance.
NOTE: getOutputStream which getInputStream method and will have an IOException, it must be arrested because they object to return to the flow, usually flow target will be another use.
2. How the development of a Client-Server Model procedures
Development Principle:
Server, the use of eavesdropping ServerSocket designated ports, can be arbitrarily designated port (port since 1024 following ports are normally retained, and in some operating systems can not be free to use, it is proposed to use more than 1024 ports), waiting customer connectivity request, the customer connection, the session; and after the completion of the session, and close the connection.
Client, the use of Socket on the network to a server connected to a port issued the request, once a successful connection, open the conversation after the completion of the session, closed Socket. Clients do not need to specify the port to open, usually temporary, dynamic allocation of a more than 1024 ports.
() Build server
Import java.net .*;
Import java.io. *;
Public class Server
(
Private ServerSocket ss;
Private Socket socket;
Private BufferedReader in;
Private PrintWriter out;
Public Server ()
(
Try
(
Ss = new ServerSocket (10000);
While (true)
(
Ss.accept = socket ();
In = new BufferedReader (new InputStreamReader (socket.getInputStream ()));
Out = new PrintWriter (socket.getOutputStream (), true);
String line = in.readLine ();
Out.println ( "you input is:" + line);
Out.close ();
In.close ();
Socket.close ();
)
Ss.close ();
)
Catch (IOException e)
()
)
Public static void main (String [] args)
(
New Server ();
)
)
This procedure establishes a server, which has been monitoring port 10000 and waits for users to connect. In the establishment of connection to the client to return to a message, and then the end of the session. This procedure can only be accepted once a customer connectivity.
Break easily configured Classpath Java (1)
And the Java class path (classpath) in the process of dealing with developers will occasionally run into trouble. This is because the actual type of loading into a category which is sometimes not obvious when the application classpath contain a large number of categories and directories, the situation is particularly grave. This paper will provide a tool to show it can be put into the category of absolute pathname.
First, the basis of Classpath
Java Virtual Machine (JVM) with the help of loading into the use of application specific category into which the light of the prevailing need to decide. CLASSPATH environment variable type loader tell Where to find a third party to provide classes and user-defined categories. In addition, you can also use the command-line parameters JVM - application classpath were designated Class path, in the - classpath specifies that the path of coverage specified in the CLASSPATH environment variable values.
In the path of the content can be: the directory (not included inside the package), the root of the package (which includes the already packaged), including such files (such as. Zip files or. Jar). Unix systems in the family, the path of each item separated by colons, in the MS Windows system, which separated from the semicolon.
Class loader to entrust level in the form of organizations, each with a load of a father type loader. When a class loaded with a load of the request, it tried to find their own category will be requested before the first father entrusted to it by the type loader. Class loading system, installed in the system from the JDK or JRE provided by the default of loading, or through CLASSPATH environment variable - classpath this JVM command line parameters into the third category, or user-defined categories. Class loader system commissioned by the expansion of the use of load-load mechanism for Java Extension category. Extensions commissioned by the bootstrap loader loaded category (bootstrap class loader) into the core JDK category.
You can develop a special type loading, custom JVM how dynamically loaded category. For instance, most Servlet engine custom class loading, dynamic load those in the directory specified in the classpath changes have occurred in the category.
Must pay special attention to is (also alarming is), the type of loading packed in the order in the classpath in the category is the priority. Class loader from the classpath first, followed by one for each set of directories and compressed files, and try to find out what types of documents to be loaded. When the loading of the first category to find a designated name of the category, it put into such, classpath all remaining items have been neglected.
Seem very simple, right?
Second, the problems which may arise
Whether or not they are willing to admit, beginners and experienced Java developers are the same, they have in some time (usually those in the worst of circumstances) was lengthy and complex classpath deception. Application procedures and rely on a third party like the number of user-defined categories to grow, classpath have gradually become a possible accumulation of all directories and files were local. At this juncture, with the first load of the load which is a category no longer obvious. If classpath includes entrance to repeat the class, the problem is particularly conspicuous. As mentioned above, type loader always loaded in the classpath first find a suitable name of the category, from a practical effect, it is "hidden" other appropriate name in the classpath in the lower priority category.
keep looking »