Set up a JSP development environment in Ubuntu

Source: Internet
Author: User
Tags gz file

Set up a JSP development environment in Ubuntu 7.04
MySQL + Tomcat + Apache + j2sdk1.6

Enter rpm-Q-A in terminal to check whether the required software for RPM and RPM packages has been installed before all installation starts.
If no rpm is installed, enter sudo apt-Get install rpm in terminal.

1. Install MySQL


Sudo apt-Get
Install mysql-Server


Start MySQL service as root:/etc/init. d/MySQL start


Stop MySQL service as root:/etc/init. d/MySQL stop

Start MYSQL:
Mysql-u root-P


Password

Ii. Install j2sdk



1. Download the JDK Installation File

Go to Sun's website
Download the latest j2sdk version:
[Url = Response


This download is
Jdk-6u1-linux-i586.bin

Downloaded to the user folder:
Homefolder (/home/jinye) in the places drop-down box)



2. Install the JDK File

In terminal, enter
/Jdk-6u1-linux-i586.bin


After a long string of Protocol Descriptions, you will be asked whether you agree with the agreement, and press y to start installation.

The folder name after installation is
Jdk1.6.0 _ 01



3. Establish a connection for JDK

Ln-S
JDK 1.6.0.0 _ 01

3. install Tomcat



1. Download the tomcat installation file


