Regarding the various configuration issues of Java

xiaoxiao2021-03-06  107

For a newcomer, the various configurations of Java are indeed annoying, except for the Java version, it is related to the operating system and other various software installed in your machine. Although I just started learning Java, I think I can sum up the relevant experience, not only is good for my own learning, but if there is novice to see this article, it must be good. Let's talk about J2SE configuration, J2SE mainly requires 2 environment variables: First, this variable is mainly used to explain Javac, JAR and other commands, which directory you put below, in my machine, I press Installation Is the version of J2SDK1.4.2_05 and I installed under the D: /J2SDK1.4.2_05 directory, then I should set PATH = D: /J2SDK1.4.2_05/bin; Second, ClassPath, why do I have this variable, mainly Because you often use the IMPORT statement when writing a Java program, how do you know where to find the class you want to import, it can only read the value of ClassPath. Here we set classpath = d: /j2sdk1.4.2_05/jre/lib/ext. In addition to your compiler know the current path, you have to join a ".". It is set to set classpath = .; d: /j2sdk1.4.2_05/jRE/LIB/EXT. Then tell the configuration of jsp.servlet and javabean under Tomcat, seeing an article online is this, you can't write more better than him, so you just brought the right, huh ~~ ~

Under Tomcat JSP, Servlet and JavaBean configuration http://www.chinaunix.net of the environment: echoguo Posted: 2003-08-27 13:22:31

I often see how JSP's beginners ask how to configure JSP, servlet, and bean under Tomcat, so I have summarized how to configure JSP, Servlet, and Ben under Tomcat, I hope to help those beginners. Step 1: Download J2SDK and Tomcat: to Sun Official Site (http://java.sun.com/j2se/1.4.2/download.html) Download J2SDK, note the download version of the SDK for Windows Offline Installation, and best Download J2SE 1.4.2 Documentation, then download Tomcat in the official site (http://www.apache.org/dist/jakarta/tomcat-4/); download the latest 4.1.x version of Tomcat); Step 2: Installation And configure your J2SDK and Tomcat: Perform the J2SDK and Tomcat installer, then press the default settings. 1. After installing J2SDK, you need to configure the environment variable, add the following environment variables in my computer -> Properties -> Advanced -> Environment Variables -> System Variables (assuming your J2SDK installed in C: /J2SDK1.4.2): Java_Home = C: /J2SDK1.4.2 ClassPath =.;% Java_home% / lib / dt.jar;% java_home% / lib / Tools.jar; (.; must not be less, because it represents the current path) Path =% java_home / bin then writes a simple Java program to test if J2SDK has been installed successfully: public class test {public static void main (string args []) {system.out.println ("this is a test program.");} } Save the above program as file named Test.java. Then open the command prompt window, cd to your directory where you test.java, and type the following command Javac Test.java Java Test At this time, if you see this is a test program. If you have successful installation, if you don't print This sentence, you need to check your configuration carefully. 2. After installing Tomcat, add the following environment variables in my computer -> Properties -> Advanced -> Environment Variables -> System Variables (assuming your Tomcat is installed in C: / Tomcat): Catalina_Home = C: / Tomcat; Catalina_Base = C: / tomcat; then modify the classpath in the environment variable, add servlet.jar under the Tomat installation directory to the ClassPath, the modified ClassPath is as follows: classpath =.;% java_home / lib / Dt.jar;% java_home / lib / Tools.jar;% catalina_home% / common / lib / servlet.jar; then you can start Tomcat, access http: // localhost: 8080 in IE, if you see Tomcat welcome page The words are successful installation.

Step 3: Establish your own JSP app directory 1. WebApps directory for the Tomcat installation directory, you can see the directory of Tomcat, which root, example, tomcat-docs, etc.; 2. Creating a directory in the webapps directory, Name called myapp; 3. MYApp New Directory Web-INF, note that the directory name is case sensitive; 4.Web-infers new file web.xml, the content is as follows: my web application 5. Newly built a new one under MyApp The JSP page of the test, the file name is index.jsp, the file content is as follows:

Now time is: <% = new java.util.date ()%> 6. Restart Tomcat 7. Open the browser, enter http: // localhost: 8080 / myapp / index.jsp See the current time when it is successful.

Step 4: Establish your own servlet: 1. Creating a servlet program with your most familiar editor (recommended using syntax-check Java IDE), the file name is Test.java, the file content is as follows: package test; 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 Test extends HttpServlet {protected void doGet (HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {PrintWriter out = response.getWriter (); out.println ( "

This is a servlet test <. / body> "); out.flush ();}} 2. Compile Test.java Under C: / Test, compile: C: / Test> Javac Test.java then in C : / Test will generate a compiled servlet file: Test.class 3. Cut the structure test / test.class to% catalina_home% / WebApps / myapp / web-inf / class, that is, cut the Test directory In the CLASSES directory, if the classes directory does not exist, create a new one.

Now WebApps / MyApp / Web-INF / CLASSES has the file directory structure 4. Modify WebApps / MyApp / Web-INF / Web.xml, add servlet and servlet-mapping, Web.xml as follows Sign, red is added: My Web Application a Application for test. < Servlet> test test a test servlet test.test test / test This paragraph declares that the servlet you want to call, and servlet-mapping is the declared servlet "mapping" to address / test 5. Ok, start Tomcat, start the browser, type http: // localhost: 8080 / myApp / test If you see the output this is a servlet test. The written servlet is successful.

转载请注明原文地址:https://www.9cbs.com/read-101672.html

New Post(0)