Chapter 3 DQM technology

 

Dynamic web page file can easy create and manage dynamic content, DQM technology of kangaroo-egg is a dynamic web page technology. This chapter will be introduce the syntax of dqm script language. About work flow of DQM please refer to addendum 1.

 

 

3.1  Introduce DQM

Add fragments of java program into traditional web HTML document then become dynamic web page(DQM web page). Dynamic web page can use database, redirects URL and other advanced features. Because dynamic web page executed at server, so network transmission to the client is only the result.

 

 

3.2 DQM directives

Directives content is inside “<%@” and “%>”, you can use it to set attribute of dynamic web. Now kangaroo-egg has three directives.

1.       Directive of “page”

Syntax: <%@page attributeA="valueA" attributeB="valueB" %>

Attribute name is case insensitive. This directive can wirte at dqm file (dynamic web page) any line. If a same directive wrote at dqm file many times, then the last directive is available.

 

Attribute of page directive

Function

Example

contenttype

Set response result’s MIME type. If not set this attribute then server use default value “text/html”.

<%@page contenttype= "text/html; charset=GB2312" %>

buffer

Whether to enable buffer function, the value can only set to “true” or “false”. If not set this attribute then server default to disable buffer function.

<%@page buffer = "true" %>

compress

Whether to enable content compress function, the value can only set to “true” or “false”. If not set this attribute then server will use current host “needCompress” element’s value to decide enable or disable compress funtion. (About “needCompress” element please refer to section 2.3 and 2.5)

<%@page compress = "true" %>

import

Import java classes and packages, you can use comma or semicolon to split the classes that need to import. You can repeatedly used this directive to add different classes and packages. Even if not set this attribute the server also will defaulr import “java.io.*” and “com.kangaroo_egg.dqm.*”.

<%@page import = "java.awt.*; java.awt.image.BufferedImage, javax.imageio.ImageIO" %>

session

