Transcript Document

Chapter 34 - Case Study: Active Server
Pages and XML
Outline
34.1
34.2
34.3
34.4
34.5
34.6
34.7
34.8
Introduction
Setup and Message Forum Documents
Forum Navigation
Adding Forums
Forum XML Documents
Posting Messages
Other Documents
Web Resources
 2004 Prentice Hall, Inc. All rights reserved.
1
2
Objectives
• In this tutorial, you will learn:
– To create a Web-based message forum using Active Server
Pages.
– To use XML with Active Server Pages.
– To be able to add new forums.
– To be able to post messages to the message forum.
– To use Microsoft’s DOM to manipulate an XML document.
– To use XSLT to transform XML documents.
 2004 Prentice Hall, Inc. All rights reserved.
3
34.1 Introduction
• Message forums
–
–
–
–
Popular internet feature
Discuss topics
Exchange information
Several major sites provide this service
• messages.yahoo.com/index.html
• web.eesite.com/forums
• groups.google.com
 2004 Prentice Hall, Inc. All rights reserved.
4
34.2 Setup and Message Forum Documents
• Prerequisites
–
–
–
–
Microsoft Internet Information Services 6 (IIS)
Internet Explorer 6 (for XML and XSLT processing)
MSXML 3.0 or higher
Write permissions on forum folder
 2004 Prentice Hall, Inc. All rights reserved.
5
34.2 Setup and Message Forum Documents
File name
forums.xml
default.asp
template.xml
addForum.asp
forumASP.xml
formatting.xsl
addPost.asp
invalid.html
site.css
style.css
Fig. 34.1
Description
XML document listing all available forums and
their filenames.
Main page, providing navigational links to the
forums.
Template for a message forum XML document.
Adds a forum.
Sample message forum.
Document for transforming message forums into
XHTML.
Adds a message to a forum.
Used to display an error message.
Style sheet for formatting XHTML documents.
Style sheet for formatting the message forum site.
Message forum documents.
 2004 Prentice Hall, Inc. All rights reserved.
6
34.3 Forum Navigation
Fig. 34.2
Key interactions between message forum documents.
default.asp
forums.xml
addForum.asp
forumASP.xml
formatting.xsl
addPost.asp
 2004 Prentice Hall, Inc. All rights reserved.
7
34.2 Setup and Message Forum Documents
• Forum listing
– XML
– filename attribute
 2004 Prentice Hall, Inc. All rights reserved.
1
<?xml version = "1.0"?>
8
Outline
2
3
<!-- Fig. 34.3 : forums.xml -->
4
<!-- Creating the ASP forum -->
forums.xml
(1 of 1)
5
6
<forums>
7
8
<forum filename = "forumASP.xml">ASP</forum>
9
10 </forums>
Name of forum.
XML document that contains the
information for forum ASP.
 2004 Prentice Hall, Inc.
All rights reserved.
9
34.2 Setup and Message Forum Documents
• Presenting forum listing
– Convert to XHTML
– CSS for formatting
– ASP facilitates the conversion
• DOMDocument
• Async property
• DocumentElement
• ChildNodes
• For Each…Next control structure
 2004 Prentice Hall, Inc. All rights reserved.
1
<% @LANGUAGE = "VBScript" %>
10
Outline
2
3
<% ' Fig. 34.4 : default.asp
4
' Forum home page
5
Option Explicit
6
default.asp
(1 of 3)
%>
7
8
9
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
Link to CSS style sheet style.css.
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
10
11 <html xmlns = "http://www.w3.org/1999/xhtml">
12
13
<head>
14
<title>Deitel Message Forums</title>
15
<link rel = "stylesheet" type = "text/css"
href = "style.css" />
16
17
</head>
18
19
<body>
20
<h1>Deitel Message Forums</h1>
21
<p><strong>Available Forums</strong></p>
22
<ul>
 2004 Prentice Hall, Inc.
