Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

webpage newbie 1

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
US
Greetings all! I am currently working on my first website and have some questions! One of my cow-orkers actually had a "mini" version of what I need, so I'm trying to modify that instead of starting from scratch.

So, the main page of the website lists a bunch of statutes that come from DB2 (iSeries) tables. I would like to add "filtering" to this main page so that the user can select just active statutes, or where the origin is the County or the State or what ever agency enforces the statute.

So, the first page is the index page:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<%
session.setAttribute("currentRecord","0");
session.setAttribute("message","");
String URL = "access.jsp";
	request.getRequestDispatcher(URL).forward(request,response);
%>
</body>
</html>

which opens the access.jsp page:
Code:
<?xml version="1.0" encoding="ISO-8859-1" ?>
<%@ page
import="java.sql.*,functions.*,java.util.ArrayList"
language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "[URL unfurl="true"]http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/URL]
<html xmlns="[URL unfurl="true"]http://www.w3.org/1999/xhtml">[/URL]
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
<title>Insert title here</title>
</head>
<body>
<%
String library = JDBCdefs.getLibrary();
ArrayList statuteList = new ArrayList();
String dataRow = "";
	
try
{
jdbcAccess datasource = new jdbcAccess();
datasource.connect();
Connection conn = datasource.getConnection();
		
Statement sqlstmt = conn.createStatement();	
String stmt = "SELECT E.STATUT, E.CHGABV, M.CHGDSC, E.CHGDSCL FROM " + library + "CMPSTAMFE E INNER JOIN " + library + "CMPSTAMF M ON E.STATUT = M.STATUT AND E.CHGABV " + 
"= M.CHGABV ORDER BY STATUT, CHGABV";
		
ResultSet statutes = sqlstmt.executeQuery(stmt);
		
while(statutes.next())
{
dataRow = statutes.getString("STATUT") + "%";
dataRow = dataRow + statutes.getString("CHGABV") + "%";
dataRow = dataRow + statutes.getString("CHGDSC") + "%";
dataRow = dataRow + statutes.getString("CHGDSCL") + "%";
statuteList.add(dataRow);
}
sqlstmt.close();
statutes.close();
conn.close();
		
} 
catch (SQLException sql)
{
System.out.println("statute Access - Sql Exception: " + sql.getMessage());
}
JDBCdefs.setStatutes(statuteList);
String URL = "listRows.jsp";
	request.getRequestDispatcher(URL).forward(request,response);
%>
</body>
</html>

which finally gets us to the main page:
Code:
<html>
<head>
<%@ page
import="java.util.ArrayList"
import="functions.*,java.util.StringTokenizer" 
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<title>NM Statute Maintenance List</title>
<link href="theme/Master.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
ArrayList statuteList = new ArrayList();
String dataRow = "";
String strIndex = (String) session.getAttribute("currentRecord");
int index = Integer.parseInt(strIndex);
statuteList = JDBCdefs.getStatutes();
String statute = "", abbrev = "", descrip = "", descripL = "";
%>
<div id="list">
<h1 align="center">Metropolitan Court<br>Statute  List</h1>
<h4 align="center">Select Statute to modify by clicking on the Row#.</h4>
<table border="1" width="100%" cellpadding="2" cellspacing="2">
<tr>
<td colspan='5'>Number of Items: <%= statuteList.size() %></td>
</tr>
<tr>
<td>Row#</td>
<td>Statute Id.</td>
<td>Abbrev.</td>
<td>Standard Description</td>
<td>Extended Description</td>
</tr>
			
<%
for (int i=0; i < statuteList.size(); i++)
{
dataRow = statuteList.get(i).toString();
StringTokenizer token = new StringTokenizer(dataRow,"%");
statute = token.nextToken();
abbrev = token.nextToken();
descrip = token.nextToken();
descripL = token.nextToken();
%>
<tr>
<td><a href="process.jsp?formtype=list&rowNbr=<%= i %>"><%= i %></a></td>
<td><%= statute.trim() %></td>
<td><%= abbrev.trim() %></td>
<td><%= descrip.trim() %></td>
<td><%= descripL.trim() %></td>
</tr>
<%
}
%>
</table>
</div>
</body>
</html>

