
When the validate method returns back to the registration page the password field get cleared there by asking again one more time to enter the password field at the time of re-submitting the form
*newuser.jsp*
<%@page contentType="text/html" pageEncoding="UTF-8"%> <%@taglib prefix="s" uri="/struts-tags" %>
RegAction.java
public class RegAction extends ActionSupport{
private String fname;
private String lname;
private String uname;
private String pwd;
private String gender;
private String country;
private String hobbies;
private String address;
public String getAddress() {
return address;
}
public void setAddress(String address) {
this.address = address;
}
public String getCountry() {
return country;
}
public void setCountry(String country) {
this.country = country;
}
public String getFname() {
return fname;
}
public void setFname(String fname) {
this.fname = fname;
}
public String getGender() {
return gender;
}
public void setGender(String gender) {
this.gender = gender;
}
public String getHobbies() {
return hobbies;
}
public void setHobbies(String hobbies) {
this.hobbies = hobbies;
}
public String getLname() {
return lname;
}
public void setLname(String lname) {
this.lname = lname;
}
public String getPwd() {
return pwd;
}
public void setPwd(String pwd) {
this.pwd = pwd;
}
public String getUname() {
return uname;
}
public void setUname(String uname) {
this.uname = uname;
}
@Override
public String execute()
{
return SUCCESS;
}
@Override
public void validate()
{
if(getFname().equals("")){
addFieldError("fname", "Enter First Name");
}
else if(getLname().equals("")){
addFieldError("lname", "Enter Last Name");
}
else if (getUname().equals("")){
addFieldError("uname", "Enter USer Name");
}
else if(getPwd().equals("")){
addFieldError("pwd", "Enter Password");
}
// else if(getGender().equals("")){ // addFieldError("gender", "Select any Gender"); // }
else if(getCountry().equals("")){
addFieldError("country", "Select any Country");
}
else if(getHobbies().equals("")){
addFieldError("hobbies", "Select a Hobby");
}
else if (getAddress().equals("")){
addFieldError("address", "Enter the Address");
}
}
}
struts.xml
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.