• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Junilu Lacar
  • Liutauras Vilda
  • Paul Clapham
  • Jeanne Boyarsky
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Jesse Duncan
  • Frits Walraven
  • Mikalai Zaikin

Struts 1.1 problem with form validation

Ranch Hand
Posts: 65
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,

I am trying to validate my struts login page to check if some value is entered for the username and password or not. If not then error message should be displayed. But when i debug my application by setting a break point in thee validate method, then the validate method is getting executed but the user is getting redirected to a blank page rather than displaying the error message in the login page itself. Please have a look at what i did so far:

Please help!!!

Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You can do one more things.the validation you can do in action itself. I am attaching some code here. just change your action mapping some what it would work

import javax.servlet.http.*;
import org.apache.struts.action.*;

public class ExampleAction extends org.apache.struts.action.Action {

/* forward name="success" path="" */
private static final String SUCCESS = "success";
/* failure name="failure" path="" */
private static final String FAILURE = "failure";

public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
//Add error into incoming HTTP request
ActionMessages errors = new ActionMessages();
// By making instance of DynaActionForm class,
DynaActionForm actionForm = (DynaActionForm) form;
//Value store into DynaForm is call here:
String first = (String) actionForm.get("first");
String last = (String) actionForm.get("last");
int age = (Integer) actionForm.get("age");
int number = (Integer) actionForm.get("number");

//Check the valiadation condition into incomming HTTP request form DynaForm
if (first == null || first.length() < 1) {
errors.add("first", new ActionMessage("error.first.required"));
if (last == null || last.length() < 1) {
errors.add("last", new ActionMessage("error.last.required"));
if (age == 0) {
errors.add("age", new ActionMessage("error.age.required"));
if (number < 1) {
errors.add("number", new ActionMessage("error.number.required"));
//Save Error/request and dispaly it anywhere within this application
saveErrors(request, errors);
if (errors.isEmpty()) {
return mapping.findForward(SUCCESS);
} else {
return mapping.findForward(FAILURE);
Posts: 4
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
<html:form action="/login">
change this to <html:form action="login.do"> and try.
    Bookmark Topic Watch Topic
  • New Topic