Integrating Apache and Tomcat parsing JSP pages

Source: Internet
Author: User

Case requirements

1. Add JSP page support for Apache HTTP Server server.

2. Access to the Web management interface of the Tomcat container to manage a variety of JSP, servelet applications.

Knowledge Tips

In a variety of enterprise Web application Systems, JSP is also a more use of a web development language, for such a site server, must be able to support the Java environment, JSP parsing, such as the installation of Tomcat, JBoss and other JSP containers. On the other hand, Apache HTTP Server is more capable of processing static HTML pages, so if you can integrate the JSP containers such as Apache and Tomcat, you will get a better experience with the Web service.

In this case, Apache still accesses the front-end service as a browser, and when the client requests access to the *.JSP Web page, it automatically invokes the back-end Tomcat service for parsing and returns the resulting page to the client. The communication process requires the installation of the connector MOD_JK to complete.

Reference answer


First, install and configure the JDK development environment

1. Installation

[Email protected] ~]# cp/var/ftp/pub/jdk-6u20-linux-i586.bin/usr/local/

[Email protected] ~]# cd/usr/local/

[Email protected] local]# chmod a+x jdk-6u20-linux-i586.bin

[Email protected] local]#./jdk-6u20-linux-i586.bin

After executing the JDK installer, the software license agreement will be displayed, press ENTER or SPACEBAR to page to the end, follow the prompts to enter "Yes" to confirm, wait 1-2 minutes or so to complete the installation.


2. Configuration

(1) Create a link file for the JDK installation directory and execution program for easy use.

[Email protected] ~]# alternatives--install/usr/bin/java Java/usr/local/jdk1.6.0_20/bin/java 1

[Email protected] ~]# alternatives--install/usr/bin/javac Javac/usr/local/jdk1.6.0_20/bin/javac 1

[Email protected] ~]# Alternatives--config java

A total of 2 programs provide "Java".

Select command

-----------------------------------------------

*+ 1/usr/lib/jvm/jre-1.4.2-gcj/bin/java

2/usr/local/jdk1.6.0_20/bin/java

Press Enter to save the current selection [+], or type the selection number: 2

[Email protected] ~]# Alternatives--config Javac

A total of 1 programs provide "Javac".

Select command

-----------------------------------------------

* 1/usr/local/jdk1.6.0_20/bin/javac

Press Enter to save the current selection [+], or type the selection number: 1

(2) Modify the/etc/profile file to add the variable settings required by the Java development environment.

[Email protected] ~]# Vi/etc/profile

...//Omit part of the content

Java_home=/usr/local/jdk1.6.0_20

Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar

Path= $JAVA _home/bin: $PATH

Export Java_home CLASSPATH PATH

[Email protected] ~]# Source/etc/profile


3. Test

(1) View the installed JDK program version information.

[Email protected] ~]# java-version

Java Version "1.6.0_20"

Java (TM) SE Runtime Environment (build 1.6.0_20-b02)

Java HotSpot (TM) Client VMs (build 16.3-b01, mixed mode, sharing)

(2) Write a Java test applet and compile the execution.

[Email protected] ~]# VI Helloworld.java

public class HelloWorld {

public static void Main (String args[]) {

System.out.println ("helloworld!!");

}

}

[[email protected] ~]# Javac Helloworld.java//Compile program

[[Email protected] ~]# java HelloWorld//Run Helloworld.class Program

helloworld!! Show running results



Ii. Installing and configuring the Tomcat container

1. Installation

The installation process for Tomcat is simple, just to extract the source package to the destination folder.

[Email protected] ~]# tar zxf apache-tomcat-7.0.23.tar.gz

[Email protected] ~]# MV Apache-tomcat-7.0.23/usr/local/tomcat


2. Configuration

(1) Create a link file for the Tomcat installation directory and the script to start and close the service, which is easy to use.

[Email protected] ~]# ln-s/usr/local/tomcat/bin/startup.sh/usr/local/sbin/tomcat-up

[Email protected] ~]# ln-s/usr/local/tomcat/bin/shudown.sh/usr/local/sbin/tomcat-down

(2) Modify the/etc/profile file to set the variable cactlina_home that the Tomcat service needs to use.

[[email protected] ~]# vi/etc/profile //Revise the original JDK environment

...//Omit part of the content

Java_home=/usr/local/jdk1.6.0_20

Catalina_home=/usr/local/tomcat

Classpath=.: $JAVA _home/lib/dt.jar: $JAVA _home/lib/tools.jar: $CATALINA _home/lib/servlet-api.jar

Path= $JAVA _home/bin: $PATH

Export Java_home catalina_home CLASSPATH PATH

[Email protected] ~]# Source/etc/profile

