Help coderanch get a
new server
by contributing to the fundraiser
  • 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 ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Devaka Cooray
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Tim Moores
  • Carey Brown
  • Mikalai Zaikin
Bartenders:
  • Lou Hamers
  • Piet Souris
  • Frits Walraven

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!!!

Thanks,
Butny
 
Greenhorn
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";

@Override
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);
}
}
}
 
Greenhorn
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.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic