Build a Linux development environment-Tomcat and JSP
Source: Internet
Author: User
Create a Linux development environment -- Tomcat, JSP -- Linux Enterprise Application-Linux server application information. The following is a detailed description. I suppose you use Debian3. If you use another Linux version, there may be differences between the installation method and the setting path.
1. Install J2SDK
1.1 Use the installation package in the Debian Source
Run the apt-get install sun-j2sdk1.4 as root to install sun's j2sdk1.4. Enter java. If the command is not found, the installation is correct. Otherwise, check whether there are two files: java and javac. Under/usr/lib/j2sdk1.4-sun/bin, if yes, create a link to/usr/bin, the connection name is the same as the original file name.
1.2 use the installation package on the sun website
For details, refer to the installation instructions on the sun website. You can also refer to my practices (graphic interface operation ):
Download the correct compressed package and decompress it. Generally, a folder named jdk1.x. x is obtained. Move the entire folder to the/usr/lib directory and enter jdk.1.x. create links to four executable files, java, javac, javadoc, and jar under x/bin, copy them to the/usr/bin folder, and rename them the same as the original file. The reason for this is that/usr/bin is a part of the $ PATH environment variable. In the future, you want to run the javac command to compile a variable. in the java source file, you only need to enter javac filename, instead of the complete path of the javac file.
JAVA_HOME environment variables can be left unspecified, because according to my use experience, jdk programs such as java and javac know where to find their home. When a program requires the JAVA_HOME environment variable, we can set it in its startup script. Because there are few programs that use the JAVA_HOME environment variables.
2. install Tomcat
Download Tomcat for Linux from http://tomcat.apache.org/network. The website has different versions of the source code package and Binary Package, and the Binary Package has three types: core, deployer, and embedded. I use the core in the tomcat5.28 Binary Package.
Download jakarta-tomcat-5.0.28.tar.gz unzip, will get the jakarta-tomcat-5.0.28 folder, I renamed it tomcat5, copy it to your favorite place. I put it under/usr/share.
2.1 test run tomcat
Enter/usr/share/tomcat5/bin/startup. sh in the terminal to start tomcat. Then, enter http: // localhost: 8080 or http: // 127.0.0.1: 8080 in the browser and you will see the page generated by tomcat.
Error in running/usr/share/tomcat5/bin/startup. sh? Trial run:
JAVA_HOME =/usr/lib/j2sdk1.4 _ sun # The path here is your j2sdk installation path export JAVA_HOME/usr/share/tomcat5/bin/startup. sh
2.2 set tomcat to boot
There are two methods: one is to start with the startup script of tomcat, and the other is to start tomcat as a Linux Process Using jsvc.
2.2.1
Create a script named tomcat5.sh with the following content:
#! /Bin/sh # file: tomcat5.sh # Set environment variables, if it cannot be started, remove the comment # JAVA_HOME =/usr/lib/j2sdk1.4-sun # CATALINA_HOME =/usr/share/tomcat5 # CLASSPATH =\# $ JAVA_HOME/lib/tools. jar: \ # $ CATALINA_HOME/bin/commons-daemon.jar: \ # $ CATALINA_HOME/bin/bootstrap. jarcase "$1" in start) echo "Starting tomcat5... "/usr/tomcat5/bin/startup. sh; stop) echo "Stopping tomcat5... "/usr/tomcat5/bin/shutdown. sh; *) echo "Usage tomcat. sh start/stop "exit 1; esac # tomcat5.sh end
Copy tomcat5.sh to/etc/init. d. Then run/usr/bin/ksysv to run the startup setting tool on the graphic interface. Drag tomcat5.sh in the Available Services column to Runlever 2 Start, Runlever 3 Start, Runlever 4 Start, Runlever 5 Start, Runlever 6 Start, Runlever 0 Stop, Runlever 1 Stop, Runlever 6 Stop, you may need to pay attention to the icon position. I drag the icon to the position where the Start Project label in each column is 90.
Or you can run:
Ln-s/etc/init. d/tomcat5.sh/etc/rc0.d/K90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc1.d/K90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc2.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc3.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc4.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc5.d/S90tomcat5. shln-s/etc/init. d/tomcat5.sh/etc/rc6.d/K95tomcat5. sh
Restart the machine to see if tomcat can be started automatically.
2.2.2
Method 2.2.1 has a serious problem, that is, tomcat has the root permission. I mean that any of your jsp scripts have the root permission, so you can easily use jsp scripts to delete things on your entire hard disk! So we 'd better not use the 2.2.1 method.
We downloaded jakarta-tomcat-5.0.28.tar.gz with the fsvc tool. In the compressed package, jakarta-tomcat-5.0.28/bin/fsvc.tar.gz. If you have followed the steps above, decompress/usr/share/tomcat5/bin/fsvc.tar.gz to get the/usr/share/tomcat5/bin/fsvc-src folder. Run on the terminal:
Get the/usr/share/tomcat5/bin/fsvc-src/fsvc file. Copy the/usr/share/tomcat5/bin/fsvc-src/native/tomcat5.sh script file to/etc/init. d, and then use the half method in 2.2.1 to set tomcat to self-start.
/Etc/init. d/tomcat5.sh also needs to be modified to make it look like:
JAVA_HOME =/usr/lib/j2sdk1.4-sunCATALINA_HOME =/usr/share/tomcat5DAEMON_HOME =/usr/share/tomcat5TOMCAT_USER = tomcat5 # change it to the user name TMP_DIR =/var/empty = CLASSPATH = \ $ JAVA_HOME/lib/tools. jar: \ $ CATALINA_HOME/bin/commons-daemon.jar: \ $ CATALINA_HOME/bin/bootstrap. jarcase "$1" in start) # Start Tomcat # $ DAEMON_HOME/bin/jsvc-src/jsvc \......
Do not restart the test. Run/etc/init manually. d/tomcat5.sh start, and enter http: // localhost: 8080 or http: // 127.0.0.1: 8080 in the browser to check whether tomcat can be started, and then run/etc/init. d/tomcat5.sh stop to check whether it can be stopped.
Q: Why cannot I start tomcat with fsvc?
For more information, see http://jakarta.apache.org/commons/daemon/faq.html. If you use Debian, run modconf and install the capability module under/kernel/security. If you use another version and compile capability as a module, place it in the appropriate location of/etc/init. d/tomcat5.sh (Would you like to use line 2nd ?) Add modprobe capability.
3. Set tomcat's server. xml deployment website
If you want others to enter your IP address in the browser without adding ": Port Number" after the IP address to access your website
Change port = "8080" to port = "80", because 80 is the default port requested by the browser. Find
Change to appBase = "/home/tomcatweb ". Add:
Put your own index. jsp in the/home/tomcatweb directory and enter http: // 127.0.0.1 in the browser. Then you can see the running result of index. jsp.
4. Chinese problems
Tomcat has no special Chinese problems. In most cases, the problem with Chinese characters is that users do not write JSP code or even HTML code.
4.1 gibberish of simple HTML files
An HTML file containing Chinese characters, such:
Hello.
The above tag tells the browser that your HTML file uses the UTF-8 encoding format. Please set the UTF-8 correctly as the encoding when saving your text editor, otherwise, only the English HTML source file can ensure that there is no garbled.
4.2 simple JSP file garbled
A JSP file containing Chinese characters, such:
<% @ Page contentType = "text/html; charset = UTF-8" %> <% Out. println ("hello. "); %>
<% @ Page contentType = "text/html; charset = UTF-8" %> labels tell tomcat and java compilers that your file is encoded in UTF-8 format.
4.3 The content of the contained file is garbled
If you use The file contains child. jsp, in parent. jsp and child. the correct <% @ page contentType = "text/html; charset = UTF-8" %> (change the UTF-8 to the correct encoding) is specified in the jsp file, the two can be different.
If your parent. use <% @ include file = "child. jsp "%> the file contains child. jsp, please ensure parent. jsp and child. jsp is the same encoding and in the parent. the correct <% @ page contentType = "text/html; charset = UTF-8" %> (change the UTF-8 to the correct encoding) is set in jsp ). Do not set <% @ page contentType = "text/html; charset = UTF-8" %> in child. jsp; otherwise, tomcat will fail (not always ).
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.