All rights reserved.
23 <%
11
24
Dim xmlFile, xmlNodes, xmlItem
25
Dim strPath, strTitle, strFileName
Setting
26
27
strPath
28
Outline
Instantiate an XML DOM object.
Async to False causes the object referenced by xmlFile
Method Load parses the XML document forums.xml.
to behave synchronously.
default.asp
= Server.MapPath(
If the"forums.xml"
parsing fails,) the browser is redirected to invalid.html
.
(2 of 3)
29
Set xmlFile = Server.CreateObject( "Microsoft.XMLDOM" )
30
xmlFile.Async = False
31
32
33
34
If Not xmlFile.Load( strPath ) Then
Call Server.Transfer( "invalid.html" )
End If
35
36
Set xmlNodes = xmlFile.DocumentElement.ChildNodes
37
38
For Each xmlItem In xmlNodes
39
strFileName = xmlItem.getAttribute( "filename" )
40
strTitle
xmlItem.text
Property= DocumentElement
gets the root element’s child nodes.
41 %>
42
<li>
<a href = "<%
43
44
</li>
45 <%
46
Property ChildNodes returns a collection of the
=strFileName
%>"><%
=strTitle
%></a>
element
node’s
child nodes.
Method getAttribute gets a forum’s filename.
Next
47 %>
48
</ul>
The anchor element creates a link to the available forums.
 2004 Prentice Hall, Inc.
All rights reserved.
49
50
12
<p><strong>Forum Management</strong></p>
Outline
51
52
<ul>
53
<li><a href = "addForum.asp">Add a Forum</a></li>
54
<li>Delete a Forum</li>
55
default.asp
(3 of 3)
</ul>
56
57
</body>
58
59 </html>
This anchor element links to the ASP document
addForum.asp that allows the user to create a
new forum.
 2004 Prentice Hall, Inc.
All rights reserved.
13
34.3 Forum Navigation
Fig. 34.4
Message forums main page.
 2004 Prentice Hall, Inc. All rights reserved.
14
34.3 Adding Forums
• Template forum
– Bare minimum elements of forum
– stylesheet tag for formatting
– forum tag
 2004 Prentice Hall, Inc. All rights reserved.
1
<?xml version = "1.0"?>
15
Outline
2
3
<!-- Fig. 34.5 : template.xml -->
4
<!-- Template XML document
-->
template.xml
5
6
<?xml:stylesheet type = "text/xsl" href = "formatting.xsl"?>
7
8
<forum>
9
</forum>
The stylesheet processing instruction
references formatting.xsl.
 2004 Prentice Hall, Inc.
All rights reserved.
16
34.3 Adding Forums
• Generating forum from template
– Form to get information on new forum
• Name and file name
• User name
• Message title and text
– Script to act on form input
• Confirm valid input
• SetAttribute
– filename
– timestamp
• CreateElement
• AppendChild
• Save
 2004 Prentice Hall, Inc. All rights reserved.
1
<% @LANGUAGE = "VBScript" %>
2
<% Option Explicit %>
17
Outline
3
4
<% ' Fig. 34.6 : addForum.asp %>Check
to see if a value was entered in
each of the form fields.
addForum.asp
Test to see if the form was submitted by testing
the form’s
(1 of 7)
submit field for a value.
5
6
<%
7
Dim xmlFile, xmlRoot, xmlNode
8
Dim strTitle, strError, strPath
9
10
If Request( "submit" ) <> Empty Then
11
12
If Request( "name" ) <> Empty And _
13
Request( "filename" ) <> Empty And _
14
Request( "user" ) <> Empty And _
15
Request( "title" ) <> Empty And _
16
Request( "text" ) <> Empty Then
17
18
' Create a new XML file
19
strPath = Server.MapPath( Request( "filename" ) )
20
21
Set xmlFile = Server.CreateObject( "Microsoft.XMLDOM" )
22
xmlFile.Async = False
23
 2004 Prentice Hall, Inc.
