File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes JSP and the fly likes form validation (stateform) and response.redirect() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Java Interview Guide this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "form validation (stateform) and response.redirect()" Watch "form validation (stateform) and response.redirect()" New topic

form validation (stateform) and response.redirect()

Sana Ali

Joined: Oct 08, 2004
Posts: 14
Hi, I have a form which takes input of memberID, LastName, FirstName.

Im using sessions and JavaBeans.

If memberID or LastName is not entered the user is to be prompted otherwise sent to the next form step.

parts of my code are:

<%@page import="*"%>
<%@page import="sana.member.MemberBean"%>

<jsp:useBean id="myMemberBean" class="sana.member.MemberBean" scope="session" />

<% myMemberBean.clear(); %>
//Define constants to represent states
public static final int DATA_ENTRY = 1;
public static final int MISSING_DATA = 2;
public static final int PROCEED_LOGIN = 3;

//Keep track of current state
int current_state;

String action = "",
id = "",
lastname = "",
firstname = "",
dateofbirth = "";

<% action = request.getParameter("action");
id = request.getParameter("memberid");
lastname = request.getParameter("lastName");
firstname = request.getParameter("firstName");
dateofbirth = request.getParameter("dateofbirth");

// Figure out current state of system, and next permissible action

current_state = DATA_ENTRY; //default state

if (action != null && action.equals("PROCEED"))
current_state = PROCEED_LOGIN;

if (id == null || id.equals("") ||
lastname == null || lastname.equals(""))
current_state = MISSING_DATA;



if (current_state == DATA_ENTRY || current_state == MISSING_DATA) {
<table width="700" border="0" cellpadding="4" cellspacing="0">
<th> <b>Member Details Input Step 1. . .</b></th>

if (current_state == MISSING_DATA) {
<td bgcolor="#FFFF66">
<p><strong>Fields Member ID and Last Name are mandatory</strong></p>
<% } %>

<form method="post" action="memberinput2.jsp">
<input type="hidden" name="action" value="PROCEED" />

//Other code

<td><input type="submit" name="submit1" value=" Proceed to Step 2 "></td>

<% } else if(current_state == PROCEED_LOGIN) {

<% } else {
// Unknown state - should not occuru

<table width="500" border=0
cellpadding=4 cellspacing=0>
<td bgcolor="lightblue"><font color="white" face="Arial"><b>A system error has occurred.</b></font></td>

<% } %>
//Other code


However, instead of the page getting reloaded and prompting the user to enter the missing data, the user is sent to the next page. :'(
Does any1 have a clue here?
Please help.
I agree. Here's the link:
subject: form validation (stateform) and response.redirect()
jQuery in Action, 3rd edition