Summary To learn JSP development, you must first build a development environment that complies with JSP specifications. Based on the principle of practicality, this article introduces three methods of configuring the JSP environment with Tomcat server as the core.
Keywords JSP engine, Web server, configuration JSP (Java Server Pages) launched by Sun is a dynamic web development technology that executes on the server side and is based on Java technology. When executing JSP, an engine that compiles JSP web pages needs to be set up on the Web server. There are many ways to configure the JSP environment, but the main task is to install and configure the Web server and JSP engine.
The following uses Tomcat as the JSP engine and cooperates with the three web servers of Tomcat, Apache, and IIS to describe three solutions for building a JSP running environment.
1. Introduction to related software
1. J2SDK: Java2 software development tool, which is the basis of Java applications. JSP is based on Java technology, so J2SDK must be installed before configuring the JSP environment.
2. Apache server: A commonly used web server developed by the Apache organization to provide web services.
3. Tomcat server: A JSP engine developed by the Apache organization. It has the function of a Web server and can be used as an independent Web server. However, as a web server, Tomcat is not as fast as Apache when processing static HTML pages, and it is not as robust as Apache, so we generally use Tomcat with Apache to let Apache serve static page requests of the website, while Tomcat serves as a dedicated JSP Engine, providing JSP parsing for better performance. And Tomcat itself is a sub-project of Apache, so Tomcat provides strong support for Apache. For beginners, Tomcat is a very good choice.
4. mod_jk.dll: A plug-in developed by the Jakarta project team of the Apache organization to enable Apache to support Tomcat. With this plug-in, Tomcat can seamlessly connect with Apache.
5. tc4ntiis.zip: A plug-in developed by the Jakarta project team of the Apache organization to enable IIS to support Tomcat.
2. Software download
1. j2sdk
version: j2sdk1.4.1 (35.9MB)
address: http://java.sun.com/j2se/1.4.1/download.html
2. Apache2
version: Apache2.0.43 (6.69MB)
address : http://www.apache.inetcosmos.org/dist/httpd/binaries/win32/
3. Tomcat4
version: 4.1.21 (8.33MB)
Address: http://jakarta.apache.org/builds/jakarta-tomcat -4.0/release/
4. mod_jk.dll: (136KB)
Address: http://jakarta.apache.org/builds/jakarta-tomcat-connectors/jk/release/
5. tc4ntiis.zip (220KB)
Address: </ BODY>
</HTML>
(2) Installation of J2SDK
Regardless of the solution, the installation of J2SDK must be completed before installing and configuring the JSP engine.
1. Install J2SDK
under Windows, directly run the downloaded j2sdk-1_4_1_01-windows-i586.exe file, and install it to a directory according to the installation wizard, for example, install to f:j2sdk 1.4.1;
2. Add environment variables
(1) If your operating system is Win 98, you can use Notepad to edit Autoexec.bat directly and add the following command line:
PATH=%PATH%;f:j2sdk1.4.1bin
SET JAVA_HOME=f:j2sdk1.4.1
SET CLASSPATH=f:j2sdk1.4.1libtools.jar
After saving, restart the computer so that the added environment variables will be effective.
(2) If your operating system is Win2000, configure the environment variables as follows. Right-click "My Computer" and select "Properties" → "System Properties" → "Advanced" → "Environment Variables" in the pop-up menu. The environment variables dialog box will pop up, and you can edit the system's environment variables. Add three variables: PATH, JAVA_HOME and CLASSPATH. The variable values are the same as above.
4. JSP environment configuration plan
(1) Plan 1: J2SDK + Tomcat
In this plan, Tomcat serves as both a JSP engine and a Web server, and the configuration is relatively simple.
1. Install Tomcat
and run the downloaded jakarta-tomcat-4.0.1.exe directly. Follow the general Windows program installation steps to install Tomcat. It will automatically find the location of the J2SDK during installation. For example, install to f:tomcat4.
2. Configure Tomcat's environment variables
and add a new environment variable TOMCAT_HOME. The variable value is f:tomcat4. The adding method is the same as the configuration method of J2SDK environment variables.
3.
After setting up the test default service, you can run the Tomcat server. Use f:tomcat4binstartup.exe to start Tomcat and use f:tomcat4binshutdown.exe to shut down. (If an Out of Environment Space error is prompted when executing startup.exe or shutdown.exe, select "Properties" → "Memory" → "Conventional Memory" in the menu of the DOS window, and change "Initial Environment" from "Automatic" Just change it to "2816".)
After starting Tomcat, open the browser and enter http://localhost:8080 in the address bar (Tomcat's default port is 8080). If you see Tomcat's welcome interface in the browser, it means Tomcat works fine.
4. For the test project,
place the test.jsp you just prepared in the f:Tomcatwebappsexamplesjsp directory. Enter http://localhost:8080/examples/jsp/test.jsp in the address bar. If you browse If "Hello World!" is displayed in the browser, it means your JSP environment configuration is successful!
Since Tomcat itself has the function of a web server, we do not have to install Apache. Of course, it can also be integrated with Apache, as described below.
(2) Option 2: J2SDK + Apache + Tomcat.
Although Tomcat can also be used as a Web server, its speed of processing static HTML is not as fast as Apache, and its function as a Web server is far inferior to Apache. Therefore, Apache and Tomcat are integrated and Apache is used as a Web server. server, and Tomcat as a dedicated JSP engine. The configuration of this solution is relatively complex, but it allows Apache and Tomcat to be perfectly integrated to achieve powerful functions.
Note that because the IIS web server uses port 80 by default, and the default port of Apache is also 80, so if you are using the Win2000 operating system and IIS is pre-installed, for convenience, please stop the IIS service before performing the following operations.
1. Install Apache,
run the downloaded apache_2.0.43-win32-x86-no_ssl.exe, and follow the wizard to install to f:Apache2. (Note that after Apache2.0.43 is successfully installed, index.html.en in the f:Apache2htdocs directory must be renamed index.html, so that the Apache welcome interface will be displayed normally when testing the default service).
2. Test the Apache default service.
After the installation is completed, the Apache server will run automatically. Open the browser and enter: http://localhost (Tomcat's default port is 80) in the address bar. If you see the Apache welcome interface in the browser, it means Apache is working properly.
3. Follow the steps in Solution 1 to install Tomcat and ensure it runs normally.
4. Copy the downloaded mod_jk-2.0.42.dll to the f:Apache2modules directory.
5. Create the working files required for mod_jk module work.
Open a text editor and enter the following statement:
workers.tomcat_home=f:tomcat4 (let the mod_jk module know about Tomcat)
workers.java_home=f:j2sdk1.4.1 (let mod_jk module know about JSDK)
ps=
worker.list=ajp13 (module version of mod_jk)
worker.ajp13.port=8009 (working port of mod_jk)
worker.ajp13.host=localhost
worker.ajp13.type=ajp13
worker.ajp13.lbfactor=1
Save the above statement in the f:Tomcat4conf directory with workers.properties as the file name (note: the file extension is .properties).
6. Configure Apache.
Use a text editor to open f:Apache2confhttpd.conf
1) Find "DirectoryIndex" and add index.jsp after index.html.var;
2) Add the following code (in brackets) at the end of httpd.conf (explanation here)
LoadModule jk_module modules/mod_jk-2.0.42.dll
(Loading the mod_jk module, used to handle the connection between Apache and Tomcat)
JkWorkersFile "f:/tomcat4/conf/workers.properties"
(Indicate the location of the workers.properties file required for the mod_jk module to work)
JkMount /servlet/* ajp13
JkMount /*.jsp ajp13
(Send all servlet and jsp requests to Tomcat through the Ajp13 protocol and let Tomcat handle it)
3) Save after adding.
7. Configure Tomcat.
Use a text editor to open f:Tomcat4confserver.xml. Because Tomcat4 does not enable Ajp13 by default, I found the following code:
<!--
<Connector className="org.apache.ajp.tomcat4.Ajp13Connector"
port="8009" minProcessors="5" maxProcessors="75" acceptCount="10" debug="0"/>
-->
Delete the comment symbol <!-- --> to enable Ajp13.
Then save. Now the integration configuration of Tomcat and Apache is basically completed.
8. For the overall test,
place test.jsp in the f:Tomcatwebappsexamplesjsp directory, and start Apache2 and Tomcat4 in sequence. Open the browser and enter http://localhost:8080/examples/jsp /test.jsp in the address bar. If "Hello World!" appears in the browser, Tomcat works normally after reconfiguration; enter http in the address bar. ://localhost/examples/jsp /test.jsp, if the result is the same as http://localhost:8080/examples/jsp /test.jsp, it means that the integration of Apache and Tomcat is successful!
(3) Option 3: J2SDK + IIS + Tomcat
The most commonly used web server under Windows platform is undoubtedly IIS. Under normal circumstances, IIS does not support JSP. We can use an IIS to Tomcat redirect plug-in to enable IIS to send all JSP requests to Tomcat. Execution can make IIS add the function of processing JSP. If you are used to using IIS, you can try this configuration. (If you have already installed the Apache server, please uninstall Apache first to facilitate subsequent operations.)
1. Follow the steps in Solution 1 to install Tomcat and ensure that it runs normally. (For example, install to f:tomcat4);
2. Extract the downloaded tc4ntiis.zip directly to the f:tomcat4 directory. Check the files required for the configuration and make sure they are in the following location:
f:tomcat4serverlibajp.jar
f:tomcat4serverlibtomcat-util.jar f:tomcat4binnativeisapi_redirect.dll f:tomcat4confntiisworkers.properties f:tomcat4confntiisuriworkermap.properties f:tomcat4confntiisiis_redirect.reg
f:tomcat4logiis_redirect.log
3. Open f:tomcat4confntiisworkers.properties with a text editor and modify the following values to:
workers.tomcat_home=f:tomcat4
workers.java_home=f:j2sdk1.4.1
4. Double-click f:tomcat4confntiisiis_redirect.reg to add the information in this registration file to the registry, but modify the key values of log_file, worker_file, and worker_mount_file to suit your environment. (For example, the Tomcat in this article is installed in f:tomcat4 instead of the default c:tomcat4). After adding and modifying, it will look like the picture below.
5. Open the Internet Service Manager, add a new virtual directory named jakarta on the default site, this virtual directory points to f:tomcat4binnative, and start the default site.
6. Right-click the server name in the Internet Service Manager, select "Properties" → "Edit" of "WWW Service" in the main properties → "ISAPI Filter" tab, add an ISAPI filter named Jakarta Redirect, the executable file is specified as f:Tomcat4binnativeisapi_redirector.dll. After adding the ISAPI filter, the status of Jakarta Redirect is a red downward arrow. Restart the IIS service and it will turn into a green arrow.
7. Edit the server.xml file and save it (same as step 7 of solution 2).
8. Restart IIS and Tomcat.
9. Test project: Put test.jsp in the f:Tomcatwebappsexamplesjsp directory. Open the browser and enter http://localhost:8080/examples/jsp/test.jsp in the address bar. If "Hello World!" appears in the browser, Tomcat works normally after reconfiguration; enter http in the address bar. ://localhost/examples/jsp /test.jsp, if the result is the same as http://localhost:8080/examples/jsp /test.jsp, it means that the integration of IIS and Tomcat is successful!
5. Conclusion
Building a JSP operating environment is the basis for learning JSP technology. There are many types of JSP engines and many configuration methods, and the software version is constantly being upgraded. You can choose the appropriate configuration method according to your needs and actual situation. I hope that the several JSP environment configuration solutions given in this article will be helpful to those who want to learn JSP.