All rights reserved.
24
25
26
If xmlFile.Load( strPath ) Then
18
Call Server.Transfer( "invalid.html" )
Outline
End If
27
28
' set up the file
29
Call xmlFile.Load(
addForum.asp
Method Load loads the template XML document.
(2 of 7)
Server.MapPath( "template.xml" ) )
30
31
' get the root element
32
Set xmlRoot = xmlFile.DocumentElement
33
34
' set the filename
35
Call xmlRoot.SetAttribute( "filename", _
36
Request( "filename" ) )
37
38
' create Name node
39
Set xmlNode = xmlFile.CreateElement( "name" )
40
xmlNode.Text = Request( "name" )
41
Call
42
Method setAttribute creates an attribute node
named filename that has the value contained in
xmlRoot.AppendChild( xmlNode )
form field filename.
43
' create first message
44
Set xmlNode = xmlFile.CreateElement( "message" )
45
Call xmlNode.SetAttribute( "timestamp", Now & " EST" )
46
Call xmlRoot.AppendChild( xmlNode )
47
48
Set xmlRoot = xmlNode
Method AppendChild appends the newly created
element name node to the root element.
 2004 Prentice Hall, Inc.
All rights reserved.
49
19
50
' create user node
51
Set xmlNode = xmlFile.CreateElement( "user" )
52
xmlNode.Text = Request( "user" )
53
Call xmlRoot.AppendChild( xmlNode )
Outline
addForum.asp
(3 of 7)
54
55
' create title node
56
Set xmlNode = xmlFile.CreateElement( "title" )
57
xmlNode.Text = Request( "title" )
58
Call xmlRoot.AppendChild( xmlNode )
59
60
' create text node
61
Set xmlNode = xmlFile.CreateElement( "text" )
62
xmlNode.Text = Request( "text" )
63
Call xmlRoot.AppendChild( xmlNode )
Calling method Save saves the
XML document to disk.
64
65
Call xmlFile.Save( strPath ) ' save the file
66
67
' load XML file
68
strPath = Server.MapPath( "forums.xml" )
69
70
Set xmlFile = Server.CreateObject( "Microsoft.XMLDOM" )
71
xmlFile.Async = False
Open XML document forums.xml.
72
 2004 Prentice Hall, Inc.
All rights reserved.
73
If Not xmlFile.Load( strPath ) Then
75
20
Call Server.Transfer( "invalid.html" )
74
Outline
End If
76
77
' get the root node
78
Set xmlRoot = xmlFile.DocumentElement
addForum.asp
(4 of 7)
79
80
' create nodes
81
Set xmlNode = xmlFile.CreateElement( "forum" )
82
Call xmlNode.SetAttribute( "filename", _
Modify forums.xml.
Request( "filename" ) )
83
84
xmlNode.Text = Request( "name" )
85
Call xmlRoot.AppendChild( xmlNode )
86
87
Call xmlFile.Save( strPath ) ' save the file
88
89
' finished processing
90
Call Server.Transfer( "default.asp" )
91
92
93
Else
strError = "ERROR: Invalid input."
End If
94
95
Save forums.xml with its new contents to
disk.
End If
96 %>
97
 2004 Prentice Hall, Inc.
All rights reserved.
98 <!DOCTYPE html
21
99
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
100
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
Outline
101
102 <html xmlns = "http://www.w3.org/1999/xhtml">
103 <head>
104
<title>Add a Forum</title>
105
<link rel = "stylesheet" type = "text/css" href = "style.css" />
addForum.asp
(5 of 7)
This XHTML form allows a user to input the
name, filename, a user name, a message title and
the message text to create a new forum.
106 </head>
107
108 <body>
109
<p>Create a Forum</p>
110
<p><% =strError %></p>
111
112
<form method = "post" action = "addForum.asp">
113
114
<h2>
115
Forum Name:<br />
116
<input type = "text" size = "40" name = "name"
value = "<% =Request( "name" ) %>" />
117
118
</h2>
119
120
<h2>
121
Forum File Name:<br />
122
<input type = "text" size = "40" name = "filename"
123
value = "<% =Request( "filename" ) %>" />
 2004 Prentice Hall, Inc.
