Description of task
A remote client must receive an information about getting a work and employee layoff dates
for a company's staff by HTTP-connection.
For that we have a need to write a server application in JSP. Selection criteria are date after an employee acceptance,
date before employee discharged, post of an employee and all combinations of these conditions.
Also we must have possibility to assign date interval by using one of categories:
Current month, Previous month, Current quarter, Previous quarter, Current year, Previous year, None.
Date format is "MMM DD, YYYY" where MMM are first three letters of month, DD are two digits of number,
YYYY are four digits of year. For example, "Jan 15, 2007". Category None indicate that we use
diapason of dates (start and end dates). Also we must have possibility to use category "all" in field
post of an employee.
Realization
Look at process of creating JSP-page in detail. Let's use server Tomcat 4.1 and database MS Access due to simple installation and connecting.
In real I recommend to use database MySQL.
Database will have two linked tables. First table contains list of posts. Names of all employees
with dates of getting work and dismissal are stored in second table.
Step 1. We create database and input test data. Create and run trial query.
Step 2. Create ODBC-source for this database and name it as Access2.
Step 3. Write and debug a console application in Java. This application receives strings with selection
criteria and returns a string with query. Test an obtained query in database.
Step 4. Use environment JBuilder 2006. Create new project for server Tomcat 4.1, new Web-module and new JSP.
During creating JSP set checkboxes for generation sample bean, generation submit form, using
libraries JSTL 1.0 CORE and SQL, creating a runtime configuration. Set property "Build Web archive"
into value "When building project or module".
Step 5. Open a file with bean. Add a properties connected afterwards with fields on JSP-page.
Step 6. Add a pieces of Java code from console application to bean.
Step 7. Delete garbage from JSP-page. Create title.
Step 8. Add fields for start date, end date and date category to JSP-page. Run/test JSP-page from JBuilder 2006.
Step 9. Add tag for outputting string with query. Run, input data and press button Submit.
Step 10. Add JSP tags for connecting to database. Add field for selection of post.
Values for selection of post will be stored in database. Run JSP, input data and press button Submit.
Step 11. Add tags for outputting content of query. Run JSP, input data and press button Submit.
Step 12. Change code so that input and selection fields remember previous values. Test it.
Step 13. Put content of query into table with borders. Add elements of representation
at top and bottom of page, set green background. Test it.
Step 14. Copy WAR-file of Web-module from JBuilder 2006's project subdirectory into server Tomcat 4.1's subdirecory. Run Tomcat and test it.
|
Step 1. We create database and input test data. Create and run trial query.
|
Step 2. Create ODBC-source for this database and name it as Access2.
|
Step 3. Write and debug a console application in Java. This application receives strings with selection
criteria and returns a string with query. Test an obtained query in database.
Screen of console application
Text of console application
package pr_11;
import java.io.*;
import java.util.Calendar;
public class Untitled1 {
private String query0 = "select * from Tabl2 where Id<0";
private static int kk = 0;
private static String Aux_st_start = "";
private static String Aux_st_end = "";
private static String Aux_time_period = "";
private static String Cr_Month(int zz) {
String mm = "";
if (zz==0) mm="Jan";
if (zz==1) mm="Feb";
if (zz==2) mm="Mar";
if (zz==3) mm="Apr";
if (zz==4) mm="May";
if (zz==5) mm="Jun";
if (zz==6) mm="Jul";
if (zz==7) mm="Aug";
if (zz==8) mm="Sep";
if (zz==9) mm="Oct";
if (zz==10) mm="Nov";
if (zz==11) mm="Dec";
return mm;
}
private static void HandleTimePeriod() {
if (Aux_time_period.compareTo("previous qrt")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
if (zz>2) {
zz = zz - 3;
}
else {
yy = yy-1; zz = zz - 3 + 12;
}
int qrt_First = (((zz / 3) * 3) + 1) - 1;
int qrt_Last = (((zz / 3) * 3) + 3) - 1;
String mm_First = Cr_Month(qrt_First);
String mm_Last = Cr_Month(qrt_Last);
cal.set(cal.MONTH, qrt_Last);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
Aux_st_start = mm_First + " 1, " + yy;
Aux_st_end = mm_Last + " "+ tt + ", " + yy;
}
if (Aux_time_period.compareTo("previous month")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
if (zz==0) {
zz=11; yy=yy-1;
}
else zz=zz-1;
cal.set(cal.YEAR, yy);
cal.set(cal.MONTH, zz);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
String mm = Cr_Month(zz);
Aux_st_start = mm + " 1, " + yy;
Aux_st_end = mm + " "+ tt + ", " + yy;
}
if (Aux_time_period.compareTo("previous year")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(1)-1;
Aux_st_start = "Jan 1, " + yy;
Aux_st_end = "Dec 31, " + yy;
}
if (Aux_time_period.compareTo("current year")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(1);
Aux_st_start = "Jan 1, " + yy;
Aux_st_end = "Dec 31, " + yy;
}
if (Aux_time_period.compareTo("current qrt")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
int qrt_First = (((zz / 3) * 3) + 1) - 1;
int qrt_Last = (((zz / 3) * 3) + 3) - 1;
String mm_First = Cr_Month(qrt_First);
String mm_Last = Cr_Month(qrt_Last);
cal.set(cal.MONTH, qrt_Last);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
Aux_st_start = mm_First + " 1, " + yy;
Aux_st_end = mm_Last + " "+ tt + ", " + yy;
}
if (Aux_time_period.compareTo("current month")==0) {
java.util.Calendar cal = java.util.Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
String mm = Cr_Month(zz);
Aux_st_start = mm + " 1, " + yy;
Aux_st_end = mm + " "+ tt + ", " + yy;
}
}
public static String getQuery0() throws UnsupportedEncodingException, IOException {
String que0 = "";
BufferedReader br = new BufferedReader(
new InputStreamReader(System.in, "Cp866"));
System.out.print("Введите начальную дату: ");
String XXvar_start_date = br.readLine();;
System.out.print("Введите конечную дату: ");
String XXvar_end_date = br.readLine();;
System.out.print("Введите категорию временного
периода: ");
String XXvar_time_period = br.readLine();
System.out.print("Введите должность: ");
String XXvar_Doljnost = br.readLine();
if (XXvar_start_date == null) {
XXvar_start_date = "";
}
if (XXvar_end_date == null) {
XXvar_end_date = "";
}
if (XXvar_Doljnost == null) {
XXvar_Doljnost = "";
}
if (XXvar_time_period == null) {
XXvar_time_period = "";
}
if (XXvar_Doljnost.compareTo("")==0) {
XXvar_Doljnost = "all";
}
if (!(XXvar_time_period.compareTo("none")==0)) {
XXvar_start_date = "";
XXvar_end_date = "";
}
if (!(XXvar_time_period.compareTo("none")==0)) {
Aux_time_period = XXvar_time_period;
HandleTimePeriod();
XXvar_start_date = Aux_st_start;
XXvar_end_date = Aux_st_end;
}
boolean Pr_Yes = (((!(XXvar_start_date.compareTo("")==0))) |
(!(XXvar_end_date.compareTo("")==0)) | (!(XXvar_Doljnost.compareTo("All
Doljnosts")==0)));
boolean Pr_Start = (!(XXvar_start_date.compareTo("")==0));
boolean Pr_End = (!(XXvar_end_date.compareTo("")==0));
boolean Pr_Doljnost = (!(XXvar_Doljnost.compareTo("all")==0));
String st = "SELECT doljnost, FIO, StartDate, EndDate FROM tabl_doljnost INNER JOIN
personal ON tabl_doljnost.Id=personal.ref_doljnost";
if (Pr_Yes) st = st + " where";
if (Pr_Start) {
st = st + " (StartDate>=#"+XXvar_start_date+"#)";
}
if ((Pr_End | Pr_Doljnost) & Pr_Start) st = st + "and";
if (Pr_End) {
st = st + " (EndDate<=#"+XXvar_end_date+"#)";
}
if (Pr_Doljnost & Pr_End) st = st + "and";
if (Pr_Doljnost) {
st = st + " (Doljnost = '" + XXvar_Doljnost + "')";
}
que0 = st;
return que0;
}
public static void main(String [] Args) throws Exception {
System.out.print(getQuery0());
}
}
|
Step 4. Use environment JBuilder 2006. Create new project for server Tomcat 4.1, new Web-module and new JSP.
During creating JSP set checkboxes for generation sample bean, generation submit form, using
libraries JSTL 1.0 CORE and SQL, creating a runtime configuration. Set property "Build Web archive"
into value "When building project or module".
|
Step 5. Open a file with bean. Add a properties connected afterwards with fields on JSP-page.
Result are the following files.
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
index
</title>
</head>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<body bgcolor="#ffffff">
<h1>
JBuilder Generated JSP
</h1>
<form method="post" action="index.jsp">
<br>Enter new value : <input name="sample"><br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br>
Value of Bean property is :<jsp:getProperty name="indexBeanId"
property="sample" />
</form>
</body>
</html>
File IndexBean.java
package pr_11;
public class IndexBean {
private String query0 = "SELECT doljnost, FIO, StartDate, EndDate FROM tabl_doljnost
INNER JOIN personal ON tabl_doljnost.Id=personal.ref_doljnost";
private String var_start_date = "";
private String var_end_date = "";
private String var_time_period = "";
private String var_doljnost = "all";
public void setVar_start_date(String newValue) {
var_start_date = newValue;
}
public void setVar_end_date(String newValue) {
var_end_date = newValue;
}
public void setVar_time_period(String newValue) {
var_time_period = newValue;
}
public void setVar_perfomer(String newValue) {
var_doljnost = newValue;
}
public String getVar_start_date() {
return var_start_date ;
}
public String getVar_end_date() {
return var_end_date;
}
public String getVar_time_period() {
return var_time_period;
}
public String getVar_perfomer() {
return var_doljnost;
}
}
|
Step 6. Add a pieces of Java code from console application to bean.
Delete keyword static everywhere.
File IndexBean.java
package pr_11;
import java.util.Calendar;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.io.UnsupportedEncodingException;
import java.io.IOException;
public class IndexBean {
private String query0 = "SELECT doljnost, FIO, StartDate, EndDate FROM tabl_doljnost
INNER JOIN personal ON tabl_doljnost.Id=personal.ref_doljnost";
private String var_start_date = "";
private String var_end_date = "";
private String var_time_period = "";
private String var_doljnost = "";
private int kk = 0;
private String Aux_st_start = "";
private String Aux_st_end = "";
private String Aux_time_period = "";
private String Cr_Month(int zz) {
String mm = "";
if (zz==0) mm="Jan";
if (zz==1) mm="Feb";
if (zz==2) mm="Mar";
if (zz==3) mm="Apr";
if (zz==4) mm="May";
if (zz==5) mm="Jun";
if (zz==6) mm="Jul";
if (zz==7) mm="Aug";
if (zz==8) mm="Sep";
if (zz==9) mm="Oct";
if (zz==10) mm="Nov";
if (zz==11) mm="Dec";
return mm;
}
private void HandleTimePeriod() {
if (Aux_time_period.compareTo("previous qrt")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
if (zz>2) {
zz = zz - 3;
}
else {
yy = yy-1; zz = zz - 3 + 12;
}
int qrt_First = (((zz / 3) * 3) + 1) - 1;
int qrt_Last = (((zz / 3) * 3) + 3) - 1;
String mm_First = Cr_Month(qrt_First);
String mm_Last = Cr_Month(qrt_Last);
cal.set(cal.MONTH, qrt_Last);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
Aux_st_start = mm_First + " 1, " + yy;
Aux_st_end = mm_Last + " "+ tt + ", " + yy;
}
if (Aux_time_period.compareTo("previous month")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
if (zz==0) {
zz=11; yy=yy-1;
}
else zz=zz-1;
cal.set(cal.YEAR, yy);
cal.set(cal.MONTH, zz);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
String mm = Cr_Month(zz);
Aux_st_start = mm + " 1, " + yy;
Aux_st_end = mm + " "+ tt + ", " + yy;
}
if (Aux_time_period.compareTo("previous year")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(1)-1;
Aux_st_start = "Jan 1, " + yy;
Aux_st_end = "Dec 31, " + yy;
}
if (Aux_time_period.compareTo("current year")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(1);
Aux_st_start = "Jan 1, " + yy;
Aux_st_end = "Dec 31, " + yy;
}
if (Aux_time_period.compareTo("current qrt")==0) {
Calendar cal = Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
int qrt_First = (((zz / 3) * 3) + 1) - 1;
int qrt_Last = (((zz / 3) * 3) + 3) - 1;
String mm_First = Cr_Month(qrt_First);
String mm_Last = Cr_Month(qrt_Last);
cal.set(cal.MONTH, qrt_Last);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
Aux_st_start = mm_First + " 1, " + yy;
Aux_st_end = mm_Last + " "+ tt + ", " + yy;
}
if (Aux_time_period.compareTo("current month")==0) {
java.util.Calendar cal = java.util.Calendar.getInstance();
int yy = cal.get(cal.YEAR);
int zz = cal.get(cal.MONTH);
int tt = cal.getActualMaximum(cal.DAY_OF_MONTH);
String mm = Cr_Month(zz);
Aux_st_start = mm + " 1, " + yy;
Aux_st_end = mm + " "+ tt + ", " + yy;
}
}
public void setVar_start_date(String newValue) {
var_start_date = newValue;
}
public void setVar_end_date(String newValue) {
var_end_date = newValue;
}
public void setVar_time_period(String newValue) {
var_time_period = newValue;
}
public void setVar_doljnost(String newValue) {
var_doljnost = newValue;
}
public String getVar_start_date() {
return var_start_date ;
}
public String getVar_end_date() {
return var_end_date;
}
public String getVar_time_period() {
return var_time_period;
}
public String getVar_doljnost() {
return var_doljnost;
}
public String getQuery0() throws UnsupportedEncodingException, IOException {
String que0 = "";
String XXvar_start_date = getVar_start_date();
String XXvar_end_date = getVar_end_date();
String XXvar_Doljnost = getVar_doljnost();
String XXvar_time_period = getVar_time_period();
if (XXvar_start_date == null) {
XXvar_start_date = "";
}
if (XXvar_end_date == null) {
XXvar_end_date = "";
}
if (XXvar_Doljnost == null) {
XXvar_Doljnost = "";
}
if (XXvar_time_period == null) {
XXvar_time_period = "";
}
if (XXvar_Doljnost.compareTo("")==0) {
XXvar_Doljnost = "all";
}
if (!(XXvar_time_period.compareTo("none")==0)) {
XXvar_start_date = "";
XXvar_end_date = "";
}
if (!(XXvar_time_period.compareTo("none")==0)) {
Aux_time_period = XXvar_time_period;
HandleTimePeriod();
XXvar_start_date = Aux_st_start;
XXvar_end_date = Aux_st_end;
}
boolean Pr_Yes = (((!(XXvar_start_date.compareTo("")==0))) |
(!(XXvar_end_date.compareTo("")==0)) |
(!(XXvar_Doljnost.compareTo("all")==0)));
boolean Pr_Start = (!(XXvar_start_date.compareTo("")==0));
boolean Pr_End = (!(XXvar_end_date.compareTo("")==0));
boolean Pr_Doljnost = (!(XXvar_Doljnost.compareTo("all")==0));
String st = "SELECT doljnost, FIO, StartDate, EndDate FROM tabl_doljnost INNER JOIN
personal ON tabl_doljnost.Id=personal.ref_doljnost";
if (Pr_Yes) st = st + " where";
if (Pr_Start) {
st = st + " (StartDate>=#"+XXvar_start_date+"#)";
}
if ((Pr_End | Pr_Doljnost) & Pr_Start) st = st + "and";
if (Pr_End) {
st = st + " (EndDate<=#"+XXvar_end_date+"#)";
}
if (Pr_Doljnost & Pr_End) st = st + "and";
if (Pr_Doljnost) {
st = st + " (Doljnost = '" + XXvar_Doljnost + "')";
}
que0 = st;
return que0;
}
}
|
Step 7. Delete garbage from JSP-page. Create title.
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<body bgcolor="#ffffff">
<form method="post" action="index.jsp">
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
|
Step 8. Add fields for start date, end date and date category to JSP-page.
(Names of bean's properties and names of JSP fields
<input> and <select> must be the same). Run/test JSP-page from JBuilder 2006.
New HTML tags:
<select>...</select>
<option>...</option>
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<body bgcolor="#ffffff">
<form method="post" action="index.jsp">
Введите начальную дату: <input name='var_start_date'><br>
Введите конечную дату: <input name='var_end_date'><br>
Выберите категорию временного периода: <select
name="var_time_period" size='1'>
<option>none</option>
<option>current month</option>
<option>previous month</option>
<option>current qrt</option>
<option>previous qrt</option>
<option>current year</option>
<option>previous year</option>
</select>
<br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
</form>
</body>
</html>
|
Step 9. Add tag for outputting string with query. Run, input data and press button Submit.
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<body bgcolor="#ffffff">
<form method="post" action="index.jsp">
Введите начальную дату: <input name='var_start_date'><br>
Введите конечную дату: <input name='var_end_date'><br>
Выберите категорию временного периода: <select
name="var_time_period" size='1'>
<option>none</option>
<option>current month</option>
<option>previous month</option>
<option>current qrt</option>
<option>previous qrt</option>
<option>current year</option>
<option>previous year</option>
</select>
<br>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br><br>
<jsp:getProperty name="indexBeanId" property="query0" />
</form>
</body>
</html>
 |
|
Step 10. Add JSP tags for connecting to database. Add field for selection of post.
Values for selection of post will be stored in database. Run JSP, input data and press button Submit.
New JSTL:SQL tags
<sql:setDataSource .../>
<sql:query>...</sql:query>
Новые тэги JSTL:Core
<c:forEach...>
...
</c:forEach>
<c:out ...>
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<sql:setDataSource url="jdbc:odbc:Access2"
driver="sun.jdbc.odbc.JdbcOdbcDriver"/>
<sql:query var="query1">select * from tabl_doljnost</sql:query>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<body bgcolor="#ffffff">
<form method="post" action="index.jsp">
Введите начальную дату: <input name='var_start_date'><br>
Введите конечную дату: <input name='var_end_date'><br>
Выберите категорию временного периода: <select
name="var_time_period" size='1'>
<option>none</option>
<option>current month</option>
<option>previous month</option>
<option>current qrt</option>
<option>previous qrt</option>
<option>current year</option>
<option>previous year</option>
</select>
<br>
Выберите должность: <select name='var_doljnost' size='1'>
<option>all</option>
<c:forEach var="vv1" begin="0" items="${query1.rows}">
<option><c:out value="${vv1.doljnost}"/></option>
</c:forEach>
</select>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br><br>
<jsp:getProperty name="indexBeanId" property="query0" />
</form>
</body>
</html>
 |
|
Step 11. Add tags for outputting content of query. Run JSP, input data and press button Submit.
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<sql:setDataSource url="jdbc:odbc:Access2"
driver="sun.jdbc.odbc.JdbcOdbcDriver"/>
<sql:query var="query1">select * from tabl_doljnost</sql:query>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<sql:query var="query2"><jsp:getProperty name="indexBeanId"
property="query0" /></sql:query>
<body bgcolor="#ffffff">
<form method="post" action="index.jsp">
Введите начальную дату: <input name='var_start_date'><br>
Введите конечную дату: <input name='var_end_date'><br>
Выберите категорию временного периода: <select
name="var_time_period" size='1'>
<option>none</option>
<option>current month</option>
<option>previous month</option>
<option>current qrt</option>
<option>previous qrt</option>
<option>current year</option>
<option>previous year</option>
</select>
<br>
Выберите должность: <select name='var_doljnost' size='1'>
<option>all</option>
<c:forEach var="vv1" begin="0" items="${query1.rows}">
<option><c:out value="${vv1.doljnost}"/></option>
</c:forEach>
</select>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br><br>
<jsp:getProperty name="indexBeanId" property="query0" />
<br><br>
<c:forEach var="vv2" begin="0" items="${query2.rows}">
<c:out value="${vv2.doljnost}"/><c:out value=" "/>
<c:out value="${vv2.FIO}"/><c:out value=" "/>
<c:out value="${vv2.StartDate}"/><c:out value=" "/>
<c:out value="${vv2.EndDate}"/><c:out value=" "/>
<br>
</c:forEach>
</form>
</body>
</html>
 |
|
Step 12. Change code so that input and selection fields remember previous values. Test it.
New attribute of element option
(HTML)
selected
New JSTL:Core tags
<c:if ...>
...
</c:if>
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<sql:setDataSource url="jdbc:odbc:Access2"
driver="sun.jdbc.odbc.JdbcOdbcDriver"/>
<sql:query var="query1">select * from tabl_doljnost</sql:query>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<sql:query var="query2"><jsp:getProperty name="indexBeanId"
property="query0" /></sql:query>
<body bgcolor="#ffffff">
<form method="post" action="index.jsp">
Введите начальную дату: <input name='var_start_date'
value="<%=indexBeanId.getVar_start_date()%>"><br>
Введите конечную дату: <input name='var_end_date'
value="<%=indexBeanId.getVar_end_date()%>"><br>
<c:set var="var_core_2">
<jsp:getProperty name="indexBeanId" property="var_time_period"
/>
</c:set>
Выберите категорию временного периода: <select
name="var_time_period" size='1'>
<c:if test="${(var_core_2 == 'none')}" >
<option selected>none</option>
</c:if>
<c:if test="${!(var_core_2 == 'none')}" >
<option>none</option>
</c:if>
<c:if test="${(var_core_2 == 'current month')}" >
<option selected>current month</option>
</c:if>
<c:if test="${!(var_core_2 == 'current month')}" >
<option>current month</option>
</c:if>
<c:if test="${(var_core_2 == 'previous month')}" >
<option selected>previous month</option>
</c:if>
<c:if test="${!(var_core_2 == 'previous month')}" >
<option>previous month</option>
</c:if>
<c:if test="${(var_core_2 == 'current qrt')}" >
<option selected>current qrt</option>
</c:if>
<c:if test="${!(var_core_2 == 'current qrt')}" >
<option>current qrt</option>
</c:if>
<c:if test="${(var_core_2 == 'previous qrt')}" >
<option selected>previous qrt</option>
</c:if>
<c:if test="${!(var_core_2 == 'previous qrt')}" >
<option>previous qrt</option>
</c:if>
<c:if test="${(var_core_2 == 'current year')}" >
<option selected>current year</option>
</c:if>
<c:if test="${!(var_core_2 == 'current year')}" >
<option>current year</option>
</c:if>
<c:if test="${(var_core_2 == 'previous year')}" >
<option selected>previous year</option>
</c:if>
<c:if test="${!(var_core_2 == 'previous year')}" >
<option>previous year</option>
</c:if>
</select>
<br>
<c:set var="var_core_1">
<jsp:getProperty name="indexBeanId" property="var_doljnost" />
</c:set>
Выберите должность: <select name='var_doljnost' size='1'>
<c:if test="${vv1.doljnost == 'all'}" >
<option selected>all</option>
</c:if>
<c:if test="${!(vv1.doljnost == 'all')}" >
<option>all</option>
</c:if>
<c:forEach var="vv1" begin="0" items="${query1.rows}">
<c:if test="${vv1.doljnost == var_core_1}" >
<option selected><c:out value="${vv1.doljnost}"/></option>
</c:if>
<c:if test="${!(vv1.doljnost == var_core_1)}" >
<option><c:out value="${vv1.doljnost}"/></option>
</c:if>
</c:forEach>
</select>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<br><br>
<c:forEach var="vv2" begin="0" items="${query2.rows}">
<c:out value="${vv2.doljnost}"/><c:out value=" "/>
<c:out value="${vv2.FIO}"/><c:out value=" "/>
<c:out value="${vv2.StartDate}"/><c:out value=" "/>
<c:out value="${vv2.EndDate}"/><c:out value=" "/>
<br>
</c:forEach>
</form>
</body>
</html>
|
Step 13. Put content of query into table with borders. Add elements of representation
at top and bottom of page, set green background. Test it.
File Index.jsp
<%@ page contentType="text/html;
charset=windows-1251" %>
<%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
<%@ taglib uri="http://java.sun.com/jstl/sql" prefix="sql" %>
<html>
<head>
<title>
Создание реального приложения
</title>
</head>
<sql:setDataSource url="jdbc:odbc:Access2"
driver="sun.jdbc.odbc.JdbcOdbcDriver"/>
<sql:query var="query1">select * from tabl_doljnost</sql:query>
<jsp:useBean id="indexBeanId" scope="session"
class="pr_11.IndexBean" />
<jsp:setProperty name="indexBeanId" property="*" />
<sql:query var="query2"><jsp:getProperty name="indexBeanId"
property="query0" /></sql:query>
<body bgcolor="#00ff00">
<form method="post" action="index.jsp">
<table width="100%" border="0" cellpadding="0"
cellspacing="0">
<tr>
<td height="97" align="center" width="100%">
<b>Сборник задач по программированию. Новая
версия</b><br>
Александра Приходько
</td>
</tr>
</table>
Введите начальную дату: <input name='var_start_date'
value="<%=indexBeanId.getVar_start_date()%>"><br>
Введите конечную дату: <input name='var_end_date'
value="<%=indexBeanId.getVar_end_date()%>"><br>
<c:set var="var_core_2">
<jsp:getProperty name="indexBeanId" property="var_time_period"
/>
</c:set>
Выберите категорию временного периода: <select
name="var_time_period" size='1'>
<c:if test="${(var_core_2 == 'none')}" >
<option selected>none</option>
</c:if>
<c:if test="${!(var_core_2 == 'none')}" >
<option>none</option>
</c:if>
<c:if test="${(var_core_2 == 'current month')}" >
<option selected>current month</option>
</c:if>
<c:if test="${!(var_core_2 == 'current month')}" >
<option>current month</option>
</c:if>
<c:if test="${(var_core_2 == 'previous month')}" >
<option selected>previous month</option>
</c:if>
<c:if test="${!(var_core_2 == 'previous month')}" >
<option>previous month</option>
</c:if>
<c:if test="${(var_core_2 == 'current qrt')}" >
<option selected>current qrt</option>
</c:if>
<c:if test="${!(var_core_2 == 'current qrt')}" >
<option>current qrt</option>
</c:if>
<c:if test="${(var_core_2 == 'previous qrt')}" >
<option selected>previous qrt</option>
</c:if>
<c:if test="${!(var_core_2 == 'previous qrt')}" >
<option>previous qrt</option>
</c:if>
<c:if test="${(var_core_2 == 'current year')}" >
<option selected>current year</option>
</c:if>
<c:if test="${!(var_core_2 == 'current year')}" >
<option>current year</option>
</c:if>
<c:if test="${(var_core_2 == 'previous year')}" >
<option selected>previous year</option>
</c:if>
<c:if test="${!(var_core_2 == 'previous year')}" >
<option>previous year</option>
</c:if>
</select>
<br>
<c:set var="var_core_1">
<jsp:getProperty name="indexBeanId" property="var_doljnost" />
</c:set>
Выберите должность: <select name='var_doljnost' size='1'>
<c:if test="${vv1.doljnost == 'all'}" >
<option selected>all</option>
</c:if>
<c:if test="${!(vv1.doljnost == 'all')}" >
<option>all</option>
</c:if>
<c:forEach var="vv1" begin="0" items="${query1.rows}">
<c:if test="${vv1.doljnost == var_core_1}" >
<option selected><c:out value="${vv1.doljnost}"/></option>
</c:if>
<c:if test="${!(vv1.doljnost == var_core_1)}" >
<option><c:out value="${vv1.doljnost}"/></option>
</c:if>
</c:forEach>
</select>
<br><br>
<input type="submit" name="Submit" value="Submit">
<input type="reset" value="Reset">
<table border="1">
<tr>
<td>Должность</td>
<td>Ф.И.О.</td>
<td>Дата приема на работу</td>
<td>Дата увольнения</td>
</tr>
<c:forEach var="vv2" begin="0" items="${query2.rows}">
<tr>
<td><c:out value="${vv2.doljnost}"/></td>
<td><c:out value="${vv2.FIO}"/></td>
<td><c:out value="${vv2.StartDate}"/></td>
<td><c:out value="${vv2.EndDate}"/></td>
</tr>
<br>
</c:forEach>
</table>
<table>
<tr align="center">
<td height="33"><p align="center"><em><font
color="#000000"><small>© Приходько
Александр
Николаевич 1996 - 2006</small><big>
</font></em></td>
</tr>
</table>
</form>
</body>
</html>
|
|
Step 14. Copy WAR-file of Web-module from JBuilder 2006's project subdirectory into server Tomcat 4.1's subdirecory. Run Tomcat and test it.
From where /
To where
|