JSP to Bean to Java class Validation
Posted
by littlevahn
on Stack Overflow
See other posts from Stack Overflow
or by littlevahn
Published on 2010-05-11T21:00:03Z
Indexed on
2010/05/11
21:04 UTC
Read the original article
Hit count: 243
I have a rather simple form in JSP that looks like this:
<form action="response.jsp" method="POST">
<label>First Name:</label><input type="text" name="firstName" /><br>
<label>Last Name:</label><input type="text" name="lastName" /><br>
<label>Email:</label><input type="text" name="email" /><br>
<label>Re-enter Email:</label><input type="text" name="emailRe" /><br>
<label>Address:</label><input type="text" name="address" /><br>
<label>Address 2:</label><input type="text" name="address2" /><br>
<label>City:</label><input type="text" name="city" /><br>
<label>Country:</label>
<select name="country">
<option value="0">--Country--</option>
<option value="1">United States</option>
<option value="2">Canada</option>
<option value="3">Mexico</option>
</select><br>
<label>Phone:</label><input type="text" name="phone" /><br>
<label>Alt Phone:</label><input type="text" name="phoneAlt" /><br>
<input type="submit" value="submit" />
</form>
But when I try and access the value of the select box in my Java class I get null. Ive tried reading it in as a String and an Array of strings neither though seems to be grabbing the right value.
The response.jsp looks like this:
<%@ page language="java" %>
<%@ page import="java.util.*" %>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%!
%>
<jsp:useBean id="formHandler" class="validation.RegHandler" scope="request">
<jsp:setProperty name="formHandler" property="*" />
</jsp:useBean>
<%
if (formHandler.validate()) {
%>
<jsp:forward page="success.jsp"/>
<%
}
else
{
%>
<jsp:forward page="retryReg.jsp"/>
<% }
%>
I already have Java script validation in place but I wanted to make sure I covered validation and checking for non-JS users.
The RegHandler just uses the name field to refer to the value in the form.
Any Idea how I could access the select box's value?
© Stack Overflow or respective owner