All rights reserved.
124
</h2>
22
Outline
125
126
<h2>
127
User:<br />
128
<input type = "text" size = "40" name = "user"
value = "<% =Request( "user" ) %>" />
129
130
addForum.asp
(6 of 7)
</h2>
131
132
<h2>
133
Message Title:<br />
134
<input type = "text" size = "40" name = "title"
value = "<% =Request( "title" ) %>" />
135
136
</h2>
137
138
<h2>
139
Message Text:<br />
140
<textarea name = "text" cols = "40"
rows = "4"><% =Request( "text" ) %></textarea>
141
142
</h2>
143
 2004 Prentice Hall, Inc.
All rights reserved.
144
<h2>
145
<input type = "submit" name = "submit" value = "Submit" />
146
<input type = "reset" value = "Clear" />
147
</form>
150
151
152
153
Outline
</h2>
148
149
23
addForum.asp
The Submit button submits the form and the (7 of 7)
values input in the form fields.
<p>
ThetoClear
will
<a href = "default.asp">Return
Main button
Page</a>
</p>
delete all values in the form
fields.
154
155 </body>
156
157 </html>
 2004 Prentice Hall, Inc.
All rights reserved.
24
34.3 Adding Forums
Fig. 34.6
Page to add a forum.
 2004 Prentice Hall, Inc. All rights reserved.
25
34.5 Forum XML Documents
• Sample forum
– XML modified with several forums added
– XSLT used to transform XML
– Final XHTML page served to Internet Explorer
 2004 Prentice Hall, Inc. All rights reserved.
1
<?xml version = "1.0"?>
26
Outline
2
3
<!-- Fig. 34.7 : forumASP.xml -->
4
<!-- Postings on ASP forum
-->
5
6
name
of the forum.
<?xml:stylesheetThe
type
= "text/xsl"
href = "formatting.xsl"?>
forumASP.xml
(1 of 2)
7
8
<forum filename = "forumASP.xml">
Each message element and its children contain
the information for a post.
9
10
<name>ASP Forum</name>
11
12
<message timestamp = "4/28/2001 2:50:34 PM EST">
13
<user>D. Bug</user>
14
<title>I Love ASP!</title>
15
<text>Everyone should use ASP.</text>
16
</message>
17
 2004 Prentice Hall, Inc.
All rights reserved.
18
<message timestamp = "5/8/2001 11:09:54 AM EST">
19
<user>Ms. Quito</user>
20
<title>ASP and XML</title>
21
<text>What a powerful combination. Try it!</text>
22
</message>
23
24
Outline
forumASP.xml
(2 of 2)
<message timestamp = "5/15/2001 4:39:50 PM EST">
25
<user>Sarge Ant</user>
26
<title>ASP</title>
27
<text>This <em>army ant</em> uses ASP in boot camp.</text>
28
27
</message>
29
30 </forum>
 2004 Prentice Hall, Inc.
All rights reserved.
1
<?xml version = "1.0"?>
28
Outline
2
3
4
5
6
7
8
9
10
11
12
Attribute
version specifies
theXSLT
XSLT version to
<!-- Fig. 34.8 : formatting.xsl
Element
xsl:stylesheet
is -->
the
which thisXML
style
sheet
conforms.
<!-- XSL document thatdocument’s
transforms
data
to XHTML
-->
root
element.
Attribute omit-xmlformatting.xsl
The
xsl:output
element
specifies
how
the
result
declaration
is assigned no,
(1 of 4)
<xsl:stylesheet
version = "1.0"
tree
is
output.
which
results
in
an
XML
Attribute
method
is
assigned
html
,
which
specifies
that
xmlns:xsl = "http://www.w3.org/1999/XSL/Transform">
declaration in the an
result
tree. document is being output.
XHTML
<xsl:output method = "html" omit-xml-declaration = "no"
doctype-system =
doctype-public =
13
14
Select the template that matches the XML document root
(/). 1.0 Strict//EN" />
"-//W3C//DTD XHTML
The asterisk
selects element nodes.
The attribute
xmlns creates a namespace
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"
<xsl:template match = "/">
prefix xsl.
15
16
17
18
<html xmlns = "http://www.w3.org/1999/xhtml">
<xsl:apply-templates select = "*" />
</html>
19
20
</xsl:template>
21
22
<xsl:template match = "forum">
23
 2004 Prentice Hall, Inc.
