JDK APACHE_2.0.47 Tomcat-5.0.19 Combined Configuration (2)
- The most comprehensive good information on the Internet (who said? The author said)
Author: weibin (welcome to reprint, please retain the right of authorship)
After successful connection, the following test is performed
11, the JSP page test
Write a simple myIndex.jsp content as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312" Language = "Java" Import = "java.sql. *" ErrorPage = ""%>
<% @ Page Import = "java.util.date"%>
hEAD>
The server is already started!
The current system time is <% = new date ()%>
body>
html>
Save the above file in the D: / Tomcat5 / WebApps / root directory:
Open two IE windows, the address bar is
http://localhost/myindex.jsp
Http: // localhost: 8080 / myIndex.jsp
The results are:
The server is already started!
Current system time is Fri Apr 09 14:51:26 CST 2004
The description is successful (if you don't have to try to restart the machine, the following is also, often configured, the configuration is correct, but you can't immediately see the machine, sometimes you can write or stop the service and start the service is not good. Why is this, I don't know)!
12, custom project directory specification
Let's talk about the point of virtual machine and virtual directory (that is, my own project):
Also set the virtual host (actually above or the project folder under Tomcat5, can be specified, as I assign to "D: / Java / AA", "D: / Java / AA" for my project The root directory of the group, of course, may not be specified, then, you can save the JSP file in the D: / Tomcat5 / WebApps / root / directory, class files are available to D: / Tomcat5 / WebApps / root / web- INF / CLASSES / directory)
Modify the corresponding part of the httpd.conf / httpd.conf under D: / Apache2 / Conf (this time my virtual directory is D: / java / aa)
# --------------------------------------- #
ServerAdmin weibin975@sohu.com # Your mail address
DocumentRoot D: / java / aa # My project group root directory D: / java / aa
ServerName Localhost # Your service name, if your machine has domain name, set it to domain name, but the software is used to test ErrorLog logs / robornet_home_log.txt # Error log, in D: / apache2 / logs
Customlog logs / robornet_custom_log.txt Common # Access Log
JKMOUNT / servlet / * ajp13 # Let Apache support to transmit to servlets to Tomcat resolution
Jkmount /*.jsp Ajp13 # Let Apache support to transfer JSP to Tomcat resolution
Virtualhost>
# --------------------------------------- #
Then set Tomcat to support my project, open the d: /tomcat5/conf/server.xml file,
Add " context>" before " Host>"
And save.
(If necessary, restart your computer, turn on the Apache server after restart)
Put the MyIndex.jsp files in the above COPY to D: / Java / aa directory
The modification is as follows:
<% @ Page ContentType = "Text / HTML; Charset = GB2312" Language = "Java" Import = "java.sql. *" ErrorPage = ""%>
<% @ Page Import = "java.util.date"%>
hEAD>
Custom project test
The server is already started!
The current system time is <% = new date ()%>
body>
html>
Open an IE window, in the address bar:
http://localhost/aa/myindex.jsp
Http: // localhost: 8080 / aa / myindex.jsp
The result of the two page shows:
Custom project test
The server is already started!
Current system time is Fri Apr 09 19:39:52 CST 2004
This shows that the custom project is used, don't be happy too early ... stay!
Description: All configurations above If there are spaces in the path, use quotation marks. It is also easy to make an error.
13. Customize file structure in the project directory
As shown in D: / Tomcat5 / WebApps / Root /, you can build a "web-inf" folder, build a "Classes" folder, write a Java class or JavaBean to generate the class file or compile generation In the "D: / Java / AA / Web-INF / CLASSES /" directory, (the best way is to put the Java source file in this directory, compiled Class files or classes in this directory After the first generation of class files, when referenced in the JSP page, you may have an exception of the class, don't worry, restart your computer, it is easy to use, maybe in some places in the forebel, just I am Debug configuration, I'm writing this article, I am afraid I can't remember, there is no relationship, when you configure it, if you think it is correct but you can't realize: Restart your computer is the only spiritan medicine, don't laugh, it is true) An example of JavaBean to help you understand the above "custom project file structure"
Then, according to the method mentioned above, the directory Web-INF and its subdirectories Classes are
Write one in the Classes directory
//Helowow.java
Package beans;
Public class hellow
{
Private string wb;
Public void setValue (String WB)
{
THIS.WB = WB;
}
Public String getValue ()
{
Return THIS.WB;
}
}
After compiling, there is a beans directory under the class directory, and there is a help.class instructions for compilation!
Write a JSP file in the D: / java / aa directory (TestJavaclass.jsp), the content is as follows:
<% @ Page ContentType = "text / html; charset = GB2312"%>
<% @ Page Import = "Beans.Hellow"%>
HEAD>
<%
Hellow hell = new hellow ();
HEL.SetValue ("weibin");
Out.println (HEL.GetValue ());
%>
Body>
html>
Open a window test: http://localhost/aa/testjavaclass.jsp
The result of me is that the page is wrong. The reason is that the reason is not to find the class hellow. In fact, what is the existence of this class, what to do, don't worry, restart the machine! When it is necessary to eliminate the correct display, (if it is right, certainly, it is good for you, for me, my psychology is unbalanced, why don't you restart, I have to restart, don't, you have to restart ... ...)
Start the APACHE server after restart.
Open a window test: http://localhost/aa/testjavaclass.jsp
If you have a name:
weibin