Summary: For the wide application of Web technology, Java is widely used in various platforms due to its unrelated nature. This paper explores how to build Java's basic web development platform under UNIX (Linux) systems.
Keywords: UNIX; Linux; JSP; mysql
introduction
With the rapid development of Internet technology, more and more companies use Internet protocol standards and Web technology to build an enterprise network -Intranet to achieve information publishing and data sharing. The information economy is challenging today's business, and web applications have great advantages over traditional information processing technology, so that companies are building their information economy on Internet and WWW.
Since the generation of Web, after several years of development, Web technology has developed from the initial simple document to today's complex e-commerce applications, and there are two phases of static documents and dynamically interactive pages. The first phase of Web technology is mainly for browsing of simple static web pages. At this stage, the web page can only contain some unchanging information content, which is basically satisfied with the original intention of the WEB, and realizes the sharing of information resources. With the development of the Internet, the first phase of Web technology cannot meet the further requirements, and the Web technology has entered the second phase of its development: the dynamic interactive page phase. Web database technology is the main core technology in this stage, people need to express their opinions, query data, even online shopping, which urgently needs the interconnection of Web and databases. Combining Web technology with data technology, developing dynamic web database applications have become the main application of today's web technology. Web and database interconnect technology mainly include CGI technology, various web server API (ISAPI, NSAPI) technology, server-side Script interpreted language ASP and PHP, etc., as shown in Figure 1.
Figure -Web and database interconnection structure diagram
Java language is an object-oriented and platform-independent programming language with simplicity, object-oriented, dynamic, distributed, portability, multi-process, platform-independent, high performance, robustness, and security. . Therefore, Java is a great advantage in Web technology. With the development of the development of the Internet, Java has become more and more. People who have just started to develop web applications are often developed under the Windows platform. Should be a few other platforms. So developing Java web apps under Windows, everyone is more familiar, and developing Java under Unix (Linux) is rare, everyone is relatively unfamiliar. What I want to say is how to build a Java development environment in a UNIX (Linux) environment. This also benefits from the advantages of Java's writing.
1 environmental construction
To develop web applications using Java, you must need a Java's operating environment and development environments. Of course, the Web has less than a database. The web program is not running with a web server.
Here we use Java operating environment: J2SDK1.4
Database: mysql 4.0.15
Web server: Tomcat 4.1.18
1.1 Java operating environment
The first thing to build is the Java's operating environment. To Sun.com http://java.sun.com/j2se/1.4.2/download.html free download J2SDK-1_4_2_05-linux-i586.bin then copy to the installation directory
Enter a binary file to decompress the file:
[root @ localhost jdk] #. / j2sdk-1_4_2_05-linux-i586.bin
After decompression is completed, you can find the J2SDK1.4.2_05 directory below the current directory.
For convenience, you can do a simple connection to this directory.
[root @ localhost jdk] #LN -S J2SDK1.4.2_05 JDK then add environment variables
Export jvav_home = / var / jdk / jdk1.4
Export ClassPath = $ java_home / lib: $ java_home / jre / lib :.
Export Path = $ PATH: $ java_home / bin: $ java_home / jre / bin
Now the Java running environment is set, you can try a Java program to verify
[root @ localhost jdk] #vi helloworld.java
Enter the following
Public class helloworld {
Public static void main (string args []) {
System.out.Println ("Hello, Wrold");
}
}
: WQ
Word disc and exit editor
[root @ localhost jdk] #javac HelloWorld.java
No mistakes
[root @ localhost jdk] #java helloworld
Hello, World
Congratulations, your Java running environment is built. Now go to the next step.
1.2 mysql database installation
1 download database installation file mysql-4.0.15a.tar.gz
2 Establish myslql users and groups
[root @ localhost var] # groupadd mysql
[root @ localhost var] # UserAdd -g mysql mysql
3 Modify the .bash_profile file below the root directory below the root directory Add path environment variable
[root @ localhost root] #vi .bash_profile
PATH = $ PATH: $ HOME / BIN: / USR / local / mysql / bin
Save exit
Let's see if you have MYSQL.
4 decompressed file
[root @ localhost jdk] #tar xzvf mysql-4.0.15a.tar.gz
Enter the contents of the decompression
[root @ localhost var] # cd mysql-4.0.15a
5 Configure the release version and compile
[root @ localhost mysql-4.0.15a] #. / configure --prefix = / usr / local / mysql
[root @ localhost mysql-4.0.15a] #make
When you run configure, you may want to specify some options, - Prefix options to install the mysql directory for / usr / local / mysql
6 installation everything
[root @ localhost mysql-4.0.15a] #make install
You may need root users to run this command
OK is now installed now Mysql database servers. There is still important steps to be implemented.
7 Create a MySQL authorization form (only if you haven't installed MySQL before:
[root @ localhost mysql-4.0.15a] # scripts / mysql_install_db
8 After doing the above steps we can start MySQL for operation.
[root @ localhost mysql-4.0.15a] #CD / usr / local / mysql / bin
[root @ localhost bin] # ./mysqld_safe &
If there is no error message, check the mysql process
[root @ localhost bin] # ps aux | grep mysql
Root 1205 0.0 0.0 5388 168?
S APR22
0:00 / bin / sh / usr / loga
L / mysql / bin / mysqld_safemysql 1227 0.0 1.3 100316 13756?
S APR22
0:36 [MySQLD]
Root 22956 0.0 0.0 4816 640 PTS / 1 S
10:41
0:00 grep mysql
Bold is MySQL process.
You can use mysql now, log in to the MySQL server with root
[root @ localhost bin] #mysql -u root -p
Here, you will be prompted to enter the password default root user password is empty. Going directly to you can
ENTER Password:
Welcome to the mysql monitor. Commands end with; or / g.
Your MySQL Connection ID IS 95 To Server Version: 4.0.15a-log
Type 'help;' or '/ h' for help. Type '/ c' to clear the buffer.
MySQL>
This will successfully log in to the MYSQL server.
mysql> show data;
--------
| Database |
--------
| cuMT |
| mysql |
| Test |
--------
3 rows in set (0.01 sec)
You can now build a database. I don't introduce how to build a database and build a table.
Root users do not passwords are unsafe, so you need to modify the password of the root user
[root @ localhost bin] # mysqladmin -u root password 'new-password'
Change 'new-password' to your own password.
Note: After doing the above, we can manage the database with MySQL's bin directory. But this has not been able to use the database in the program. The following error occurred when I connect the database in the JSP:
Java.sql.sqlexception: Data Source Rejected Establish From Server: "Host 'localhost.localdomain'is Not allowed to connect to this mysql server"
This is the specific explanation of mysql permissions, please refer to the access rights system of the mysql reference manual
What we need to do is to let root can connect to the database from localhost, you can also create a new user to connect
Log in to the mysql server
MySQL> grant all privileges on *. * to cumt @ localhost
Identified by 'cumt' with grant option;
Mysql> grant all privileges on *. * to cumt @ "%"
Identified by 'cumt' with grant option;
These two days of statement adds the user cumt to connect to a complete super user of the server from anywhere, but must use a password CUMT to do this. Now we can connect the database from the program to CUMT.
But there is no write access to the table in the program. This is because our database users are ROOT instead of our MySQL users in the MySQL group. So only the permissions that read the permissions are not written. We need to change the owner of the directory and files below the Var directory below the mysql directory: MYQL users in the mysql group:
[root @ localhost bin] #Chown -r mysql / usr / local / mysql / var [root @ localhost bin] #CP support- files / my-medium.cnf /etc/my.cnf
Ok, we can use the CUMT to connect to the database and the operation database in the program.
1.3 Web Server Tomcat Installation Configuration
Download Tomcat, Jakarta-Tomcat-4.1.18.tar.gz
unzip
Root @ localhost var] #tar xzvf jakarta-tomcat-4.1.18.tar.gz for easy operation: ln -s jakarta-tomcat-4.0.1 Tomcatln -s J2SDK1.4.0 JDK modified Tomcat / bin / startup.sh as: Export java_home = / usr / local / jdkexport classpath = $ java_home / lib: $ java_home / jre / lib: .export path = $ PATH: $ java_home / bin: $ java_home / jre / bin / usr / local / tomcat / bin / Catalina.sh Start launches Tomcat / Bin / Startup.sh1. Using PS -AX | GREP Tomcat You can query the presentation of the Tomcat programs in memory Use http: // Your server domain name or IP address or localhost: 8080 / Access 2. Require system boot automatic tomcat to join: /usr/local/tomcat/bin/startup.sh3. For Linux7.1 system, Tomcat seems to be started normally, you need to install: Compat- LibSTDC - 6.2-2.9.0.14.i386.0.14.i386.2.9.0.14.i386.rpm4. If you want to access your JSP program with http://www.xxx.com:8080/Myweb, The following steps: (1). Create a directory MYWEB such as / home / bqlr / myweb (2). Create a web-inf and web-inf / classes directory (3) under MyWeb. Modify Server in Tomcat's confed .xml:
(4) In Tomcat's WebApps directory, establish a directory connection MyWebln -S / Home / BQLR / MYWEB / USR / local / Tomcat / WebAPPS / MyWeb (5) Restart Tomcat. Class file is placed in / home / BQLR / MyWeb / Web-INF / CLASSES directory JSP file is placed under / home / bqlr / myweb