All rights reserved.
24
<head>
29
25
<title><xsl:value-of select = "name"/></title>
26
<link rel = "stylesheet" type = "text/css"
27
28
href = "style.css" />
Link to the CSS style sheet style.css.
formatting.xsl
(2 of 4)
</head>
29
30
Outline
<body>
31
32
<table width = "100%" cellspacing = "0"
33
cellpadding = "2">
34
<tr>
35
<td class = "forumTitle">
<xsl:value-of select = "name" />
36
37
</td>
38
</tr>
39
</table>
Get value of name element.
40
41
<table width = "100%" cellspacing = "0"
42
cellpadding = "2">
43
<xsl:apply-templates
44
45
46
select = "message" />
</table>
Apply message template.
 2004 Prentice Hall, Inc.
All rights reserved.
47
48
<p>
30
<a>
Outline
<xsl:attribute
49
name = "href">addPost.asp?file=<xsl:value-of
50
52
</xsl:attribute>
53
Post a Message</a><br />
54
55
formatting.xsl
(3 of 4)
select = "@filename" />
51
Get the value of attribute filename.
<a href = "default.asp">Return to Main Page</a>
</p>
56
57
</body>
Begin template message.
58
59
</xsl:template>
60
61
<xsl:template match = "message">
62
63
64
<tr>
<td class = "msgTitle">
<xsl:value-of select = "title" />
65
66
67
</td>
</tr>
68
69
70
<tr>
Get value of user element.
<td class = "msgInfo">
71
by
72
<em><xsl:value-of select = "user" /></em>
 2004 Prentice Hall, Inc.
All rights reserved.
73
at
74
<span class = "date">
</span>
76
78
Outline
<xsl:value-of select = "@timestamp" />
75
77
31
</td>
</tr>
formatting.xsl
Get value of attribute timestamp
.
(4 of 4)
79
80
81
<tr>
<td class = "msgText">
<xsl:value-of select = "text" />
82
83
84
</td>
</tr>
85
Get value of text element.
86
87
</xsl:template>
88
89 </xsl:stylesheet>
 2004 Prentice Hall, Inc.
All rights reserved.
1
2
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
32
Outline
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
3
4
<!-- Fig. 34.9 : forumASP_transformed.html -->
5
<!-- Results of transforming forumASP.xml
forumASP_transformed
.html
-->
6
7
(1 of 3)
<html xmlns = "http://www.w3.org/1999/xhtml">
8
9
<head>
10
<title>ASP Forum</title>
11
<link href = "site.css" type = "text/css" rel = "stylesheet"
Forum/>
title.
12
</head>
13
14
15
16
17
<body>
<table cellpadding = "2" cellspacing = "0" width = "100%">
<tr>
<td class = "forumTitle">ASP Forum</td>
18
</tr>
19
</table>
Message title.
20
21
22
23
24
<table cellpadding = "2" cellspacing = "0" width = "100%">
<tr>
<td class = "msgTitle">I Love ASP!</td>
</tr>
 2004 Prentice Hall, Inc.
