Hello, and thank you for youre time,
I have a problem with my jsp application, when i try to get the values from the html form on the jsp page process.jsp, it sets the values of each element but then does not return them to the java page. It keeps checking the web page for more properties but when it reaches the bottom of the jsp page it terimates itsself and says source not found. Any help would be appriciated, Thanks
Here is the code for the process.jsp page
<%@ page import="java.util.ArrayList" %>
<%@ page import="scannerForm.DataAccess" %>
<%@ page import="java.util.Iterator" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<jsp:useBean id="formbean" class="scannerForm.FormDataBean"/>
<jsp:setProperty name="formbean" property="swipeCard"/>
<jsp:setProperty name="formbean" property="workArea"/>
<jsp:setProperty name="formbean" property="partNumber"/>
<jsp:setProperty name="formbean" property="quantity"/>
<html xmlns="http://www.w3.org/1999/xhtml">
<link rel="stylesheet" type="text/css" href="css/style.css" />
<link rel="icon" type="image/ico" href="images/logo1.ico" />
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<head>
<title>Scanner Form</title>
</head>
<body BGCOLOR="#ffffcc" style="width:auto;height:auto;border-style:solid;border-color:#F00;">
<script type="text/javascript">
function validateForm()
{
if (document.frm.swipeCard.value ==""){
alert("A valid card number must be entered.");
document.frm.cardNumber.focus();
return false;
}
if (document.frm.partNumber.value ==""){
alert("A valid part number must be entered.");
document.frm.cardNumber.focus();
return false;
}
if (document.frm.quantity.value ==""){
alert("A quantity must be entered");
document.frm.quantity.focus();
return false;
}
}</script>
<% if (request.getParameter("swipeCard") == null && request.getParameter("workArea") == null && request.getParameter("partNumber") == null && request.getParameter("quantity") == null ){ %>
<form id="1" method="get" action="process.jsp" onsubmit="return validateForm()" style="width:auto;height:auto;border-style:solid;border-color:#F00;">
<h2>Scanner Form<br /><img id="image" src="images/logo.gif" href="images/logo.gif"/></h2>
<hr>
<p>Swipe Card Number:</p>
<p><input type="text" name="swipeCard" property="swipeCard"/></p>
<p for="workArea">Work Area:
<select name="workArea" id="workArea">
<%
DataAccess dataAccess = new DataAccess();
ArrayList workAreas = dataAccess.loadWorkAreas();;
Iterator it = workAreas.iterator();
String xx = null;
while(it.hasNext()) {
xx = (String) it.next(); %>
<option name="workArea" id="workArea" property="workArea" value="<%=xx%>"><%=xx%></option>
<% } %>
</select></p>
<p>Part Number: </p>
<p><input type="text" name="partNumber" property="partNumber"/></p>
<p>Quantity: </p>
<p><input type="text" name="quantity" property="quantity"/></p>
<hr>
<p><input type="submit" value="Process"/><input type="reset" /></p>
</form>
<% } else { %>
<!-- <form id="2" method="post" style="width:auto;height:auto;border-style:solid;border-color:#F00;">-->
<h2>Scanner Form<br /><img id="image" src="images/logo.gif" href="images/logo.gif"/></h2>
<hr>
<p>You have provided the following data:</p>
<p>Card Number: <jsp:getProperty name="formbean" property="swipeCard"/> </p>
<p>Work Area: <jsp:getProperty name="formbean" property="workArea"/> </p>
<p>Part Number: <jsp:getProperty name="formbean" property="partNumber"/> </p>
<p>Quantity: <jsp:getProperty name="formbean" property="quantity"/> </p>
<p><input type="button" value="New Report" onclick="document.location = 'process.jsp';"/></p>
<p><input type="button" value="Exit" onclick="window.close()"/></p>
<% } %>
</body>
</html>
...and here is the code for the FormDataBean.java
package scannerForm;
import java.io.*;
import java.sql.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.Vector;
import downtime.ConnectionDataBase;
import jdbc_connect.conn;
public class FormDataBean implements Serializable {
public static String ColumnsNames = "user_id, workarea, storeroom_part_number, quantity, created_date, created_by";
public static String jdbc_connection = "dcs_fp";
conn conn_fandp = null;
//fields
//private String cardNumber;
private String swipeCard;
private String workArea;
private String partNumber;
private String quantity;
private ArrayList formData;
//constructor
public FormDataBean() {
//test values
//loadValues();
//cardNumber = "2";
//workArea = "3";
//partNumber = "4";
//quantity = "5";
swipeCard = null;
// cardNumber = null;
workArea = null;
partNumber = null;
quantity = null;
// form validation
if (swipeCard==null && workArea==null && partNumber==null && quantity==null) {
System.out.println("Card Number: " + swipeCard + " |Work Area: " + workArea + " |Part Number: " + partNumber + " |Quantity: " + quantity);
}else{
InsertmainElement();
loadValues();
}
}
//public void setCardNumber(String cardNumber) {
// this.cardNumber = cardNumber;
//System.out.println("work area" + workArea);
// }
// public String getCardNumber() {
// return cardNumber;
// }
public void setSwipeCard(String swipeCard) {
this.swipeCard = swipeCard;
//System.out.println("work area" + workArea);
}
public String getSwipeCard() {
return swipeCard;
}
public void setWorkArea(String workArea) {
this.workArea = workArea;
//System.out.println("work area" + workArea);
}
public String getWorkArea() {
return workArea;
}
public void setPartNumber(String partNumber) {
this.partNumber = partNumber;
//System.out.println("partNumber" + partNumber);
}
public String getPartNumber() {
return partNumber;
}
public void setQuantity(String quantity) {
this.quantity = quantity;
//System.out.println("quantity" + quantity);
}
public String getQuantity() {
return quantity;
}
//loadValues method
public void loadValues(){
if ( workArea==null && partNumber==null && quantity==null) {
//System.out.println("Card Number: " + cardNumber);
System.out.println("Card Number: " + swipeCard);
System.out.println("Work Area: " + workArea);
System.out.println("Part Number: " + partNumber);
System.out.println("Quantity: " + quantity);
}else{
//System.out.println("Card Number: " + cardNumber);
System.out.println("Card Number: " + swipeCard);
System.out.println("Work Area: " + workArea);
System.out.println("Part Number: " + partNumber);
System.out.println("Quantity: " + quantity);
}
}
//database method
public ArrayList InsertmainElement()
{
boolean bln_result = true;
int ErrorStatus = 0;
String data_row = "";
//ResultSet rs;
conn_fandp = new conn();
bln_result = conn_fandp.getConnection(jdbc_connection);
if (bln_result == false) {
System.out.println("Connection to DCS FANDP schema failed.");
}
else {
System.out.println("Connection to DCS FANDP succeded.");
}
formData = new ArrayList();
try {
// this will call the store procedure
String sql ="";
Connection curr_conn = conn_fandp.current_connection;
curr_conn.prepareCall("{call fandp.strm_scanner('"+swipeCard.trim() + "', '"+workArea.trim() + "', '"+partNumber.trim() + "', "+quantity.trim() + ")").execute();
ResultSet rs = curr_conn.createStatement().executeQuery(sql);
rs.close();
curr_conn.close();
}catch(Exception e) {
// bln_result = false;
System.out.println(e);
}
// get an Iterator object for ArrayList using iterator() method.
//Iterator itr = formData.iterator();
// use hasNext() and next() methods of Iterator to iterate through the elements.
//System.out.println("Iterating through ArrayList elements...");
// while(itr.hasNext()){
// System.out.println("Iterations:" + itr.next());
// }
//System.out.println("bryn " + itr.hasNext());
conn_fandp.current_connection = null;
conn_fandp = null;
//for testing purposes...
//formData.add(cardNumber);
//formData.add(workArea);
//formData.add(partNumber);
//formData.add(quantity);
return formData;
}
}