(3) Modify the Tomcat-users.xml file to add the Administrator account "Benet" setting.

[Email protected] ~]# Vi/usr/local/tomcat/conf/tomcat-users.xml

<?xml version= ' 1.0 ' encoding= ' utf-8 '?>

<tomcat-users>

<role rolename= "Manager-gui"/>

<user username= "Tcadm" password= "pwd123" roles= "Manager-gui"/>

</tomcat-users>


3. Test

(1) Start the Tomcat service and confirm the monitoring status of the Tomcat service.

[Email protected] ~]# tomcat-up

Using catalina_base:/usr/local/tomcat

Using Catalina_home:/usr/local/tomcat

Using Catalina_tmpdir:/usr/local/tomcat/temp

Using Jre_home:/usr/local/jdk1.6.0_20

Using CLASSPATH:/usr/local/tomcat/bin/bootstrap.jar:/usr/local/tomcat/bin/tomcat-juli.jar

[Email protected] ~]# NETSTAT-ANPT | grep java

TCP 0 0::: 8009:::* LISTEN 2591/java

TCP 0 0::: 8080:::* LISTEN 2591/java

(2) To access http://your_server_ip:8080/, you can see Tomcat's Web Home page (1).

650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/49/B1/wKiom1QZMJDjNVCyAAWc2gaX14k406.jpg "title=" 8080. PNG "alt=" wkiom1qzmjdjnvcyaawc2gax14k406.jpg "/>

Figure 1 The Web home page of Tomcat 7.0

(3) Use the Manager App button to manage Tomcat after logging in (2).


650) this.width=650; "src=" http://s3.51cto.com/wyfs02/M01/49/B2/wKioL1QZMIrwOtCcAARV2SJkm5M633.jpg "title=" image 005. PNG "alt=" wkiol1qzmirwotccaarv2sjkm5m633.jpg "/>

Figure 2 Managing Tomcat 7.0


(4) If you want to stop the Tomcat service, execute "tomcat-down".



Iii. connecting the Tomcat service to the Apache service

1. Install the MOD_JK module.

[email protected] ~]# CP mod_jk-1.2.31-httpd-2.2.x.so/usr/local/httpd/modules/


2. Adjust the configuration of Apache services and Tomcat services.

(1) Modify the httpd.conf configuration file and add the JDK call settings.

[Email protected] ~]# vi/usr/local/httpd/conf/httpd.conf

...//Omit part of the content

DocumentRoot "/usr/local/httpd/htdocs"

...//Omit part of the content

LoadModule Jk_module modules/mod_jk-1.2.28-httpd-2.2.x.so

Jkworkersfile conf/workers.properties

Jklogfile Logs/mod_jk.log

Jkshmfile LOGS/MOD_JK.SHM

Jkloglevel Notice

Jkmount/*/*.jsp Benet

Jkmountcopy All

AddType application/x-jsp. jsp

(2) Add a Tomcat profile and establish a Web App directory link.

[Email protected] ~]# vi/usr/local/httpd/conf/workers.properties

Worker.list=benet

worker.benet.port=8009

Worker.benet.host=localhost

Worker.benet.type=ajp13

Worker.benet.lbfactor=1


(3) Restart Apache and Tomcat services

[Email protected] tomcat]# Tomcat-down; tomcat-up//or Cd/usr/local/tomcat/bin then./shutdown.sh./start.sh

[Email protected] tomcat]#/usr/local/httpd/bin/apachectl restart


3. Deploying the JSP App Catalog

Upload the JSP app to the Apache Web root directory (such as/apps/) and link to Tomcat's webaaps/. In this example, a JSP test Web page showtime.asp is created to output the system time.

[Email protected] ~]# mkdir/usr/local/httpd/htdocs/apps/

[Email protected] ~]# vi/usr/local/httpd/htdocs/apps/showtime.jsp

<% @page language= "java" import= "java.util.*"%>


[Email protected] ~]# ln-s/usr/local/httpd/htdocs/apps/usr/local/tomcat/webapps/


4. Access http://www.benet.com/apps/showtime.jsp for testing

The current system time (3) of the prompt information machine should be output normally in the Web page.


Figure 3 JSP test page display results 650) this.width=650; "Src=" http://s3.51cto.com/wyfs02/M02/49/B1/wKiom1QZMFTxg3IIAAFY88AF4VA193.jpg "Title=" image 006.png "alt=" Wkiom1qzmftxg3iiaafy88af4va193.jpg "/>

This article is from the "Dragon Love Xue qi" blog, please make sure to keep this source http://dragon123.blog.51cto.com/9152073/1554350

Integrating Apache and Tomcat parsing JSP pages

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.