So how do I from listRows.jsp add a radio button group:
[tt]o Active o Inactive o All[/tt]

and then recall the access.jsp with the correct criteria in the SQL?

Like I said, someone else has done most of this...I'd actually like it to default to just the Active statutes, and only show the Inactive only upon request when the radio button is selected and the page refreshed. Any pointers will be greatly appreciated!





Leslie

Have you met Hardy Heron?
 
There are some serious issues with this design. Most of the code in access.jsp should be refactored into a java class, and referenced from access.jsp. Of course, if you do that, you don't really need access.jsp. You could add a few lines to the main page.

Code:
Library l = new Library;
l.setStatus("active");
ArrayList statuteList = l.getStatuteList();

Library would contain something like

Code:
public Library(){}
private String status = "ALL";


public void setStatus(inStatus String){
status = inStatus;
}

public ArrayList getStatuteList(){

String library = JDBCdefs.getLibrary();
ArrayList statuteList = new ArrayList();
String dataRow = "";
    
try
{
jdbcAccess datasource = new jdbcAccess();
datasource.connect();
Connection conn = datasource.getConnection();
        
Statement sqlstmt = conn.createStatement();    
String stmt = "SELECT E.STATUT, E.CHGABV, M.CHGDSC, E.CHGDSCL FROM " + library + "CMPSTAMFE E INNER JOIN " + library + "CMPSTAMF M ON E.STATUT = M.STATUT AND E.CHGABV " +
"= M.CHGABV ";

if (!status.equalsIgnoreCase("all"))
stmt += " AND M.STATUS = '" + status +"' ";

stmt += " ORDER BY STATUT, CHGABV";
        
ResultSet statutes = sqlstmt.executeQuery(stmt);
        
while(statutes.next())
{
dataRow = statutes.getString("STATUT") + "%";
dataRow = dataRow + statutes.getString("CHGABV") + "%";
dataRow = dataRow + statutes.getString("CHGDSC") + "%";
dataRow = dataRow + statutes.getString("CHGDSCL") + "%";
statuteList.add(dataRow);
}
sqlstmt.close();
statutes.close();
conn.close();
        
}
catch (SQLException sql)
{
System.out.println("statute Access - Sql Exception: " + sql.getMessage());
}
return statuteList;
}


You don't really say how to tell if something is active or inactive, so I can't tell you how to adjust the creation of your query.

-----------------------------------------
I cannot be bought. Find leasing information at
 
I'm open to suggestions...like I said, someone else did most of this as his own personal application to modify data in one of the tables I'm using. Now we need to give users in the organization the ability to modify these tables and he just gave me his thrown together app as a base so I didn't have to start from scratch...and I'm much happier writing a java class than the web pages. In our other projects he does the front end and I do the back end, but I'm not real clear on how he takes what I've done and integrates it into the websites.

I'll work on this today and get back to you if I have any other questions (which I'm sure I will!). I'm pretty good with queries, so I think I'll be able to get that part myself.

Leslie
 
Ok, so I created my new class Library, but I can't figure out where to put the lines you provided in the listRows.jsp file....I also get an error on the setStatus:
"inStatus cannot be resolved to a type"

Thanks for any pointers!

Leslie
 
