I have the following
JSP page for collecting bill information, the page
validates the data itself but I want to then pass the entered details into a
javabean so I can then store them for later use. My javabean just has simple
get and set methods for storing the info. But how do I get the data into
it???
I have tried using <jsp:setProperty name="myBillBean" property="b1"
param="b1" /> at different points on this page and the start of the next but
either nothing is passed to the Javabean or I just get null.
Have included the Javabean below the JSP page
Any ideas?
S
<%@page import="java.io.*"%>
<%@page import="com.bill.BillBean"%>
<jsp:useBean id="myBillBean" class="com.bill.BillBean" scope="session" />
<%!
// Define constants that represent our states
public static final int DATA_ENTRY = 1;
public static final int INVALID_MISSING_DATA = 2;
public static final int SUBMIT_DATA = 3;
// keep track of our current state
int current_state;
// Variables for storing the HTML form data
String action, b1 ;
%>
<%
action = request.getParameter("action");
b1 = request.getParameter("b1");
// Figure out current state of system, and next permissible action
current_state = DATA_ENTRY; // this is the default
if (action != null && action.equals("Submit Data")) {
current_state = SUBMIT_DATA;
if (mon == null ||!mon.matches("[0-9]*\\.[0-9]{2}")) {
current_state = INVALID_MISSING_DATA;
}
}
%>
<%
if (current_state == DATA_ENTRY || current_state == INVALID_MISSING_DATA) {
%>
<table width="500" border="0"
cellpadding="4" cellspacing="0">
<tr>
<td bgcolor="lightred">
<font color="white" face="Arial"><b>Submit Data</b>
</font></td>
</tr>
<%
if (current_state == INVALID_MISSING_DATA) {
%>
<tr>
<td bgcolor="yellow">
<font color="blue" face="Arial">
<b>You have not entered data correctly </b>
</font></td>
</tr>
<% } %>
<tr>
<td>
<form method="post" action="first2.jsp">
<input type="hidden" name="action" value="Submit Data" />
<table>
<tr><td><b>Monday:</b></td><td><input type="text" name="mon" size="25"
value="<%= b1==null ? "" : b1 %>"></td></tr>
</table><br />
<input type="submit" value="Submit Data">
</form>
</td>
</tr>
</table>
<% } else if (current_state == SUBMIT_DATA) {
response.sendRedirect("next.jsp");
%>
<% } %>
</body>
</html>
Javabean
package com.bill.;
import java.util.*;
/**
A bill JavaBean
*/
public class BillBean {
private String b1;
//New address bill bean with null values (default) for fields.
public BillBean() {
}
//Clears the fields
public void clear() {
b1 = null;
}
//Sets the b1 variable
public void setB1 (String b1) {
this.b1 = b1;
}
// Gets b1
public String getB1() {
return b1;
}
}