All rights reserved.
25
26
<tr>
33
<td class = "msgInfo">
27
by
28
<em>D. Bug</em>
29
at
31
</tr>
32
<tr>
</tr>
35
<tr>
(2 of 3)
<td class = "msgTitle">ASP and XML</td>
37
</tr>
38
<tr>
39
<td class = "msgInfo">
40
by
41
<em>Ms. Quito</em>
42
at
44
</tr>
45
<tr>
<td class = "msgText">
What a powerful combination. Try it!</td>
47
48
Message text.
Message author.
<span class = "date">5/8/2001 11:09:54 AM EST</span></td>
43
46
forumASP_transformed
.html
<td class = "msgText">Everyone should use ASP.</td>
34
36
Time and date posted.
<span class = "date">4/28/2001 2:50:34 PM EST</span></td>
30
33
Outline
</tr>
 2004 Prentice Hall, Inc.
All rights reserved.
<tr>
49
34
<td class = "msgTitle">ASP</td>
50
51
</tr>
52
<tr>
Outline
54
by
forumASP_transformed
.html
55
<em>Sarge Ant</em>
(3 of 3)
56
at
<td class = "msgInfo">
53
<span class = "date">5/15/2001 4:39:50 PM EST</span></td>
57
58
</tr>
59
<tr>
<td class = "msgText">
60
This army ant uses ASP in boot camp.</td>
61
62
</tr>
63
</table>
64
65
<p>
66
<a href = "addPost.asp?file=forumASP.xml">Post a Message</a>
67
<br>
68
<a href = "default.asp">Return to Main Page</a>
69
</p>
70
71
</body>
Link to add a new post.
72
73 </html>
 2004 Prentice Hall, Inc.
All rights reserved.
35
34.5 Forum XML Documents
Fig. 34.9
Output of the transformation of the forum XML document.
 2004 Prentice Hall, Inc. All rights reserved.
36
34.6 Posting Messages
• Posting a message
– Procedure similar to creating new forum
 2004 Prentice Hall, Inc. All rights reserved.
1
<% @LANGUAGE = "VBScript" %>
37
Outline
2
3
4
<% ' Fig. 34.10 : addPost.asp
' ASP document for posting a message
5
6
7
Option
Check to see if a value was entered in
each
of the form
fields. the form’s
submitted
by testing
ExplicitTest to see if the form was
submit field for a value.
8
Dim xmlFile, xmlRoot, xmlNode
9
Dim strTitle, strError, strPath
addPost.asp
(1 of 5)
10
11
If Request( "submit" ) <> Empty Then
12
13
If Request( "file" ) <> Empty And _
14
Load
Request( "userName" ) <>Method
Empty And
_
15
Request( "messageTitle" ) <> Empty And _
16
Request( "messageText" ) <> Empty Then
loads the forum XML document.
17
18
strPath = Server.MapPath( Request( "file" ) )
19
20
Set xmlFile = Server.CreateObject( "Microsoft.XMLDOM" )
21
xmlFile.Async = False
22
23
24
25
If Not xmlFile.Load( strPath ) Then
Call Server.Transfer( "invalid.html" )
End If
 2004 Prentice Hall, Inc.
All rights reserved.
26
38
27
' get the root node
28
Set xmlRoot = xmlFile.DocumentElement
Outline
29
30
' create first message
31
Set xmlNode = xmlFile.CreateElement( "message" )
32
Call xmlNode.SetAttribute( "timestamp", Now & " EST" )
33
Call xmlRoot.AppendChild( xmlNode )
34
35
Set xmlRoot = xmlNode
addPost.asp
Create a message
(2 ofnode.
5)
Create a timeStamp attribute for the
message node.
36
37
' create user node
38
Call CreateElementNode( "user", "userName", xmlNode )
39
40
' create title node
41
Call CreateElementNode( "title", "messageTitle", xmlNode )
42
43
' create text node
44
Call CreateElementNode( "text", "messageText", xmlNode )
45
46
Call xmlFile.Save( strPath ) ' save the file
47
48
' finished processing
49
Call Server.Transfer( Request( "file" ) )
Create the children of the message
node: user, title and text.
 2004 Prentice Hall, Inc.