On the website [url = http://tomcat.apache.org/#http://tomcat.apache.org/#/url]
Download Tomcat


Download optionsSource codeOr binary files, this download is compressed binary file apache-tomcat-6.0.13.tar.gz



2. Unzip and install Tomcat

Tar zxf
Apache-tomcat-6.0.13.tar.gz


The decompressed folder APACHE-Tomcat-6.0.13 appears in the current directory.



3. Establish a connection for Tomcat

Ln-S
Apache -- tomcat-6.0.13 Tomcat

Iv. Configure Environment Variables

This is troublesome. I not only modified the following file, but also added the environment variable in/etc/enviroment and restarted it.


In
After adding the following content to/etc/profile, run it in the system (restart the host)


Path = $ path:/home/jinye/JDK/bin:/home/jinye/JDK/JRE/bin


Java_home =/home/jinye/JDK

Export
Java_home


Classpath = "./:/home/jinye/JDK/lib:/home/jinye/JDK/JRE/lib"

Export
Classpath


Catalina_home =/home/jinye/tomcat

Export
Catalina_home

5. Download, install, and configure the Apache server


1. Install

Sudo apt-Get
Install apache2



2. Integration of apache2 and tomcat6


sudo apt-Get
install libapache2-mod-jk
check whether JK exists in the startup module of apache2. load
sudo ls
/etc/apache2/mod-enabled/
CGI. load
mod-security.conf
php5.conf
proxy. conf
rewrite. load userdir. load
JK. load
mod-security.load
php5.load
proxy. load userdir. conf



Modify the workers. properties file to change the tomcat_home and java_home addresses to JDK and tomcat installed above.
Address

Sudo gedit
/Etc/libapache2-mod-jk/workers. Properties


Workers. tomcat_home =/home/jinye/tomcat


Workers. java_home =/home/jinye/JDK






Configure/etc/apache2/apache2.conf

Set # sudo gedit
/Usr/share/doc/libapache2-mod-jk/content in httpd_example_apache2.conf



Copy to the end of apache2.conf


sudo
/etc/init. d/apache2 restart
sudo
/usr/share/tomcat6/bin /. /shutdown. sh
sudo
/usr/share/tomcat6/bin /. /startup. sh
sudo gedit
/etc/rc. local
modify the jdk_home
and java_home addresses
export
jdk_home =/home/jinye/JDK
Export
java_home =/home/jinye/JDK


Sudo gedit
/Etc/apache2/httpd. conf


Open the httpd. conf file and add the following persons to the file:Code:

Loadmodule
Jk_module/usr/lib/apache2/modules/mod_jk.so


Jkworkersfile "/etc/libapache2-mod-jk/workers. properties"

Jklogfile
"/Var/log/apache2/mod_jk.log"

Jkloglevel
Info


Jklogstampformat "[% A % B % d % H: % m: % S % Y]"

Jkmount
Servlet/ajp13_worker



Open [url = http: // localhost/index. jsp] http: // localhost/index. jsp [/url]


See Apache
The Tomcat homepage indicates that the installation and integration are successful.



* Note ************************************** *********************


Jkmount
Servlet/ajp13_worker

Two
"Ajp13_worker"
It appears in the following lines in the file/etc/libapache2-mod-jk/workers. properties that are not commented out:







Worker. List = ajp13_worker


Worker. ajp13_worker.port = 8009


Worker. ajp13_worker.host = localhost


Worker. ajp13_worker.type = ajp13


Worker. ajp13_worker.lbfactor = 1


Worker. loadbalancer. balanced_workers = ajp13_worker



When modifying/etc/apache2/httpd. conf, be sure to keep the same


**************************************** **********************

6. Use JDBC in JSP to connect to the MySQL database



1. Download The JDBC driverProgram


Www.mysql.com/downloads/find connectors, and then there is connector/J on the left side of the page.
Click here to download the selected tar.gz and ZIP files.


Download the .tar.gz File



2.expand the just-downloaded file (mysql-connector-java-5.0.6.tar.gz)

Tar zxvf
Mysql-connector-java-5.0.6.tar.gz



3. Configure the connection file


Will just expand the mysql-connector-java-5.0.6
Copy the mysql-connector-java-5.0.6-bin.jar file to the JDK and
In the Lib folder under Tomcat

CD
Mysql-connector-java-5.0.6

CP
/Mysql-connector-java-5.0.6-bin.jar ~ /JDK/lib

CP
/Mysql-connector-java-5.0.6-bin.jar ~ /Tomcat/lib



4. the following format can be used to connect to the database during JSP writing:


Class. forname ("com. MySQL. JDBC. Driver"). newinstance ();

Connection
Conn =
Drivermanager. getconnection ("JDBC: mysql: // localhost/Database Name", "User Name", "password ");


Statement
Stmt = conn. createstatement (resultset. type_scroll_sensitive,
Resultset. concur_updatable );

String SQL =
"Select * from database name ";

Resultset rs
= Stmt.exe cutequery (SQL );

* *** Note: Chinese Characters in JSP files in Linux are sometimes garbled and can be used in JSP files. <% @
Page C %> *****

7. Test

Sudo
-Sh


Password


Start MySQL
Service:


#/Etc/init. d/MySQL start


Start Tomcat
Service:


#/Home/tomcat/bin/startup. Sh



Create databases and tables for testing:

#/MySQL-u
Root-P


Password




Mysql> Create Database test;


Mysql> use test;


Mysql> Create Table Test (test1 varchar (20), Test2
Varchar (20 ));


Mysql> insert into test (test1, Test2) Values
('A', 'B ');




// Check whether the test information has been added


Mysql> show databases;


Mysql> show tables;


Mysql> select * from test;






Create a new empty file named test. jsp under/home/jinye/tomcat/webapps/root and write the code


The test code is as follows:
//------------------------------------------------------------------------




<% @ Page C %>


<% @ Page import = "Java. util. *" %>


<% @ Page import = "Java. SQL. *" %>



<HTML>


<Body>


<%








Class. forname ("com. MySQL. JDBC. Driver"). newinstance ();



Connection conn =
Drivermanager. getconnection ("JDBC: mysql: // localhost/test", "root", "666nnn ");






Statement
Stmt = conn. createstatement (resultset. type_scroll_sensitive,
Resultset. concur_updatable );



String SQL = "select * from
Test ";



Resultset rs =
Stmt.exe cutequery (SQL );








While (Rs. Next ()){
%>






The content of your first field is: <% = Rs. getstring (1) %>




Your second field content is: <% = Rs. getstring (2) %>


<% }%>


<% Out. Print ("database operation successful, congratulations"); %>


<%
Rs. Close ();



Stmt. Close ();



Conn. Close ();


%>


</Body>


</Html>
//-------------------------------------------

Related Article

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.