Sorry about that. I've spent too much time in PL/SQL lately.
That line should be
Code:
public void setStatus(String inStatus){
Assuming your radio group is named "status" and the new Library class is in your functions package, try something like this
Code:
<html>
<head>
<%@ page
import="java.util.ArrayList"
import="functions.*,java.util.StringTokenizer"
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<title>NM Statute Maintenance List</title>
<link href="theme/Master.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
Library l = new Library;
String status = (String)request.getParameter("status");
if (status != null && !status.equalsIgnorCase("")){
l.setStatus(status);
}
ArrayList statuteList = l.getStatuteList();
String dataRow = "";
String strIndex = (String) session.getAttribute("currentRecord");
int index = Integer.parseInt(strIndex);
String statute = "", abbrev = "", descrip = "", descripL = "";
%>
<div id="list">
<h1 align="center">Metropolitan Court<br>Statute  List</h1>
<h4 align="center">Select Statute to modify by clicking on the Row#.</h4>
<table border="1" width="100%" cellpadding="2" cellspacing="2">
<tr>
<td colspan='5'>Number of Items: <%= statuteList.size() %></td>
</tr>
<tr>
<td>Row#</td>
<td>Statute Id.</td>
<td>Abbrev.</td>
<td>Standard Description</td>
<td>Extended Description</td>
</tr>
            
<%
for (int i=0; i < statuteList.size(); i++)
{
dataRow = statuteList.get(i).toString();
StringTokenizer token = new StringTokenizer(dataRow,"%");
statute = token.nextToken();
abbrev = token.nextToken();
descrip = token.nextToken();
descripL = token.nextToken();
%>
<tr>
<td><a href="process.jsp?formtype=list&rowNbr=<%= i %>"><%= i %></a></td>
<td><%= statute.trim() %></td>
<td><%= abbrev.trim() %></td>
<td><%= descrip.trim() %></td>
<td><%= descripL.trim() %></td>
</tr>
<%
}
%>
</table>
</div>
</body>
</html>

-----------------------------------------
I cannot be bought. Find leasing information at
 
ok, I've added the radio buttons, but I'm not sure I've got a radio group....and there are a few other issues.

First, I'm working in Eclipse. When I add the Library.java to the functions package, the java file is fine, but the class has a red X on it, but I don't know why. There are no errors in the java file....

Second, I added the code where you suggested and I get an error: "Syntax error on token "new", delete this token"
When I delete the new I get:
"Library can not be resolved"

Here's what I've got in both files right now:
Code:
package functions;

import java.sql.*;
import java.util.ArrayList;


public class Library {

private String status = "ALL";


public void setStatus(String inStatus){
	status = inStatus;
}

public ArrayList getStatuteList(){

	String library = JDBCdefs.getLibrary();
	ArrayList statuteList = new ArrayList();
	String dataRow = "";

	try
	{
		jdbcAccess datasource = new jdbcAccess();
		datasource.connect();
		Connection conn = datasource.getConnection();

		Statement sqlstmt = conn.createStatement();    
		String stmt = "SELECT E.STATUT, E.CHGABV, M.CHGDSC, E.CHGDSCL FROM " + library + "CMPSTAMFE E INNER JOIN " + library + "CMPSTAMF M ON E.STATUT = M.STATUT AND E.CHGABV = M.CHGABV ";

		if (!status.equalsIgnoreCase("all"))
		stmt += " AND M.STATUS = '" + status +"' ";

		stmt += " ORDER BY STATUT, CHGABV";

		ResultSet statutes = sqlstmt.executeQuery(stmt);

	while(statutes.next())
	{
		dataRow = statutes.getString("STATUT") + "%";
		dataRow = dataRow + statutes.getString("CHGABV") + "%";
		dataRow = dataRow + statutes.getString("CHGDSC") + "%";
		dataRow = dataRow + statutes.getString("CHGDSCL") + "%";
		statuteList.add(dataRow);
	}
	sqlstmt.close();
	statutes.close();
	conn.close();

}
catch (SQLException sql)
{
	System.out.println("statute Access - Sql Exception: " + sql.getMessage());
}
return statuteList;
}

}

and
Code:
<html>
<head>
<%@ page
import="java.util.ArrayList"
import="functions.*,java.util.StringTokenizer" 
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<title>NM Statute Maintenance List</title>
<link href="theme/Master.css" rel="stylesheet" type="text/css" />
</head>
<body>
<%
[b][COLOR=red]Library l = new Library;[/color][/b]
String status = (String)request.getParameter("status");
if (status != null && !status.equalsIgnoreCase("")){
	l.setStatus(status);
}
ArrayList statuteList = new ArrayList();
String dataRow = "";
String strIndex = (String) session.getAttribute("currentRecord");
int index = Integer.parseInt(strIndex);
statuteList = JDBCdefs.getStatutes();
String statute = "", abbrev = "", descrip = "", descripL = "";
%>
<div id="list">
<h1 align="center">Metropolitan Court<br>Statute  List</h1>
<h4 align="center">Select Statute to modify by clicking on the Row#.</h4>
<table border="1" width="100%" cellpadding="2" cellspacing="2"><tr>
<td colspan='3'>Number of Items: <%= statuteList.size() %></td>
[b]<td colspan='2'>Filter By: <input name="Status" type="radio" value="A" checked> Active
<input name="Status" type="radio" value="I"> Inactive 
<input name="Status" type="radio" value="All"> All</td>[/b]
</tr>
<tr>
<td>Row#</td>
<td>Statute Id.</td>
<td>Abbrev.</td>
<td>Standard Description</td>
<td>Extended Description</td>
</tr>
			
<%
for (int i=0; i < statuteList.size(); i++)
{
	dataRow = statuteList.get(i).toString();
	StringTokenizer token = new StringTokenizer(dataRow,"%");
	statute = token.nextToken();
	abbrev = token.nextToken();
	descrip = token.nextToken();
	descripL = token.nextToken();
%>
<tr>
<td><a href="process.jsp?formtype=list&rowNbr=<%= i %>"><%= i %></a></td>
<td><%= statute.trim() %></td>
<td><%= abbrev.trim() %></td>
<td><%= descrip.trim() %></td>
<td><%= descripL.trim() %></td>
</tr>
<%
}
%>
</table>
</div>
</body>
</html>

the bold section is where I added the radio buttons, but like I said, I'm not sure I created a "Group" (at least that's not how I would do it in Delphi!!) and the red bold section is where I get the error about new.

