Linux network server architecture practices

zhaozj2021-02-16  49

/ * ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- ------------------------ Write in front: I see many netizens's questions are related to server configuration, build a reliable and safe application development The server is the foundation of web programming, especially for friends who have developed JSP on Linux.

This document is the crystallization of my multi-year server configuration. I haven't been modified by my N before publishing (the last big revision is just released in RH7.2, and then because I have not found a mistake because I didn't find any mistakes, I didn't have it. Upgrade), documentation

Be reprinted by Tianji.com by the end of 2001 (http://www.yesky.com/200206/217592.shtml), then reproduced multiple Linux and Java communities such as LinuxBYE.NET, CNJsp.COM, have not been discovered since the time test Error, you are as good as

safe to use.

Documentation is not ideal in the web page, if you want to get PDF of this document, or have any comments, you can mail to Roczhao@msn.com

The document is longer, divided into more articles, this is the sixth, the following is the text: ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ ----------------------------------------- * /

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

Step 16 Server Test

## Why not use 1 1 = <% = 1 1%> or <% Out.Print ("Hello World!");%> This example? Because this example can only test whether Apache and Resin can Collaborative work, do not test database connections, JDBC2.0 support, whether Chinese issues exist, etc. The following example will be given, the first example can test all the above problems; the second example tells you how to use the connection pool of RESIN; the third example tells you how to call the component, how to separate the data layer and the processing layer The fourth example is used to test PHP.

Example 1: Connect the database using the connection string

1 Create a database

## The database script is as follows, can be stored as a .sql file, then use phpMyAdmin to generate a database

## Note, the following example will also use the database.

Create Database Yesgo

Use yesgo;

Create Table ProV

(

ProV_id tinyint (2) Not Null Primary Key,

ProV_name char (6) Not null

);

INSERT INTO PROV VALUES ('01', 'Anhui');

INSERT INTO PROV VALUES ('02', 'Beijing');

Insert Into Prov Values ​​('03', 'Chongqing');

INSERT INTO PROV VALUES ('04', 'Fujian');

Insert Into Prov Values ​​('05', 'Gansu');

Insert Into Prov Values ​​('06', 'Guangdong');

Insert Into Prov Values ​​('07', 'Guangxi'); Insert Into Prov Values ​​('08,' Guizhou ');

INSERT INTO PROV VALUES ('09', 'Hainan');

Insert Into Prov Values ​​('10', 'Hebei');

INSERT INTO PROV VALUES ('11', 'Heilongjiang');

INSERT INTO PROV VALUES ('12', 'Henan');

Insert Into Prov Values ​​('13', 'Hubei');

INSERT INTO PROV VALUES ('14', 'Hunan');

INSERT INTO PROV VALUES ('15', 'Inner Mongolia');

INSERT INTO PROV VALUES ('16', 'Jiangsu');

Insert Into Prov Values ​​('17', 'Jiangxi');

INSERT INTO PROV VALUES ('18', 'Jilin');

Insert Into Prov Values ​​('19', 'Liaoning');

INSERT INTO PROV VALUES ('20', 'Ningxia');

Insert Into Prov Values ​​('21', 'Qinghai');

INSERT INTO PROV VALUES ('22', 'Shanxi');

INSERT INTO PROV VALUES ('23', 'Shaanxi');

INSERT INTO PROV VALUES ('24', 'Shandong');

INSERT INTO PROV VALUES ('25', 'Shanghai');

INSERT INTO PROV VALUES ('26', 'Sichuan');

Insert Into ProV Values ​​('27', 'Tianjin');

INSERT INTO PROV VALUES ('28', 'Tibet');

INSERT INTO PROV VALUES ('29', 'Xinjiang');

INSERT INTO PROV VALUES ('30', 'Yunnan');

INSERT INTO PROV VALUES ('31', 'Zhejiang');

INSERT INTO PROV VALUES ('32', 'Hong Kong');

INSERT INTO PROV VALUES ('33', 'Macau');

Insert Into Prov Values ​​('34', 'Taiwan');

2 Add an account for the database

## The account added as follows is only permissions to the YESGO database and has all permissions to it. But why do you want to add four times? Mainly Host's different, it is necessary to note that mysql verification is a connection correct, but also depends on the account and password, but also look at the host name and database name.

MySQL -P

. Mysql> grant all privileges on yesgo * to your_user_name @ localhost identified by 'your_password' with grant option;. Mysql> grant all privileges on yesgo * to your_user_name@'ns.yesgo.loc 'identified by' your_password 'with grant option;

MySQL> Grant All Privileges on yesgo. * to your_user_name@'192.168.1.2 'ide1' Your_password 'with grant option;

Mysql> Grant All privileges on yesgo. * to your_user_name @ '%' identified by 'Your_password' with grant option;

Mysql> EXIT

3 Create a JSP source file

Touch /Home/www/cnmysql.jsp

Chown -r www /Home/www/cnmysql.jsp

Chgrp -r root /Home/www/cnmysql.jsp

CHMOD 771 /HOME/www/cnmsql.jsp

vi /Home/www/cnmsql.jsp

## The source code is as follows:

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

<%

Class.Forname ("org.gjt.mm.mysql.driver");

Connection conn = drivermanager.getConnection ("JDBC: MySQL: // Host_Name / DB_NAME", "User_Name", "Password");

Statement Stmt = conn.createstatement ();

ResultSet RS = Stmt.executeQuery ("SELECT * from proV");

rs.next ();

Out.print (rs.getstring ("prov_id") " rs.getstring (" proV_name ") "
");

rs.next ();

Out.print (rs.getstring ("prov_id") " rs.getstring (" proV_name ") "
");

rs.previous ();

Out.print (rs.getstring ("prov_id") " rs.getstring (" proV_name ") "
");

Rs.last ();

Out.print (rs.getstring ("prov_id") " rs.getstring (" proV_name ") "
");

Rs.first ();

Out.print (RS.GetString ("Prov_ID") " rs.getstring (" proV_name ") "
"); rs.close ();

Stmt.close ();

CONN.CLOSE ();

%>

4 test the program

Lynx http://www.yesgo.loc/cnmysql

## The correct result should be:

1 Anhui

2 Beijing

1 Anhui 34 Taiwan

1 Anhui

Example 2: Connect the database using the connection pool

1 establish a data source

vi /usr/local/resin/conf/RESIN.conf

JDBC / YESGO // Data Source Name

javax.sql.datasource // data source type

// database driver

// connection string

// username

// password

// maximum number of connections

// delay time

2 Create a JSP source file

Touch /Home/www/testpool.jsp

Chown -r www /Home/www/testpool.jsp

Chgrp -r root /Home/www/testpool.jsp

CHMOD 771 /HOME/www/testpool.jsp

vi /Home/www/testpool.jsp

## The source code is as follows:

<% @ page language = "java" import = "java.sql. *, com.caucho.sql. *;"%>

<%

DBPOOL POOL = New dbpool ();

Connection conn = pool.getpool ("Data_Source_name") .getConnection ();

Statement Stmt = conn.createstatement ();

ResultSet RS = Stmt.executeQuery ("SELECT * from proV");

rs.next ();

Out.print (rs.getstring ("prov_id") rs.getstring ("proV_name") "
");

rs.next ();

Out.print (rs.getstring) rs.getstring ("proV_name") "
"); rs.previous ();

Out.print (rs.getstring ("prov_id") rs.getstring ("proV_name") "
");

Rs.last ();

Out.print (rs.getstring ("prov_id") " rs.getstring (" proV_name ") "
");

Rs.first ();

Out.print (rs.getstring ("prov_id") rs.getstring ("proV_name") "
");

Rs.close ();

Stmt.close ();

CONN.CLOSE ();

%>

3 debug the program

Lynx http://www.yesgo.loc/testpool.jsp

## The result of the process is the same as an example:

1 Anhui

2 Beijing

1 Anhui 34 Taiwan

1 Anhui

转载请注明原文地址:https://www.9cbs.com/read-23316.html

New Post(0)