First, download the tool:
I suggest using editplus + JDK for beginners. I think it is easier to use editplus + JDK for beginners, such as JB, eclipse, and jcreator, but it does not know how to configure environment variables for beginners,
Thus it is difficult to reach the point of knowing and knowing why.
You can download it at the following address:
Editplus (the latest version is v2.11): http://count.skycn.com/softdown.php? Id = 3641 & url = http://sc-http.skycn.net/down/epp211a_cn.exe (you need to follow the registration code to find it yourself, a lot of online)
JDK (the latest version is java2sdk3164_2): http://count.skycn.com/softdown.php? Id = 3116 & url = http://sc-http.skycn.net/down/j2sdk-1_4_2-windows-i586.exe (this is for Windows)
Then install JDK. I installed it under the C:/JDK directory:
Then there is the classpath problem:
Just as the operating system uses path to search for executable programs, the Java Runtime Environment will traverse classpath to find classes. Even a simple program such as helloworld will traverse the JVM.
Classpath defines every path until the corresponding file is found.
I believe that if your system is not 2 K or XP, you should set the path as follows:
My computer-> properties-> advanced-> Environment Variables
Append the following path to the environment variable: C:/JDK/bin;.; C:/JDK/lib.
You can also configure C:/JDK/bin;.; C:/JDK/lib/dt. jar; C:/JDK/lib/tools. jar.
★Remember: In the environment variables, remember not to be less. It indicates the current path. If there are fewer errors, you will say it!
DT. jar is a class library about the runtime environment, and tools. jar is a class library about some tools.
If C:/JDK/bin is not configured, "javac" is not an internal or external command, or a program or batch file that can be run ." This error occurs.
Then we should write the program:
The first is (helloworld. Java). Open editplus and create a new Java file. Enter the following information to keep it case-insensitive:
Public class helloworld {
Public static void main (string [] ARGs ){
System. Out. println ("Hello, world! ");
}
}
Then save the file (CTRL + S) to helloworld. java. Remember to distinguish the case sensitivity. helloworld. Java is not helloworld. Java or other
Run the following command: Start-> Run-> cmd
Switch the directory to the current directory in the console:
Javac helloworld. Java
Java helloworld
You will see the output Hello, world on the console! (Not coming out? I have eaten my computer :))
Javac is a compilation command that compiles helloworld. Java into helloworld. Class.
Java is the command to explain. JVM will explain and execute helloworld. Class.
At this time:
1. If exception occurs in thread "Main" Java. Lang. noclassdeffounderror: helloworld
That is, you didn't add that. (DOT) to the environment variable)
2. If exception in thread "Main" Java. Lang. nosuchmethoderror: Main appears
Or helloworld. Java: 1: Public class helloworld must be defined in a file called
"Helloworld. Java ".
That is, you did not write this helloworld case-insensitive, or you did not save it as helloworld. Java
This name must be the same as the public class name.
Let's talk about the problem of environment variables. Next, let's talk about how to compile and run the environment variables in editplus, and choose tools> parameter settings> Configure user tools.
1. Add a tool (add an Application)
Menu text: compile Java program
Program: C:/JDK/bin/javac.exe
Parameter: File Name
Initial Directory: file directory
2. Add a tool (add an Application)
Menu text: run Java program
Program: C:/JDK/bin/java.exe
Parameter: File Name (excluding the extension)
Initial Directory: file directory
You can add a tool group name as needed, such as debug Java program.
Then, in the drop-down menu of tools, you will see the compile Java program and run Java program options. Then you can use Ctrl + 1 to compile and CTRL + 2 to run the program.
The following describes how to run servlet:
To run servlet, JSP/servlet iner is required. We recommend that you use Tomcat for beginners.
Tomcat (Latest Version 5.0): http://cvs.apache.org/builds/jakarta-tomcat-5/nightly/jakarta-tomcat-5-bin-20030725.zip
Decompress the package:
C:/tomcat
Then configure the environment variable:
Add three system variables:
Java_home: C:/JDK
Tomcat_home: C:/tomcat
Classpath: % java_home %/LIB; % tomcat_home %/lib
The environment variables of Tomcat are configured. Check whether Tomcat can run as follows:
In the console, go to the C:/tomcat/bin directory and run startup. Then, a window appears, which means that the server has been running.
Enter http: // localhost: 8080 in the browser. If the welcome page appears, it means Tomcat is okay.
Write your first Servlet as above.
Import java. Io .*;
Import javax. servlet .*;
Import javax. servlet. http .*;
Public class helloworld extends httpservlet
{
Public void doget (httpservletrequest request, httpservletresponse response) throws servletexception, ioexception
{
Response. setcontenttype ("text/html ");
Printwriter out = response. getwriter ();
Out. println ("<HTML> Out. println ("this is my first servlet ");
Out. println ("</title> Out. println ("Out. println ("</body>
}
}
Then use javac helloworld. Java to compile the file. If the file cannot be imported javax. servlet .*
Then, copy the servlet. jar file in C:/tomcat/common/lib to C:/JDK/JRE/lib/EXT and compile it again!
Then, in the Tomcat directory c:/tomcat/webapps/root, follow the following file structure:
Root/index.html
Root/Welcom. jsp
Root/WEB-INF/lib/myservlet. Jar (If your servlet. Class is typed into a. jar file, put it under Lib)
Root/WEB-INF/classes/helloworld. Class (put the above generated helloworld. Class file in this)
Then, enter http: // localhost: 8080/servlet/helloworld in the browser. The Error 404 -- not found is returned by the server.
What's going on?
Servlet must use the C:/tomcat/webapps/root/WEB-INF directory under the Web. xml file registration, open this web. xml file with EP,
Add
<Servlet>
<Servlet-Name> helloworld </servlet-Name>
<Servlet-class> helloworld </servlet-class>
</Servlet>
<Servlet-mapping>
<Servlet-Name> helloworld </servlet-Name>
<URL-pattern>/servlet/helloworld </url-pattern>
</Servlet-mapping>
Such a structure
<Servlet>
<Servlet-Name> helloworld </servlet-Name>
<Servlet-class> helloworld </servlet-class>
</Servlet>
Indicates the specified servlet class.
The following structure
<Servlet-mapping>
<Servlet-Name> helloworld </servlet-Name>
<URL-pattern>/servlet/helloworld </url-pattern>
</Servlet-mapping>
Specifies the URL mode to which helloservlet maps.
After modifying web. XML, restart the server and then enter http: // localhost: 8080/servlet/helloworld. Then, a large Hello, world! Waiting for you. Congratulations.
Flat :)
AI, the hands are tired. Write it here. I hope it will be helpful for beginners!