Whether to enable session on current dqm file, the value can only set to “true” or “false”. If not set this attribute then server default to enable session function. (About session please refer to chapter 8.

<%@page session = "true" %>

command

Whether to enable “command” function on current dqm file, the value can only set to “true” or “false”. If not set this attribute then server default to disable command function. (About command we will introduce later.)

<%@page command = "true" %>

isthreadsafe

Whether to enable safe thread mode function on current dqm file, the value can only set to “true” or “false”. If this attribute set to “true”, then the current dqm file is saft when many user visit it at same time. If this attribute set to “false”, then the same time current dqm file can only be visited by a single user. If not set this attribute thenthe value default is “true”.

<%@page isthreadsafe = "true" %>

Table 3-2-1

 

2.       Directive of “include”

Dqm file (dynamic web page) can use “include” directives to include other files(dqm files, html files, or other type files). If the file (included use “include” directives) containing fragments of java program or directives, then these code were also executed.

Syntax: <%@ include file="filename"%>

In the development of web applications, if most dqm file contains the same content then you can let this part of the same content into a single file, and use “include” directives to include this file. This can increase performance while maintaining.

 

Notice: Include directive only can hold a single file attribute. For example:

<%@ include file="1.txt" file="2.txt"%>

Then server will inform user that error syntax.

Underside is correct syntax:

<%@ include file="1.txt"%><%@ include file="2.txt"%>

 

The space of at file’s head and end will be ignored. For example:

<%@ include file="  1.txt  "%>  equal  <%@ include file="1.txt"%>

 

The include file can use relative path or absolute path. Relative path is relative to the current dqm file's path. For example: “../xxx.txt”, “test/xxx.txt”. Absolute path’s example is “c:\xxx.txt”, “/xxx.txt”.

 

3.       Directive of “bean”

It’s very similar to the JSP javabean, the function is repeated use components. Please refer to Chapter 11.

 

 

3.3 Fragments of java program

You can insert fragments of java program into dqm file. A simple example, hello.dqm, source code:

1

2

3

4

<%

String s = "hello!";

out.print(s);

%>

 

When user visit “hello.dqm” the result is “hello!”. You can see the fragments of java program of between “<%” and “%>”. However, you may have noticed that has a “out” object, it’s a built-in object. Kangaroo-egg server has six built-in object: out, request, response, session, application and command. Later, we will introduce these objects.

 

 

3.4 Dqm file released

How to release dqm files? Very easy, only put the dqm files into host or virtual host home directory (webpath). The home directory has specific structure.

 

folder

description

home directory (root directory)

use “webPath” element set it

The location of main host or virtual host home directory, all the dynamic web files (dqm files), html files and other resources are stored under this directory.

home directory/WEB-INF/classes

All the java class files that dqm file need used are stored under this directory.

home directory/WEB-INF/lib

All the java jar or zip files that dqm file need used are stored under this directory. For example, you can put JDBC Driver jar file under this folder.

home directory/WEB-INF/work

Kangaroo-egg will put dqm compiled files under this folder.

Table 3-4-1

 

From table 3-4-1 you can seen that java file should put under “classes” and “lib” directory, but there is some difference. The java class file only can be stored under “classes” folder. The jar or zip file (many java class files can pack into a jar or zip file) only can be stored under “lib” folder.

If “classes” and “lib” folder containing the same name class file then server will priority load file that at “classes” folder.

 

Notice: The class file that at “classes” or “lib” folder only can loaded by current main host or virtual host.

 

The “WEB-INF” is not necessarily, if you not use dqm file(only use static html file) then this folder an not existed. If “classes” and “lib” folder (that under “WEB-INF” folder) not existed, so you can create it manually.

If you enable automatically compile dqm file then server will automatically create the “WEB-INF” folder when complie dqm file. About automatically compile please refer to section 2.3 and 2.5.

The dqm file name must conform to the java identifier. For example a dqm file name is “he-llo.dqm”, but this dqm file name is invalid. Because file name include “-” symbol, this symbol can’t be part of a Java identifier. And the folder that dqm file under it must conform to the java identifier too.

In windows OS that file name is case insensitive, but java is case sensitive, so maybe will happen the status of compiled folder confused. For example a web application with a “sd” folder, and a name of “hello.dqm” file under “sd” folder.

Folder structure: web application root/sd/hello.dqm

 

When user visit this dqm file then server will compile it frist, so you can find compiled file under “WEB-INF” folder.

Compiled folder structure: WEB-INF/work/com/kangaroo_egg/workfile/sd/hello_dqm.class

 

Next we change web application “sd” folder to “Sd”, and create a new dqm file “hello1.dqm” under it.

Now folder structure: web application root/Sd/hello1.dqm

web application root/Sd/hello.dqm

 

When user visit new file “hello1.dqm” then server will compile it first, so you can find new compiled file under “WEB-INF” folder.

Compiled folder structure: WEB-INF/work/com/kangaroo_egg/workfile/sd/hello_dqm.class

WEB-INF/work/com/kangaroo_egg/workfile/sd/hello1_dqm.class

 

You can seen that “sd” folder(under WEB-INF) not be changed, because windows think two directory(“sd” and “Sd”) is the same. But this time problem is coming, java is case sensitive, so mistakes will happen when execute “hello1_dqm.class”, because “hello1_dqm.class” file must under “Sd” folder.

Ok you maybe think I can chang the folder name “sd” to “Sd”:

WEB-INF/work/com/kangaroo_egg/workfile/Sd

But it’s not feasible, because “hello_dqm.class” must under “sd” folder.

Like this status we call it compiled folder confused, to solve it must delete this folder and all under it files: WEB-INF/work/com/kangaroo_egg/workfile/sd/ , and recompile.

Now kangaroo-egg server can detect this status and solve it automatically, but sometimes maybe can’t delete confused folder, then will prompt user delete it manually.

Please don’t change folder name that under “WEB-INF” folder.