All rights reserved.
Else
50
39
strError = "ERROR: Invalid input."
51
Outline
End If
52
53
addPost.asp
(3 of 5)
End If
54
55
56
' procedure that creates an element node
57
Sub CreateElementNode( elementName, formElement, node )
58
Set xmlNode = xmlFile.CreateElement( elementName )
59
xmlNode.Text = Request( formElement )
60
Call xmlRoot.AppendChild( node )
End Sub
61
62 %>
63
64 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
65
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
66
67 <html xmlns = "http://www.w3.org/1999/xhtml">
68
<head>
69
<title>Post a Message</title>
70
<link rel = "stylesheet" type = "text/css"
href = "style.css" />
71
72
</head>
73
 2004 Prentice Hall, Inc.
All rights reserved.
74
75
<body>
40
<p><% =strError %></p>
Outline
76
77
78
<form method = "post" action = This
"addPost.asp">
form allows
the user to create a post by
entering the values into the form fields.
<p>
79
User:<br />
80
<input type = "text" size = "40" name = "userName"
value = "<% =Request( "userName" ) %>" />
81
82
addPost.asp
(4 of 5)
</p>
83
84
<p>
85
Message Title:<br />
86
<input type = "text" size = "40" name = "messageTitle"
value = "<% =Request( "messageTitle" ) %>" />
87
88
</p>
89
90
<p>
91
Message Text:<br />
92
<textarea name = "messageText" cols = "40"
rows = "4"><% =Request( "messageText" ) %>
93
94
95
</textarea>
</p>
96
 2004 Prentice Hall, Inc.
All rights reserved.
<p>
97
<input type = "hidden" name = "file"
98
value = "<% =Request( "file" ) %>"/>
99
100
<input type = "submit" name = "submit" value = "Submit" />
101
<input type = "reset" value = "Clear" />
102
</p>
103
</form>
41
Outline
addPost.asp
(5 of 5)
104
105
<p>
<a href = "<% =Request( "file" ) %>">Return to Forum</a>
106
107
</p>
108
</body>
109
110 </html>
 2004 Prentice Hall, Inc.
All rights reserved.
42
34.6 Posting Messages
Fig. 34.10
Adding a message to a forum.
 2004 Prentice Hall, Inc. All rights reserved.
43
34.6 Posting Messages
Fig. 34.11
New forum on the message board.
 2004 Prentice Hall, Inc. All rights reserved.
44
34.6 Posting Messages
Fig. 34.12
Initial content of the newly added forum.
 2004 Prentice Hall, Inc. All rights reserved.
45
34.6 Posting Messages
Fig. 34.13 Contents of the Internet and World Wide Web: Third Edition forum.
 2004 Prentice Hall, Inc. All rights reserved.
46
34.7 Other Documents
• Other documents required by forum
– Error page
– CSS for formatting
• XHTML
• Forums
 2004 Prentice Hall, Inc. All rights reserved.
1
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
2
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
47
Outline
3
4
<!-- Fig. 34.14 : invalid.html
-->
5
<!-- XHTML document for displaying errors -->
6
7
<html xmlns = "http://www.w3.org/1999/xhtml">
Link that references CSS style sheet site.css.
8
9
<head>
10
<title>Deitel Book Organization</title>
11
<link rel = "stylesheet" type = "text/css"
href = "site.css" />
12
13
invalid.html
(1 of 1)
</head>
14
15
16
<body>
<h1>Invalid Request.</h1>
17
18
19
<p><a href = "default.asp">Return to Main Page</a></p>
</body>
20
21 </html>
 2004 Prentice Hall, Inc.
All rights reserved.
1
/* Fig. 34.15 : site.css
*/
2
/* Stylesheet for XHTML documents */
48
Outline
3
4
body
5
{
Define styles for the body element.
6
background: white;
7
color: black;
8
font-family: Arial, sans-serif;
9
font-size: 10pt;
site.css
(1 of 3)
10 }
11
12 a
Define styles for the anchor element.
13 {
14
background: transparent;
15
color: blue;
16
text-decoration: none;
17 }
18
19 a:hover
Define styles for the table element.
20 {
21
text-decoration: underline;
22 }
23
 2004 Prentice Hall, Inc.
