Win a copy of TDD for a Shopping Website LiveProject this week in the Testing forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Jeanne Boyarsky
  • Tim Cooke
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Frits Walraven
Bartenders:
  • Piet Souris
  • Himai Minh

Pop up error while using validation in struts2.0

 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,
I have wriiten a small application using struts 2.0...and then i have tried to implement validation in it.I have given 2 input fields, and when i click on submit without entereing in one of the fields or both, i get a pop-up stating that [object-error].

Kindly, help me out in this...the code is given below...
Thanks in advance.

Login.jsp:

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252"/>
<title>Login</title>

</head>
<body>

<s:form action="loginAction" validate="true">


Username: <s:textfield name="username"/>
Password: <s assword name="password"/>

<s:submit value="submit"/>
</s:form>
</body>
</html>

loginAction-Validation.xml:

<validators>

<field name="username">

<field-validator type="required">
<param name="fieldName">username</param>

<!--<param name="trim">true</param>-->

<message>Login name is required</message>

</field-validator>

</field>

<field name="password">

<field-validator type="requiredstring">

<!--<param name="trim">true</param>-->

<message>Password is required</message>

</field-validator>

</field>

</validators>

loginAction.Java:

public class loginAction extends ActionSupport{

String username;
String password;
public String execute()throws Exception{

System.out.println(""+username);
System.out.println(""+password);
System.out.println("Validating login");
if(!getUsername().equals("Admin") || !getPassword().equals("Admin")){
addActionError("Invalid user name or password! Please try again!");
return "ERROR";
}else{
return "SUCCESS";
}

}

public void setUsername(String username) {
this.username = username;
}

public String getUsername() {
return username;
}

public void setPassword(String password) {
this.password = password;
}

public String getPassword() {
return password;
}
}

does anyone know....how to solve it....
thanks...
Rajiv
 
them good ole boys were drinking whiskey and rye singin' this'll be the day that I die. Drink tiny ad.
Free, earth friendly heat - from the CodeRanch trailboss
https://www.kickstarter.com/projects/paulwheaton/free-heat
reply
    Bookmark Topic Watch Topic
  • New Topic