Thanks for any insight into what I'm doing wrong!

leslie
 
try
Code:
Library l = new Library();
I don't know what class jdbcAccess is, but you'll probably need to import that into your Library class. Also, I think you want the setStatus method outside of the constructor method, like getStatuteList(). You'll also need a setJDBCdefs(???? jdbcd) method, using whatever class JDBCdefs is.
Code:
private Object JDBCdefs;
public void setJDBCdefs(Object jdbcd){
JDBCdefs = jdbcd;
}
Change object to the appropriate class name. Then it should compile.

-----------------------------------------
I cannot be bought. Find leasing information at
 
great! adding the () at the end of Library fixed all the errors! The page at least came up in the browser this time (albeit with no data, but hey..can't ask for everything all at once!)

Here's the jdbcAccess class. I'll keep trying to get the data to show up in my webpage! I'm also doing an online jsp tutorial to try and refresh my skills and remember how it all works!

Code:
package functions;

import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class jdbcAccess implements Serializable
{
private Connection conn;
	
public jdbcAccess()
{
	super();
}
public void connect() throws SQLException
{
	try
	{
	String driver = "com.ibm.as400.access.AS400JDBCDriver";
	String url = "jdbc:as400://iseries;date format=iso";
	String username = "username";
	String password = "userpassword";
			
	Class.forName(driver);
	conn = DriverManager.getConnection(url,username,password);
				
} catch (SQLException se)
{ System.out.println("SQL MVD Connection Error: " + se.getErrorCode() + " " + se.getMessage());
				 
} catch (ClassNotFoundException cnf)
	{ System.out.println("Class MVD Connection Error: " + cnf.getMessage());	      
	}
}
public Connection getConnection()
{
	return conn;
}
}

Leslie

Have you met Hardy Heron?
 
I got my list back!!! I was still calling the JDBCdefs to get the statute list, once I changed it to the correct procedure, they all came back!

However, I can't get it to only show active or inactive when the radio button is changed.....

any suggestions?

thanks for all your help!

leslie


 
in the code I provided
Code:
String status = (String)request.getParameter("status");
So, I think you'll just need to change your radio buttons to a lower case s status, or the line above to an upper case S.
I also assumed
Code:
if (!status.equalsIgnoreCase("all"))
stmt += " AND M.STATUS = '" + status +"' ";
You'll need to adjust that based on your data model.

-----------------------------------------
I cannot be bought. Find leasing information at
 
ok, here is the most recent version of the code. If I hard code in the status values it works. When I click the radio buttons what do I need to have so that it refreshes the page with the new selection?

Thanks for all your assistance!

Code:
<html>
<head>
<%@ page
import="java.util.ArrayList"
import="functions.*,java.util.StringTokenizer" 
language="java"
contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"
%>
<title>NM Statute Maintenance List</title>
<link href="theme/Master.css" rel="stylesheet" type="text/css" />
</head>
<body>

<%
		Library l = new Library();
		String status = (String)request.getParameter("status");
		if (status != null && !status.equalsIgnoreCase("")){
			l.setStatus(status);
		}
		
		ArrayList statuteList = l.getStatuteList();
		String dataRow = "";
		String strIndex = (String) session.getAttribute("currentRecord");
		int index = Integer.parseInt(strIndex);
		statuteList = l.getStatuteList();
		String statute = "", abbrev = "", descrip = "", descripL = "";
%>

		<div id="list">
		<h1 align="center">Metropolitan Court<br>Statute  List</h1>
		<h4 align="center">Select Statute to modify by clicking on the Row#.</h4>
		<table border="1" width="100%" cellpadding="2" cellspacing="2">
			<tr>
				<td colspan='3'>Number of Items: <%= statuteList.size() %></td>
				<td colspan='2'>Filter By: <input name="status" type="radio" value="A" checked> Active
				<input name="status" type="radio" value="I"> Inactive 
				<input name="status" type="radio" value="all"> All</td>
			</tr>
			<tr>
			<td>Row#</td>
			<td>Statute Id.</td>
			<td>Abbrev.</td>
			<td>Standard Description</td>
			<td>Extended Description</td>
			</tr>
			

			
<%
		for (int i=0; i < statuteList.size(); i++)
		{
			dataRow = statuteList.get(i).toString();
			StringTokenizer token = new StringTokenizer(dataRow,"%");
			statute = token.nextToken();
			abbrev = token.nextToken();
			descrip = token.nextToken();
			descripL = token.nextToken();
%>
			<tr>
				<td><a href="process.jsp?formtype=list&rowNbr=<%= i %>"><%= i %></a></td>
				<td><%= statute.trim() %></td>
				<td><%= abbrev.trim() %></td>
				<td><%= descrip.trim() %></td>
				<td><%= descripL.trim() %></td>
			</tr>
<%
		}
%>
		</table>
		</div>
</body>
</html>

Code:
package functions;

import java.sql.*;
import java.util.ArrayList;


public class Library {

	private String status = "ALL";


	public void setStatus(String inStatus){
		status = inStatus;
	}

	public ArrayList getStatuteList(){

		String library = JDBCdefs.getLibrary();
		ArrayList statuteList = new ArrayList();
		String dataRow = "";

		try
		{
			jdbcAccess datasource = new jdbcAccess();
			datasource.connect();
			Connection conn = datasource.getConnection();

			Statement sqlstmt = conn.createStatement();    
			String stmt = "SELECT E.STATUT, E.CHGABV, M.CHGDSC, E.CHGDSCL FROM " + library + "CMPSTAMFE E INNER JOIN " + library + "CMPSTAMF M ON E.STATUT = M.STATUT AND E.CHGABV " +
			"= M.CHGABV ";
			
			if (status.equalsIgnoreCase("A"))
				stmt += " AND M.STASTS <> 'I'";
		
			if (status.equalsIgnoreCase("I"))
				stmt += " AND M.STASTS = 'I'";
			
			stmt += " ORDER BY STATUT, CHGABV";
			
			System.out.println(stmt);

			ResultSet statutes = sqlstmt.executeQuery(stmt);

			while(statutes.next())
			{
				dataRow = statutes.getString("STATUT") + "%";
				dataRow = dataRow + statutes.getString("CHGABV") + "%";
				dataRow = dataRow + statutes.getString("CHGDSC") + "%";
				dataRow = dataRow + statutes.getString("CHGDSCL") + "%";
				statuteList.add(dataRow);
			}
			sqlstmt.close();
			statutes.close();
			conn.close();

		}
		catch (SQLException sql)
		{
			System.out.println("statute Access - Sql Exception: " + sql.getMessage());
		}
		return statuteList;
	}

}

Leslie

Have you met Hardy Heron?
 
try this
Code:
<input name="status" type="radio" value="I" onClick="window.location = 'index.jsp?status=I'"> Inactive
<input name="status" type="radio" value="all" onclick="window.location = 'index.jsp?status=all'"> All</td>

-----------------------------------------
I cannot be bought. Find leasing information at
 
wow that's great! I wish I could give you a thousand stars!!

After I add another filter for the origin of the statute I'll be moving onto the edit form...I'm sure I'll have more questions and issues!

Thanks for all your help!

leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top