#LyX 1.6.7 created this file. For more info see http://www.lyx.org/
\lyxformat 345
\begin_document
\begin_header
\textclass scrbook
\begin_preamble
\input{preamble.tex}
\end_preamble
\options twoside,pointlessnumbers,obeyspaces,utf8
\use_default_options true
\language english
\inputencoding utf8
\font_roman lmodern
\font_sans helvet
\font_typewriter courier
\font_default_family default
\font_sc false
\font_osf false
\font_sf_scale 100
\font_tt_scale 100
\graphics default
\float_placement H
\paperfontsize default
\spacing single
\use_hyperref true
\pdf_bookmarks true
\pdf_bookmarksnumbered false
\pdf_bookmarksopen false
\pdf_bookmarksopenlevel 1
\pdf_breaklinks false
\pdf_pdfborder false
\pdf_colorlinks false
\pdf_backref false
\pdf_pdfusetitle true
\papersize letterpaper
\use_geometry false
\use_amsmath 2
\use_esint 1
\cite_engine basic
\use_bibtopic false
\paperorientation portrait
\secnumdepth 2
\tocdepth 2
\paragraph_separation indent
\defskip medskip
\quotes_language english
\papercolumns 1
\papersides 2
\paperpagestyle default
\bullet 0 5 11 -1
\bullet 1 5 24 -1
\bullet 2 0 0 -1
\tracking_changes false
\output_changes false
\author ""
\author ""
\end_header
\begin_body
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
input{chapter.tex}
\end_layout
\end_inset
\end_layout
\begin_layout Chapter
JasperReports and PHP -- Windows
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
epigraph{Testing shows the presence, not the absence of bugs.}{Edsger Wybe
Dijkstra}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This chapter describes how to integrate
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
with PHP and Apache's HTTP Server.
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Integration-Windows-HTTP-PHP"
\end_inset
shows the major components involved in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
integration with PHP in Windows.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename drawings/integration-http-php.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Integration-Windows-HTTP-PHP"
\end_inset
Integration - Apache HTTP Server and PHP (Windows)
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
The components are as follows:
\end_layout
\begin_layout Itemize
\series bold
Browser.
\series default
Any web browser.
\end_layout
\begin_layout Itemize
\series bold
Web Server.
\series default
Apache's web server software that responds to web page requests.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\series default
A web page containing a form and a button.
The user clicks the button to retrieve the report.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpreport}
\end_layout
\end_inset
.
\series default
A web page that runs a report and returns a PDF directly to the browser.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\series default
Provides PHP with the ability to execute Java code.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
Classes.
\series default
Passes parameters to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
using the report API.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
.
\series default
The reporting engine used to query the database and generate a PDF.
\end_layout
\begin_layout Itemize
\series bold
Database.
\series default
Any database that has a JDBC driver.
\end_layout
\begin_layout Standard
The system works as follows:
\end_layout
\begin_layout Enumerate
The web browser sends a request to the web server (Apache) for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
The web server returns the HTML for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
, which includes a form with a button.
\end_layout
\begin_layout Enumerate
The user clicks the button.
\end_layout
\begin_layout Enumerate
The web server passes
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpreport}
\end_layout
\end_inset
to the PHP interpreter.
\end_layout
\begin_layout Enumerate
The PHP interpreter opens a connection to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
creates an instance of the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
engine.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
engine runs a report.
\end_layout
\begin_layout Enumerate
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
returns the results of running the report to the PHP interpreter.
\end_layout
\begin_layout Enumerate
The PHP interpreter sends the PDF directly to the web browser.
\end_layout
\begin_layout Enumerate
The web browser displays (or saves) the PDF.
\end_layout
\begin_layout Standard
Consider integrating
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
with PHP only if no other choices are possible.
Given a choice, use
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appapachetomcat{}
\end_layout
\end_inset
, instead;
\emph on
only
\emph default
\shape italic
\emph on
install the
\shape default
\emph default
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
\shape italic
\emph on
if PHP is an
\emph default
absolute requirement
\emph on
.
\end_layout
\begin_layout Standard
In this chapter:
\end_layout
\begin_layout Itemize
\series bold
Prerequisites.
\series default
Software packages required to complete the integration.
\end_layout
\begin_layout Itemize
\series bold
Apache's HTTP Server.
\series default
Brief installation guide and validation.
\end_layout
\begin_layout Itemize
\series bold
PHP.
\series default
Installation guide with instructions specifically for Apache's HTTP Server.
\end_layout
\begin_layout Itemize
\series bold
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\series default
Installation instructions with an example integration.
\end_layout
\begin_layout Section
Prerequisites
\end_layout
\begin_layout Standard
The following software packages must be installed and functional:
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
iReport Directory
\end_layout
\begin_layout Standard
When installing
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
, change the default destination folder, as shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:iReport-Destination-Folder"
\end_inset
.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/ireport-setup.png
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:iReport-Destination-Folder"
\end_inset
Destination Folder
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Install
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
in a directory that does not contain spaces, as some software misinterprets
spaces in directory names.
A directory name containing spaces (for example,
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogramfiles
\end_layout
\end_inset
) is the source of many software bugs.
Double quotes can help, but that adds complexity and requires manual interventi
on, so use directory names without spaces to avoid the problem altogether.
(Both
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
and
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
handle spaces in names correctly, but install them to the location shown
in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:iReport-Destination-Folder"
\end_inset
anyway, to avoid having to qualify paths with double quotes.)
\end_layout
\begin_layout Section
Apache's HTTP Server
\end_layout
\begin_layout Standard
This section shows how Apache was configured to complete the integration.
\end_layout
\begin_layout Subsection
Installation
\end_layout
\begin_layout Standard
To install Apache's HTTP server:
\end_layout
\begin_layout Enumerate
Configure the server as shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Apache-Setup-Server-Configuration"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/apache-setup-01.png
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Apache-Setup-Server-Configuration"
\end_inset
Apache Setup Server Configuration
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Click
\series bold
Change
\series default
to set the default destination folder, as shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:Apache-Setup-Installation-Directory"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/apache-setup-02.png
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:Apache-Setup-Installation-Directory"
\end_inset
Apache Setup Installation Directory
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Accept the
\series bold
Installation Wizard
\series default
's defaults for the remaining panels.
\end_layout
\begin_layout Standard
Apache's HTTP Server is installed.
\end_layout
\begin_layout Subsection
Validation
\end_layout
\begin_layout Standard
Browse to the following address to verify that Apache is installed and running:
\end_layout
\begin_layout Standard
\begin_inset CommandInset href
LatexCommand href
name "http://localhost"
target "http://localhost"
\end_inset
\end_layout
\begin_layout Standard
The following text appears:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
It works!
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Section
PHP
\end_layout
\begin_layout Standard
This section shows how to configure PHP to complete the integration.
\end_layout
\begin_layout Subsection
Installation
\end_layout
\begin_layout Standard
The installation of PHP requires a bit more configuration than
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
or
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
.
Note that the binary Microsoft Installer (MSI) does not work as expected
(that is, it does not actually change the Apache's configuration settings
to use the PHP module).
\end_layout
\begin_layout Standard
Extract the zip archive into the following directory:
\end_layout
\begin_layout LyX-Code
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogphp
\end_layout
\end_inset
\end_layout
\begin_layout Subsection
Configuration
\end_layout
\begin_layout Standard
To configure the installation to work with Apache:
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpconf
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Add the following lines (use forward slashes, not backslashes):
\end_layout
\begin_deeper
\begin_layout LyX-Code
\size footnotesize
PHPIniDir "c:/programs/php/"
\end_layout
\begin_layout LyX-Code
\size footnotesize
LoadModule php5_module "c:/programs/php/php5apache2_2.dll"
\end_layout
\begin_layout LyX-Code
\size footnotesize
AddType application/x-httpd-php .php
\end_layout
\end_deeper
\begin_layout Enumerate
Save the file.
\end_layout
\begin_layout Subsection
Validation
\end_layout
\begin_layout Standard
To verify that PHP and Apache are communicating, perform the following steps:
\end_layout
\begin_layout Enumerate
Restart Apache (do not use the Apache Monitor).
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocs
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Change the contents of
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocs
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
to
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:PHP-Test-Windows"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float algorithm
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename source/php/index-test.php.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "alg:PHP-Test-Windows"
\end_inset
PHP Test
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/index.php"
\end_inset
.
\end_layout
\begin_layout Standard
The following text appears:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
PHP works!
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
If not, view the contents of Apache's error log (see
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Windows-Applications-Logs"
\end_inset
), correct the errors, and try again.
\end_layout
\begin_layout Section
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This section describes how to install and configure the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
Before installation can proceed, download the files for the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
that are listed in
\begin_inset CommandInset ref
LatexCommand vref
reference "tab:Windows-Applications-Versions"
\end_inset
.
\end_layout
\begin_layout Subsection
Installation
\end_layout
\begin_layout Standard
To install the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
:
\end_layout
\begin_layout Enumerate
Create the following directory:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocsjava
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Copy
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileincjava}
\end_layout
\end_inset
into
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocsjava
\end_layout
\end_inset
\family default
.
\end_layout
\begin_layout Enumerate
Create the following directory:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogbridge
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Copy
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejarbridge}
\end_layout
\end_inset
into
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogbridge
\end_layout
\end_inset
\family default
.
\end_layout
\begin_layout Subsection
Execution
\end_layout
\begin_layout Standard
To run the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
:
\end_layout
\begin_layout Enumerate
Click
\series bold
Start
\series default
\series bold
» Run
\series default
.
\end_layout
\begin_layout Enumerate
Type:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
cmd
\end_layout
\end_deeper
\begin_layout Enumerate
Type the following commands to run the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
:
\end_layout
\begin_deeper
\begin_layout LyX-Code
cd
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogbridge
\end_layout
\end_inset
\end_layout
\begin_layout LyX-Code
\family typewriter
java -jar
\family default
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejarbridge}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
If a
\series bold
Windows Security Alert
\series default
dialog appears, click
\series bold
Unblock
\series default
.
\end_layout
\begin_layout Enumerate
Click
\series bold
OK
\series default
to run the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
on port 8080, as shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PHP/Java-Bridge-Start"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/bridge-run.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:PHP/Java-Bridge-Start"
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
Start
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
is waiting for requests on port 8080.
\end_layout
\begin_layout Subsection
Validation
\end_layout
\begin_layout Standard
The following describes how to call
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
code from PHP.
This allows you to determine if the installation to this point is successful.
At this point, the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
is not configured to use
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
, which is expected.
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocs
\backslash
filename{
\backslash
filephpdemo}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Change the contents to reflect
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:Java-and-PHP"
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephpdemo"
\end_inset
).
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float algorithm
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename source/php/index.php.png
display false
\end_inset
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "alg:Java-and-PHP"
\end_inset
Java and PHP
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Browse to the following location:
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/index.php"
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
The current date and time appear, showing that
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
was called successfully from PHP:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
shortdayofweekname{
\backslash
day}{
\backslash
month}{
\backslash
year}
\backslash
shortmonthname{}
\backslash
twodigit{
\backslash
day}
\backslash
currenttime{}:05 EST
\backslash
number
\backslash
year{}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
If the date and time does not appear, view Apache's error logs to diagnose
the problem.
\end_layout
\begin_layout Subsection
Integration
\end_layout
\begin_layout Standard
The following describes how to configure the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
, to run
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
.
The batch file provides
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
with the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
libraries location.
\end_layout
\begin_layout Enumerate
Optionally, uninstall QuickTime (to remove QuickTime for
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
), if it is currently installed.
\end_layout
\begin_layout Enumerate
Create a new file called
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filebatchbridge}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filebatchbridge"
\end_inset
).
\end_layout
\begin_layout Enumerate
Move the file to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogbridge
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Switch to the command window running the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Type
\series bold
CTRL-c
\series default
to stop the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Type the following (see
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PHP/Java-Bridge-Batch-File-Start"
\end_inset
):
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filebatchbridge
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/bridge-batch.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:PHP/Java-Bridge-Batch-File-Start"
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
Batch File Start
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/index.php"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
Verify that the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
is functioning correctly.
\end_layout
\end_deeper
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
can now use the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
application class files.
The next part of the configuration describes how to create reports:
\end_layout
\begin_layout Enumerate
Create a new folder for reports:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirdevreports
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Start
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Create a new
\series bold
Blank A4
\series default
report.
\end_layout
\begin_layout Enumerate
Use the settings shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:New-Report-Location"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/ireport-new-report.png
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:New-Report-Location"
\end_inset
New Report Location
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Click
\series bold
Next
\series default
.
\end_layout
\begin_layout Enumerate
Click
\series bold
Finish
\series default
.
\end_layout
\begin_layout Enumerate
Add
\series bold
Static Text
\series default
to the
\series bold
Title
\series default
band.
\end_layout
\begin_layout Enumerate
Change the
\series bold
Static Text
\series default
to
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
- Test Report
\family default
.
\end_layout
\begin_layout Enumerate
Click
\series bold
Preview
\series default
to compile and view the report.
\end_layout
\begin_layout Standard
The directory
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirdevreports
\end_layout
\end_inset
\family default
contains the following files:
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejrxmltest}
\end_layout
\end_inset
-- The report design.
\end_layout
\begin_layout Itemize
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejaspertest}
\end_layout
\end_inset
-- The compiled version of the report.
\end_layout
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
engine needs only the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileextjasper}
\end_layout
\end_inset
file to produce a PDF file.
\end_layout
\begin_layout Subsection
PDF Creation
\end_layout
\begin_layout Standard
To generate a PDF file from the browser:
\end_layout
\begin_layout Enumerate
Create a file named
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephppdf}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filephppdf"
\end_inset
).
\end_layout
\begin_layout Enumerate
Copy
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephppdf}
\end_layout
\end_inset
into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocs
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/test.php"
\end_inset
.
\end_layout
\begin_layout Standard
A single-page PDF file appears with the following text:
\end_layout
\begin_layout Standard
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
begin{displayed}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
- Test Report
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
end{displayed}
\end_layout
\end_inset
\end_layout
\begin_layout Standard
If the PDF file does not appear, view the error logs to diagnose the problem.
\end_layout
\begin_layout Standard
The algorithm to create a basic report is as follows:
\end_layout
\begin_layout Enumerate
Determine the path to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
fileextjasper}
\end_layout
\end_inset
report file.
\end_layout
\begin_layout Enumerate
Create a map that contains key-value parameters (it can be empty, but not
null).
\end_layout
\begin_layout Enumerate
Create a data source used to populate the content (in this example, an empty
source is used, but the most common data source will be a JDBC connection).
\end_layout
\begin_layout Enumerate
Create a handle to the class that has static methods for filling out the
report.
\end_layout
\begin_layout Enumerate
Fill out the report.
\end_layout
\begin_layout Enumerate
Write the PDF file to the browser.
\end_layout
\begin_layout Standard
Note that the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
interface defines two similar functions in
\begin_inset CommandInset ref
LatexCommand ref
reference "tab:Java-Bridge-Methods"
\end_inset
.
\begin_inset Foot
status collapsed
\begin_layout Plain Layout
A procedure is a sequence of steps that can be called by name.
A function is a procedure that returns a value.
A method is a procedure or function declared as part of a class, but must
be called using a valid class instance (that is, an object).
A static method is a method that can be called without a class instance.
\end_layout
\end_inset
\end_layout
\begin_layout Standard
\begin_inset Float table
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "tab:Java-Bridge-Methods"
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
Method Interfaces
\end_layout
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Tabular
<lyxtabular version="3" rows="3" columns="2">
<features>
<column alignment="left" valignment="top" width="0">
<column alignment="left" valignment="top" width="0">
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
rowcolor{tableheader}
\backslash
toprule{}
\end_layout
\end_inset
\series bold
Function Name
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\series bold
Description
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
midrule{}
\end_layout
\end_inset
\family typewriter
Java( ...
)
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Create a new class instance.
\end_layout
\end_inset
</cell>
</row>
<row>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
\family typewriter
JavaClass( ...
)
\end_layout
\end_inset
</cell>
<cell alignment="left" valignment="top" usebox="none">
\begin_inset Text
\begin_layout Plain Layout
Create a class reference for calling static methods.
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
tabularnewline
\backslash
bottomrule%
\end_layout
\end_inset
\end_layout
\end_inset
</cell>
</row>
</lyxtabular>
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Generally, objects that can receive method calls are created using the first
function.
Static methods are called on classes referenced using the second method.
Inadvertently passing variables assigned to the results of a
\family typewriter
JavaClass
\family default
function call will likely cause an
\family typewriter
IllegalArgumentException
\family default
.
\end_layout
\begin_layout Standard
If the logs show a
\family typewriter
ClassNotFoundException
\family default
, double check that
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filebatchbridge}
\end_layout
\end_inset
contains no typing errors or other mistakes.
Notice that using
\family typewriter
-Djava.ext.dirs
\family default
requires no changes to the CLASSPATH (neither the environment variable
nor the
\family typewriter
-classpath
\family default
command line option are necessary).
\end_layout
\begin_layout Subsection
Connection
\end_layout
\begin_layout Standard
Database connections are established using the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
Database Connectivity (JDBC) API.
All major database vendors provide a JDBC driver.
This section describes how to use the JDBC driver with the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
to fill out a report using data from a database.
For the purposes of this example, the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
database driver is used.
\end_layout
\begin_layout Standard
The easiest way to download and install the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
JDBC driver is as follows:
\end_layout
\begin_layout Enumerate
Run the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
Stack Builder tool.
\end_layout
\begin_layout Enumerate
Select the pgJDBC driver (
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PostgreSQL-JDBC-Driver"
\end_inset
).
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status open
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/pgJDBC.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:PostgreSQL-JDBC-Driver"
\end_inset
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
JDBC Driver
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Install the database driver into the default directory:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogramfiles{}
\end_layout
\end_inset
PostgreSQL
\backslash
pgJDBC
\end_layout
\end_deeper
\begin_layout Enumerate
Accept the
\series bold
Installation Wizard
\series default
's defaults for the remaining panels.
\end_layout
\begin_layout Enumerate
Copy the JDBC driver into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogireport
\backslash
path{ide10
\backslash
modules
\backslash
ext
\backslash
}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Move or delete the existing JDBC driver.
\end_layout
\begin_layout Enumerate
Update the
\series bold
Classpath
\series default
in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
(
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PHP/Java-Bridge-Configure-iReport-Classpath"
\end_inset
).
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/ireport-setup-classpath.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:PHP/Java-Bridge-Configure-iReport-Classpath"
\end_inset
Configure
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
Classpath
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
The
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
JDBC driver can be installed anywhere.
Installing it in
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appireport{}
\end_layout
\end_inset
's
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjava{}
\end_layout
\end_inset
library directory, however, does not require modifications to the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filebatchbridge}
\end_layout
\end_inset
batch file.
\end_layout
\begin_layout Standard
The remainder of this section describes how to retrieve report data.
\end_layout
\begin_layout Enumerate
Stop
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filebatchbridge}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Run
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filebatchbridge}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Run
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filesqlclimate}
\end_layout
\end_inset
against the database (see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filesqlclimate"
\end_inset
).
\end_layout
\begin_layout Enumerate
If using
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
apppostgres{}
\end_layout
\end_inset
8.4 or greater, run
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filesqlcasts}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filesqlcasts"
\end_inset
).
\end_layout
\begin_layout Enumerate
Create a new report,
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filejrxmlcity}
\end_layout
\end_inset
, that queries the database for a list of cities (see
\begin_inset CommandInset ref
LatexCommand vref
reference "sub:\\filejrxmlcity"
\end_inset
).
\end_layout
\begin_layout Enumerate
Preview the report to see
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PHP/Java-Bridge-City-Report"
\end_inset
.
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/report-city.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:PHP/Java-Bridge-City-Report"
\end_inset
Report - Cities
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Standard
If the report does not correctly show the accented character in Abord â
Plouffe, check that the database encoding is set to UTF-8.
If required, edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filesqlclimate}
\end_layout
\end_inset
using an editor that supports UTF-8 encodings.
Lastly, do not copy and paste the text from
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filesqlclimate}
\end_layout
\end_inset
; rather, execute it by loading (or otherwise running) the file contents
directly.
\end_layout
\begin_layout Enumerate
Copy the following files into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocs{}
\end_layout
\end_inset
(see
\begin_inset CommandInset ref
LatexCommand vref
reference "sec:PHP-Source-Files"
\end_inset
):
\end_layout
\begin_deeper
\begin_layout Enumerate
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpcity}
\end_layout
\end_inset
\end_layout
\begin_layout Enumerate
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpconstants}
\end_layout
\end_inset
\end_layout
\begin_layout Enumerate
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpconstants}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Change any values necessary (such as
\family typewriter
$DBPASS
\family default
).
\end_layout
\begin_layout Enumerate
Save
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpconstants}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/city.php"
\end_inset
.
\end_layout
\begin_layout Standard
The report shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PHP/Java-Bridge-City-Report"
\end_inset
is a PDF file downloaded through a web browser.
\end_layout
\begin_layout Standard
If the report does not appear, check the error logs.
If there are no obvious errors shown in the logs, try the following:
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Remove the pound symbol (
\family typewriter
#
\family default
) from the first two lines.
\end_layout
\begin_layout Enumerate
Reload the report page:
\end_layout
\begin_deeper
\begin_layout Standard
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/city.php"
\end_inset
\end_layout
\end_deeper
\begin_layout Enumerate
Resolve any errors.
\end_layout
\begin_layout Standard
Remember to comment out the first two lines you removed the pound symbol
from when the errors have been resolved (to avoid exposing information
that hackers could use to compromise the system).
\end_layout
\begin_layout Subsection
Interaction
\end_layout
\begin_layout Standard
A report lacking the ability to filter results is only partially useful.
The steps to parse parameters set by the user and pass them into the report
comprise this part of the
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appphpjavabridge{}
\end_layout
\end_inset
integration documentation.
Specifically, this section describes:
\end_layout
\begin_layout Itemize
A naming scheme for HTML form variables.
\end_layout
\begin_layout Itemize
How to pass array values into a report.
\end_layout
\begin_layout Standard
A naming scheme is used to automatically force form inputs into appropriate
data types before being passed to
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
appjasperreports{}
\end_layout
\end_inset
.
The key is using a variable name prefix that signifies how the variable
is used.
Additionally, the prefix can include the data type.
Some examples are shown in
\begin_inset CommandInset ref
LatexCommand ref
reference "alg:Example-Report-Input-Fields"
\end_inset
.
\end_layout
\begin_layout Standard
\begin_inset Float algorithm
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename source/html/report-inputs.html.png
\end_inset
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "alg:Example-Report-Input-Fields"
\end_inset
Example Report Input Fields
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
In the example, city report (
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpcity}
\end_layout
\end_inset
), the query was implemented so that results are returned when no parameters
are provided.
This was accomplished by giving default values to parameters.
The city name, for example, is given a default value of the empty string,
as opposed to leaving it blank (which would be a
\family typewriter
null
\family default
value).
A
\family typewriter
null
\family default
city value translates to a condition that matches no database data:
\end_layout
\begin_layout LyX-Code
\family typewriter
c.name_lowercase LIKE
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
%
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
|| null ||
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
%
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
\end_layout
\begin_layout Standard
Whereas, an empty string city value translates to the following condition:
\end_layout
\begin_layout LyX-Code
\family typewriter
c.name_lowercase LIKE
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
%
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
||
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\backslash
textquotesingle
\end_layout
\end_inset
||
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
%
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle
\end_layout
\end_inset
\end_layout
\begin_layout Standard
The latter condition matches all city names, which is the desired behaviour.
\end_layout
\begin_layout Standard
To create a web page that passes parameters into the report:
\end_layout
\begin_layout Enumerate
Copy
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filehtmlfilter}
\end_layout
\end_inset
into
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
windirprogapachehttpdocs
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Edit
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
filename{
\backslash
filephpjasper}
\end_layout
\end_inset
.
\end_layout
\begin_layout Enumerate
Remove the comment mark (
\family typewriter
#
\family default
) from the following lines:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
#include_once
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
params.php
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
;
\end_layout
\begin_layout LyX-Code
\family typewriter
#$params = report_parse_params();
\end_layout
\end_deeper
\begin_layout Enumerate
Add a comment mark (
\family typewriter
#
\family default
) to the beginning of the following line:
\end_layout
\begin_deeper
\begin_layout LyX-Code
\family typewriter
$params = new Java(
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
java.util.HashMap
\begin_inset ERT
status collapsed
\begin_layout Plain Layout
\backslash
textquotesingle{}
\end_layout
\end_inset
);
\end_layout
\end_deeper
\begin_layout Enumerate
Save the file.
\end_layout
\begin_layout Enumerate
Browse to
\begin_inset CommandInset href
LatexCommand href
target "http://localhost/filter.html"
\end_inset
.
\end_layout
\begin_layout Enumerate
Click
\series bold
Report
\series default
to the report without parameters.
The result appears as in
\begin_inset CommandInset ref
LatexCommand vref
reference "fig:PHP/Java-Bridge-City-Report"
\end_inset
.
\end_layout
\begin_layout Enumerate
Set
\series bold
City Name
\series default
to
\series bold
ab
\series default
.
\end_layout
\begin_layout Enumerate
Set
\series bold
Min Latitude
\series default
to
\series bold
4200
\series default
.
\end_layout
\begin_layout Enumerate
Set
\series bold
Max Latitude
\series default
to
\series bold
5000
\series default
.
\end_layout
\begin_layout Enumerate
Set
\series bold
Regions
\series default
to
\series bold
2, 10
\series default
.
\end_layout
\begin_layout Enumerate
Click
\series bold
Report
\series default
.
\end_layout
\begin_layout Standard
The final report appears as in
\begin_inset CommandInset ref
LatexCommand ref
reference "fig:PHP/Java-Bridge-Filtered-Report"
\end_inset
.
\end_layout
\begin_layout Standard
\begin_inset Float figure
wide false
sideways false
status collapsed
\begin_layout Plain Layout
\begin_inset Graphics
filename captures/report-filter.png
display false
\end_inset
\end_layout
\begin_layout Plain Layout
\begin_inset Caption
\begin_layout Plain Layout
\begin_inset CommandInset label
LatexCommand label
name "fig:PHP/Java-Bridge-Filtered-Report"
\end_inset
Report - Filtered Cities
\end_layout
\end_inset
\end_layout
\end_inset
\end_layout
\begin_layout Standard
This report shows cities (with a lower case name) that start with
\series bold
ab
\series default
, are at a latitude between
\series bold
4200
\series default
and
\series bold
5000
\series default
, and are in either region
\series bold
2
\series default
or
\series bold
10
\series default
.
\end_layout
\begin_layout Section
Summary
\end_layout
\begin_layout Standard
Apache's HTTP Server is a brilliant example of what the open software movement
has achieved.
Having been scoured and improved by scores of exceptionally bright developers,
the result is the world's most widely used, robust, configurable, reliable,
and secure web server software applications.
The premise of this chapter, indeed of Part II, is that building software
on top of open source applications can only improve the quality of systems.
\end_layout
\end_body
\end_document