All rights reserved.
24 table
25 {
49
Outline
26
border-width: 1px;
27
border-style: solid;
site.css
(2 of 3)
28 }
29
30 .forumTitle
31 {
32
background: lime;
33
color: black;
34
font-size: 12pt;
35
font-weight: bold;
36
text-align: center;
37 }
38
39 .msgTitle
40 {
41
background: silver;
42
color: black;
43
font-size: 10pt;
44
font-weight: bold;
45 }
46
 2004 Prentice Hall, Inc.
All rights reserved.
47 .msgInfo
48 {
50
Outline
49
background: silver;
50
color: black;
51
font-size: 10pt;
52 }
site.css
(3 of 3)
53
54 .msgPost
55 {
56
background: silver;
57
color: black;
58
font-size: 8pt;
59 }
60
61 .msgText
62 {
63
font-size: 10pt;
64
padding-left: 10px;
65 }
66
67 .date
68 {
69
font-size: 8pt;
70 }
 2004 Prentice Hall, Inc.
All rights reserved.
1
/* Fig. 34.16 : style.css */
2
/* Stylesheet for forums
51
Outline
*/
3
4
h1
5
{
Define styles for the h1 element.
6
color: #330099;
7
letter-spacing: 2px;
8
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
9
style.css
(1 of 5)
background-color: transparent;
10 }
11
12 h2
Define styles for the h2 element.
13 {
14
color: #6633FF;
15
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
16
font-size: small;
17
background-color: transparent;
18 }
19
20 p
Define styles for the p element.
21 {
22
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
23
color: #336666;
24
letter-spacing: 1px;
25
font-size: larger;
 2004 Prentice Hall, Inc.
All rights reserved.
font-weight: bold;
26
27
52
background-color: transparent;
Outline
28 }
29
30 body
Define styles for the body element.
31 {
32
background-image: url(bug2.gif);
33
background-repeat: no-repeat;
34
margin-top: 5%;
35
background-position: 25%;
36
margin-left: 10%;
style.css
(2 of 5)
37 }
38
39 li
Define styles for the li element.
40 {
41
font-family: "Courier New", Courier, monospace;
42
font-weight: bolder;
43
list-style-type: circle;
44
color: #3333FF;
45
background-color: transparent;
46 }
47
 2004 Prentice Hall, Inc.
All rights reserved.
48 input
53
49 {
Outline
Define styles for the input element.
50
background-color: transparent;
51
color: #336666;
52
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
53 }
style.css
(3 of 5)
54
55 textarea
Define styles for the textarea element.
56 {
57
background-color: transparent;
58
color: #336666;
59
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
60 }
61
62 .forumTitle
63 {
64
65
color: #FFFFCC;
font-size: 14pt;
66
font-family: Verdana, Geneva, Arial, Helvetica, sans-serif;
67
text-align: center;
68
background-color: #6666CC;
69 }
70
 2004 Prentice Hall, Inc.
All rights reserved.
71 .msgTitle
72 {
54
Outline
73
background: #FFFFCC;
74
color: black;
75
font-size: 10pt;
76
font-weight: bold;
style.css
(4 of 5)
77 }
78
79 .msgInfo
80 {
81
background: #FFFFCC;
82
color: black;
83
font-size: 10pt;
84 }
85
86 .msgPost
87 {
88
background: silver;
89
color: black;
90
font-size: 8pt;
91 }
92
 2004 Prentice Hall, Inc.
All rights reserved.
93 .msgText
94 {
95
font-size: 10pt;
96
padding-left: 10px;
55
Outline
style.css
(5 of 5)
97 }
98
99 .date
100 {
101
font-size: 8pt;
102 }
 2004 Prentice Hall, Inc.
All rights reserved.