This week's book giveaways are in the Cloud and AI/ML forums.
We're giving away four copies each of Cloud Native Patterns and Natural Language Processing and have the authors on-line!
See this thread and this one for details.
Win a copy of Cloud Native PatternsE this week in the Cloud forum
or Natural Language Processing in the AI/ML forum!

parthiban thrangaraju

Greenhorn
+ Follow
since Feb 06, 2011
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
1
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by parthiban thrangaraju


Hi Raaja,

Thanks for your reply.

I have written the code for checking from database. In this code if the email id already exists in the database, it is not storing once again but the error message is not displayed and also i have tried by using logic tag. Both the scenarios are not working.How to solve the problem.

Jsp code
----------

<!DOCTYPE html>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html lang="en">
<head>
<title><bean:message key="newuser.title1"/></title>
<meta charset="utf-8">
</head>

<body id="page7">

<table id="login-form">
<html:form action="/NewUserForm" styleId="login-form">
<fieldset>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title2"/>
</td>
<td>
<html:text property="firstname"/>
</td>
<td>
<html:errors property="firstname"/>
</td>
</tr>

</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title3"/>
</td>
<td>
<html:text property="lastname"/>
</td>
<td>
<html:errors property="lastname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title4"/>
</td>
<td>
<html:radio property="gender" value="Male">Male</html:radio>
<html:radio property="gender" value="Female">Female</html:radio>
</td>
<td>
<html:errors property="gender"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title5"/>
</td>
<td>
<html:text property="dateofbirth"/>
</td>
<td>
<html:errors property="dateofbirth"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title6"/><sup>*</sup>
</td>
<td>
<html:text property="emailid"/>
</td>
<td>
<html:errors property="emailid"/>
<logic:present name="email">
Email Id already exists.
</logic:present>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title1"/>
</td>
<td>
<html:text property="username"/>
</td>
<td>
<html:errors property="username"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title2"/>
</td>
<td>
<html:password property="password"/>
</td>
<td>
<html:errors property="password"/>
</td>
</tr>

</div>
<div>
<tr>
<td>
<bean:message key="newuser.title7"/>
</td>
<td>
<html:password property="confirmpassword"/>
</td>
<td>
<html:errors property="confirmpassword"/>
</td>
</tr>

</div>

<div class="wrapper">
<tr>
<td colspan="3">
<html:submit value="REGISTER" styleId="submit"/>
</td>
</tr>

</div>
</fieldset>
</html:form>
</table>

</body>
</html>

Action Form
---------------


package classes.newuser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;




public class NewUserForm extends org.apache.struts.validator.ValidatorForm {

private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;

public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;

}

/*public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

NewUserAction act= new NewUserAction();
ActionForm form=null;




errors.add("emailid", new ActionMessage("NewUserForm.emailid.alreadyexists"));

return errors;
}*/
}

Action Class
--------------


package classes.newuser;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionFormBean;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.ValidatorPlugIn;
import org.apache.struts.validator.validwhen.ValidWhen;


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

private static final String SUCCESS = "success";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

NewUserForm nsf=(NewUserForm)form;



String firstname=nsf.getFirstname();
String lastname=nsf.getLastname();
String gender=nsf.getGender();
String dateofbirth=nsf.getDateofbirth();
String emailid=nsf.getEmailid();
String username=nsf.getUsername();
String password=nsf.getPassword();
String confirmpassword=nsf.getConfirmpassword();

try{

String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();

//String email=request.getParameter("emailid").toString();
System.out.println(emailid);
ResultSet rs=st.executeQuery("select emailid from registration where emailid='"+emailid+"'");
int count=0;
while(rs.next()){

String email=rs.getString("emailid");
System.out.println("email=============="+email);
count++;
}


if(count>0){

request.setAttribute("emailid", "email");

}

else{

String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);

}

}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return mapping.findForward(SUCCESS);
}



}


Thanks in advance
7 years ago
Hi,


I have written the code to validate the email id, if the email id already exists an error message should be displayed saying "Email Id already exists".
I have written the code for checking from database. If the email id already exists in the database it is not storing once again but the error message is not displayed. How to solve the problem.

Jsp code
----------

<!DOCTYPE html>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html lang="en">
<head>
<title><bean:message key="newuser.title1"/></title>
<meta charset="utf-8">
</head>

<body id="page7">

<table id="login-form">
<html:form action="/NewUserForm" styleId="login-form">
<fieldset>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title2"/>
</td>
<td>
<html:text property="firstname"/>
</td>
<td>
<html:errors property="firstname"/>
</td>
</tr>

</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title3"/>
</td>
<td>
<html:text property="lastname"/>
</td>
<td>
<html:errors property="lastname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title4"/>
</td>
<td>
<html:radio property="gender" value="Male">Male</html:radio>
<html:radio property="gender" value="Female">Female</html:radio>
</td>
<td>
<html:errors property="gender"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title5"/>
</td>
<td>
<html:text property="dateofbirth"/>
</td>
<td>
<html:errors property="dateofbirth"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title6"/><sup>*</sup>
</td>
<td>
<html:text property="emailid"/>
</td>
<td>
<html:errors property="emailid"/>
<logic:present name="email">
Email Id already exists.
</logic:present>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title1"/>
</td>
<td>
<html:text property="username"/>
</td>
<td>
<html:errors property="username"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title2"/>
</td>
<td>
<html:password property="password"/>
</td>
<td>
<html:errors property="password"/>
</td>
</tr>

</div>
<div>
<tr>
<td>
<bean:message key="newuser.title7"/>
</td>
<td>
<html:password property="confirmpassword"/>
</td>
<td>
<html:errors property="confirmpassword"/>
</td>
</tr>

</div>

<div class="wrapper">
<tr>
<td colspan="3">
<html:submit value="REGISTER" styleId="submit"/>
</td>
</tr>

</div>
</fieldset>
</html:form>
</table>

</body>
</html>

Action Form
---------------


package classes.newuser;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;




public class NewUserForm extends org.apache.struts.validator.ValidatorForm {

private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;

public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;

}

/*public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

NewUserAction act= new NewUserAction();
ActionForm form=null;




errors.add("emailid", new ActionMessage("NewUserForm.emailid.alreadyexists"));

return errors;
}*/
}

Action Class
--------------


package classes.newuser;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionFormBean;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.ValidatorPlugIn;
import org.apache.struts.validator.validwhen.ValidWhen;


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

private static final String SUCCESS = "success";
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

NewUserForm nsf=(NewUserForm)form;



String firstname=nsf.getFirstname();
String lastname=nsf.getLastname();
String gender=nsf.getGender();
String dateofbirth=nsf.getDateofbirth();
String emailid=nsf.getEmailid();
//String email=request.getParameter("emailid");
String username=nsf.getUsername();
String password=nsf.getPassword();
String confirmpassword=nsf.getConfirmpassword();

try{

/*String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();
String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);*/

String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();

//String email=request.getParameter("emailid").toString();
System.out.println(emailid);
ResultSet rs=st.executeQuery("select emailid from registration where emailid='"+emailid+"'");
int count=0;
while(rs.next()){

String email=rs.getString("emailid");
System.out.println("email=============="+email);
count++;
}

//String ei=rs.getString(1);
if(count>0){

//return mapping.findForward(errors);
request.setAttribute("emailid", "email");


}

else{

String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);

}

}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return mapping.findForward(SUCCESS);
}



}


Thanks in advance
7 years ago
Hi Joe Ess,

I have validated the email address and the scenario is working but the problem is error message is not displaying "Email Id already exists". I have attached the code. Can youo help me

Jsp page
-----------

<!DOCTYPE html>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<html lang="en">
<head>
<title><bean:message key="newuser.title1"/></title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<!--[if lt IE 7]>
<link rel="stylesheet" href="css/ie/ie6.css" type="text/css" media="screen">
</head>

<body id="page7">
<table id="login-form">
<html:form action="/NewUserForm" styleId="login-form">
<fieldset>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title2"/>
</td>
<td>
<html:text property="firstname"/>
</td>
<td>
<html:errors property="firstname"/>
</td>
</tr>

</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title3"/>
</td>
<td>
<html:text property="lastname"/>
</td>
<td>
<html:errors property="lastname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title4"/>
</td>
<td>
<html:radio property="gender" value="Male">Male</html:radio>
<html:radio property="gender" value="Female">Female</html:radio>
</td>
<td>
<html:errors property="gender"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title5"/>
</td>
<td>
<html:text property="dateofbirth"/>
</td>
<td>
<html:errors property="dateofbirth"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title6"/><sup>*</sup>
</td>
<td>
<html:text property="emailid"/>
</td>
<td>
<html:errors property="emailid"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title1"/>
</td>
<td>
<html:text property="username"/>
</td>
<td>
<html:errors property="username"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title2"/>
</td>
<td>
<html:password property="password"/>
</td>
<td>
<html:errors property="password"/>
</td>
</tr>

</div>
<div>
<tr>
<td>
<bean:message key="newuser.title7"/>
</td>
<td>
<html:password property="confirmpassword"/>
</td>
<td>
<html:errors property="confirmpassword"/>
</td>
</tr>
</div>
<div class="wrapper">
<tr>
<td colspan="3">
<html:submit value="REGISTER" styleId="submit"/>
</td>
</tr>
</div>
</fieldset>
</html:form>
</table>

</body>
</html>

Action Form
--------------


package classes.newuser;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;



public class NewUserForm extends org.apache.struts.validator.ValidatorForm {

private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;

public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;

}

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

NewUserAction act= new NewUserAction();
ActionForm form=null;

//Boolean flag= act.

errors.add("emailid", new ActionMessage("NewUserForm.emailid.alreadyexists"));

return errors;
}
}


Action Class
---------------


package classes.newuser;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionFormBean;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.ValidatorPlugIn;
import org.apache.struts.validator.validwhen.ValidWhen;

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


private static final String SUCCESS = "success";


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

NewUserForm nsf=(NewUserForm)form;



String firstname=nsf.getFirstname();
String lastname=nsf.getLastname();
String gender=nsf.getGender();
String dateofbirth=nsf.getDateofbirth();
String emailid=nsf.getEmailid();

String username=nsf.getUsername();
String password=nsf.getPassword();
String confirmpassword=nsf.getConfirmpassword();

try{


String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();

//String email=request.getParameter("emailid").toString();
System.out.println(emailid);
ResultSet rs=st.executeQuery("select emailid from registration where emailid='"+emailid+"'");
int count=0;
while(rs.next()){

String email=rs.getString("emailid");
System.out.println("email=============="+email);
count++;
}

//String ei=rs.getString(1);
if(count>0){

//return mapping.findForward(errors);


}

else{

String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);

}

}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return mapping.findForward(SUCCESS);
}



}


thanks in advance
7 years ago
Hi,

In action form can we use org.apache.struts.validator.validatorForm and validate method. I have attached my code


ActionForm
--------------

package classes.newuser;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;

public class NewUserForm extends org.apache.struts.validator.ValidatorForm {


private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;


public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;

}

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

NewUserAction act= new NewUserAction();
ActionForm form=null;

//Boolean flag= act.

errors.add("emailid", new ActionMessage("NewUserForm.emailid.alreadyexists"));

return errors;
}
}

can any one help me
7 years ago
this code is validating the email id but the error message is not displayed saying that email id already exists. can any one help me.
7 years ago
Hi,

After submitting the form i have to validate the email id. If already exists in database i have to display an error message saying that email id already exist. I have written the code but its not working. Can any one help me. I have attached my code

jsp code
----------

<!DOCTYPE html>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%--<%@taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>--%>
<%--<%@taglib uri="/struts-tags" prefix="s" %>--%>
<html lang="en">
<body>


<section id="mainContent">
<article class="last">
<div class="inside">
<table id="login-form">
<html:form action="/NewUserForm" styleId="login-form">
<fieldset>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title2"/>
</td>
<td>
<html:text property="firstname"/>
</td>
<td>
<html:errors property="firstname"/>
</td>
</tr>


</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title3"/>
</td>
<td>
<html:text property="lastname"/>
</td>
<td>
<html:errors property="lastname"/>
</td>
</tr>

</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title4"/>
</td>
<td>
<html:radio property="gender" value="Male">Male</html:radio>
<html:radio property="gender" value="Female">Female</html:radio>
</td>
<td>
<html:errors property="gender"/>
</td>
</tr>
<%--<s:radio name="" list="{'Male','Female'}"/>--%>
<%--<label for="checkbox">Remember me</label> <input type="checkbox" name="checkbox" id="checkbox">--%>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title5"/>
</td>
<td>
<html:text property="dateofbirth"/>
</td>
<td>
<html:errors property="dateofbirth"/>
</td>
</tr>
<%--<s:date name="date" format="dd-mm-yyyy" />--%>
<%--<s:textfield/>--%>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title6"/><sup>*</sup>
</td>
<td>
<html:text property="emailid"/>
</td>
<td>
<html:errors property="emailid"/>
</td>
</tr>

</div>
<div>
<tr>
<td>
<bean:message key="common.title1"/>
</td>
<td>
<html:text property="username"/>
</td>
<td>
<html:errors property="username"/>
</td>
</tr>

</div>
<div>
<tr>
<td>
<bean:message key="common.title2"/>
</td>
<td>
<html:password property="password"/>
</td>
<td>
<html:errors property="password"/>
</td>
</tr>

</div>
<div>
<tr>
<td>
<bean:message key="newuser.title7"/>
</td>
<td>
<html:password property="confirmpassword"/>
</td>
<td>
<html:errors property="confirmpassword"/>
</td>
</tr>

</div>

<div class="wrapper">
<tr>
<td colspan="3">
<html:submit value="REGISTER" styleId="submit"/>
</td>
</tr>

</div>
</fieldset>
</html:form>
</table>

</div>
</article>
</section>
</div>
</div>
</section>
<!-- footer -->
<footer>
<div class="container">
<a href=""><bean:message key="common.title31"/></a> <bean:message key="common.title32"/> <a href=""><bean:message key="common.title33"/></a>
</div>
</footer>
</body>
</html>

action class
--------------

package classes.newuser;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionFormBean;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.ValidatorPlugIn;
import org.apache.struts.validator.validwhen.ValidWhen;

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


private static final String SUCCESS = "success";


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

NewUserForm nsf=(NewUserForm)form;

String firstname=nsf.getFirstname();
String lastname=nsf.getLastname();
String gender=nsf.getGender();
String dateofbirth=nsf.getDateofbirth();
String emailid=nsf.getEmailid();
//String email=request.getParameter("emailid");
String username=nsf.getUsername();
String password=nsf.getPassword();
String confirmpassword=nsf.getConfirmpassword();

try{



String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();

//String email=request.getParameter("emailid").toString();
System.out.println(emailid);
ResultSet rs=st.executeQuery("select emailid from registration where emailid='"+emailid+"'");
int count=0;
while(rs.next()){

String email=rs.getString("emailid");
System.out.println("email=============="+email);
count++;
}


if(count>0){

ActionErrors errors=new ActionErrors();
errors.add("emailid", new ActionMessage("NewUserForm.emailid.alreadyexists"));

}

else{

String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);

}

}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return mapping.findForward(SUCCESS);
}
/* public ActionErrors validate(ActionMapping mapping, HttpServletRequest request){

ActionErrors errors=new ActionErrors();

errors.add("emailid",new ActionError(error.emailid.wrong));
return errors;
}*/

}

action form
--------------

package classes.newuser;

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;

public class NewUserForm extends org.apache.struts.validator.ValidatorForm {


private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;

public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;


}

/*public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

return errors;
}*/
}

Thanks in advance
Parthiban

7 years ago
I have solved it
7 years ago
Hi Joe Ess,

Sorry i wrongly posted the code. I forget to change the text. From this code what problem i am facing is, the datas what i have entered is not updated in database, but after pressing register button the page is forwarding to success page. Till day before yesterday the datas are updated in database but today i executed the code its not working. I don't know where the problem. Can you help me.

Thanks in advance
parthiban.t
7 years ago
In struts1 how to check whether the entered email id is already exists in database or not. If it already exists we have to display an error message saying that the email id already exists. Can anyone help. Here i had attached my code.

jsp code
-----------

<!DOCTYPE html>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%--<%@taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>--%>
<%--<%@taglib uri="/struts-tags" prefix="s" %>--%>
<html lang="en">

<head>
<title><bean:message key="newuser.title1"/></title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<!--[if lt IE 7]>
<link rel="stylesheet" href="css/ie/ie6.css" type="text/css" media="screen">
<script type="text/javascript" src="js/ie_png.js"></script>
<script type="text/javascript">
ie_png.fix('.png, .logo img, .nav-box ul li, .list1 li');
</script>
<![endif]-->
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<![endif]-->
</head>

<body id="page7">
<table id="login-form">
<html:form action="/NewUserForm" styleId="login-form">
<fieldset>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title2"/>
</td>
<td>
<html:text property="firstname"/>
</td>
<td>
<html:errors property="firstname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title3"/>
</td>
<td>
<html:text property="lastname"/>
</td>
<td>
<html:errors property="lastname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title4"/>
</td>
<td>
<html:radio property="gender" value="Male">Male</html:radio>
<html:radio property="gender" value="Female">Female</html:radio>
</td>
<td>
<html:errors property="gender"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title5"/>
</td>
<td>
<html:text property="dateofbirth"/>
</td>
<td>
<html:errors property="dateofbirth"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title6"/>
</td>
<td>
<html:text property="emailid"/>
</td>
<td>
<html:errors property="emailid"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title1"/>
</td>
<td>
<html:text property="username"/>
</td>
<td>
<html:errors property="username"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title2"/>
</td>
<td>
<html:password property="password"/>
</td>
<td>
<html:errors property="password"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="newuser.title7"/>
</td>
<td>
<html:password property="confirmpassword"/>
</td>
<td>
<html:errors property="confirmpassword"/>
</td>
</tr>
</div>
<div class="wrapper">
<tr>
<td colspan="3">
<html:submit value="REGISTER" styleId="submit"/>
</td>
</tr>
</div>
</fieldset>
</html:form>
</table>
<!-- footer -->
<footer>
<div class="container">
<a href=""><bean:message key="common.title31"/></a> <bean:message key="common.title32"/> <a href=""><bean:message key="common.title33"/></a>
</div>
</footer>
</body>
</html>

Action Class
---------------

package classes.newuser;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionFormBean;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.ValidatorPlugIn;
import org.apache.struts.validator.validwhen.ValidWhen;


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


private static final String SUCCESS = "success";


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

NewUserForm nsf=(NewUserForm)form;

String firstname=nsf.getFirstname();
String lastname=nsf.getLastname();
String gender=nsf.getGender();
String dateofbirth=nsf.getDateofbirth();
String emailid=nsf.getEmailid();
String username=nsf.getUsername();
String password=nsf.getPassword();
String confirmpassword=nsf.getConfirmpassword();

try{

String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();
String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return mapping.findForward(SUCCESS);
}

}

Action Form
---------------


package classes.newuser;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;


public class NewUserForm extends org.apache.struts.validator.ValidatorForm {


private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;
private String action="register";


public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;
this.action="register";

}

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

return errors;
}
}

Validation.xml
-----------------

<form name="NewUserForm">
<field property="firstname" depends="required,mask">
<msg name="mask" key="NewUserForm.firstname.mask"/>
<arg key="NewUserForm.firstname"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
</field>
<field property="lastname" depends="required,mask">
<msg name="mask" key="NewUserForm.lastname.mask"/>
<arg key="NewUserForm.lastname"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
</field>
<field property="gender" depends="required">
<msg name="required" key="NewUserForm.gender"/>
</field>
<field property="dateofbirth" depends="required,date">
<msg name="date" key="NewUserForm.dateofbirth.date"/>
<arg key="NewUserForm.dateofbirth"/>

<var>
<var-name>datePattern</var-name>
<var-value>dd-MM-yy</var-value>
</var>
</field>
<field property="emailid" depends="required,email">
<msg name="email" key="NewUserForm.emailid.email"/>
<arg key="NewUserForm.emailid"/>
</field>
<field property="username" depends="required">
<arg key="NewUserForm.username"/>
</field>
<field property="password" depends="required,mask,minlength">
<msg name="mask" key="NewUserForm.password.mask"/>
<arg key="NewUserForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
<arg1 key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
<field property="confirmpassword" depends="validwhen">
<!-- <arg key="NewUserForm.confirmpassword"/> -->
<msg name="validwhen" key="NewUserForm.confirmpassword.validwhen"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == password)</var-value>
</var>
</field>

</form>



Thanks
parthiban
7 years ago
Hi,

In struts1 how to check whether the entered email id is already exists in database or not. If it already exists we have to display an error message saying that the email id already exists. Can anyone help. Here i had attached my code.

jsp code
-----------

<!DOCTYPE html>
<%@page contentType="text/html"%>
<%@page pageEncoding="UTF-8"%>

<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logic" prefix="logic" %>
<%--<%@taglib uri="http://struts.apache.org/tags-tiles" prefix="tiles" %>--%>
<%--<%@taglib uri="/struts-tags" prefix="s" %>--%>
<html lang="en">

<head>
<title><bean:message key="newuser.title1"/></title>
<meta charset="utf-8">
<link rel="stylesheet" href="css/reset.css" type="text/css" media="all">
<link rel="stylesheet" href="css/layout.css" type="text/css" media="all">
<link rel="stylesheet" href="css/style.css" type="text/css" media="all">
<!--[if lt IE 7]>
<link rel="stylesheet" href="css/ie/ie6.css" type="text/css" media="screen">
<script type="text/javascript" src="js/ie_png.js"></script>
<script type="text/javascript">
ie_png.fix('.png, .logo img, .nav-box ul li, .list1 li');
</script>
<![endif]-->
<!--[if lt IE 9]>
<script type="text/javascript" src="js/html5.js"></script>
<![endif]-->
</head>

<body id="page7">
<table id="login-form">
<html:form action="/NewUserForm" styleId="login-form">
<fieldset>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title2"/>
</td>
<td>
<html:text property="firstname"/>
</td>
<td>
<html:errors property="firstname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title3"/>
</td>
<td>
<html:text property="lastname"/>
</td>
<td>
<html:errors property="lastname"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title4"/>
</td>
<td>
<html:radio property="gender" value="Male">Male</html:radio>
<html:radio property="gender" value="Female">Female</html:radio>
</td>
<td>
<html:errors property="gender"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title5"/>
</td>
<td>
<html:text property="dateofbirth"/>
</td>
<td>
<html:errors property="dateofbirth"/>
</td>
</tr>
</div>
<div class="field">
<tr>
<td>
<bean:message key="newuser.title6"/>
</td>
<td>
<html:text property="emailid"/>
</td>
<td>
<html:errors property="emailid"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title1"/>
</td>
<td>
<html:text property="username"/>
</td>
<td>
<html:errors property="username"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="common.title2"/>
</td>
<td>
<html:password property="password"/>
</td>
<td>
<html:errors property="password"/>
</td>
</tr>
</div>
<div>
<tr>
<td>
<bean:message key="newuser.title7"/>
</td>
<td>
<html:password property="confirmpassword"/>
</td>
<td>
<html:errors property="confirmpassword"/>
</td>
</tr>
</div>
<div class="wrapper">
<tr>
<td colspan="3">
<html:submit value="REGISTER" styleId="submit"/>
</td>
</tr>
</div>
</fieldset>
</html:form>
</table>
<!-- footer -->
<footer>
<div class="container">
<a href=""><bean:message key="common.title31"/></a> <bean:message key="common.title32"/> <a href=""><bean:message key="common.title33"/></a>
</div>
</footer>
</body>
</html>

Action Class
---------------

package classes.newuser;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts.action.Action;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionFormBean;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionRedirect;
import org.apache.struts.action.ActionServlet;
import org.apache.struts.validator.FieldChecks;
import org.apache.struts.validator.ValidatorPlugIn;
import org.apache.struts.validator.validwhen.ValidWhen;


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


private static final String SUCCESS = "success";


public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {

NewUserForm nsf=(NewUserForm)form;

String firstname=nsf.getFirstname();
String lastname=nsf.getLastname();
String gender=nsf.getGender();
String dateofbirth=nsf.getDateofbirth();
String emailid=nsf.getEmailid();
String username=nsf.getUsername();
String password=nsf.getPassword();
String confirmpassword=nsf.getConfirmpassword();

try{

String url="jdbc:mysql://localhost:3306/nemogroups";
Class.forName("com.mysql.jdbc.Driver");
Connection con= DriverManager.getConnection(url, "root" ,"root" );
Statement st=con.createStatement();
String insert="insert into registration(firstname,lastname,gender,dateofbirth,emailid,username,password,confirmpassword) values('"+firstname+"','"+lastname+"','"+gender+"','"+dateofbirth+"','"+emailid+"','"+username+"','"+password+"','"+confirmpassword+"')";
st.executeUpdate(insert);
}
catch (Exception e) {
// TODO: handle exception
System.out.println(e);
}
return mapping.findForward(SUCCESS);
}

}

Action Form
---------------


package classes.newuser;

import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionMapping;


public class NewUserForm extends org.apache.struts.validator.ValidatorForm {


private static final long serialVersionUID = 1L;
private String firstname=null;
private String lastname=null;
private String gender=null;
private String dateofbirth=null;
private String emailid=null;
private String username=null;
private String password=null;
private String confirmpassword=null;
private String action="register";


public String getAction() {
return action;
}

public void setAction(String action) {
this.action = action;
}

public String getConfirmpassword() {
return confirmpassword;
}

public String getDateofbirth() {
return dateofbirth;
}

public String getEmailid() {
return emailid;
}

public String getFirstname() {
return firstname;
}

public String getGender() {
return gender;
}

public String getLastname() {
return lastname;
}

public String getPassword() {
return password;
}

public String getUsername() {
return username;
}

public void setConfirmpassword(String confirmpassword) {
this.confirmpassword = confirmpassword;
}

public void setDateofbirth(String dateofbirth) {
this.dateofbirth = dateofbirth;
}

public void setEmailid(String emailid) {
this.emailid = emailid;
}

public void setFirstname(String firstname) {
this.firstname = firstname;
}

public void setGender(String gender) {
this.gender = gender;
}

public void setLastname(String lastname) {
this.lastname = lastname;
}

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

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

public void reset(ActionMapping mapping,HttpServletRequest request){

this.firstname=null;
this.lastname=null;
this.gender=null;
this.dateofbirth=null;
this.emailid=null;
this.username=null;
this.password=null;
this.confirmpassword=null;
this.action="register";

}

public ActionErrors validate(ActionMapping mapping,HttpServletRequest request){

ActionErrors errors=new ActionErrors();

return errors;
}
}

Validation.xml
-----------------

<form name="NewUserForm">
<field property="firstname" depends="required,mask">
<msg name="mask" key="NewUserForm.firstname.mask"/>
<arg key="NewUserForm.firstname"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
</field>
<field property="lastname" depends="required,mask">
<msg name="mask" key="NewUserForm.lastname.mask"/>
<arg key="NewUserForm.lastname"/>
<var>
<var-name>mask</var-name>
<var-value>^[a-zA-Z]*$</var-value>
</var>
</field>
<field property="gender" depends="required">
<msg name="required" key="NewUserForm.gender"/>
</field>
<field property="dateofbirth" depends="required,date">
<msg name="date" key="NewUserForm.dateofbirth.date"/>
<arg key="NewUserForm.dateofbirth"/>

<var>
<var-name>datePattern</var-name>
<var-value>dd-MM-yy</var-value>
</var>
</field>
<field property="emailid" depends="required,email">
<msg name="email" key="NewUserForm.emailid.email"/>
<arg key="NewUserForm.emailid"/>
</field>
<field property="username" depends="required">
<arg key="NewUserForm.username"/>
</field>
<field property="password" depends="required,mask,minlength">
<msg name="mask" key="NewUserForm.password.mask"/>
<arg key="NewUserForm.password"/>
<var>
<var-name>mask</var-name>
<var-value>^[0-9a-zA-Z]*$</var-value>
</var>
<arg1 key="${var:minlength}" resource="false"/>
<var>
<var-name>minlength</var-name>
<var-value>6</var-value>
</var>
</field>
<field property="confirmpassword" depends="validwhen">
<!-- <arg key="NewUserForm.confirmpassword"/> -->
<msg name="validwhen" key="NewUserForm.confirmpassword.validwhen"/>
<var>
<var-name>test</var-name>
<var-value>(*this* == password)</var-value>
</var>
</field>

</form>



Thanks
parthiban
7 years ago
Hi,

In struts1 how to check whether the entered email id is already exists in database or not. If it already exists we have to display an error message saying the the email id already exists. Can anyone help.


Thanks
parthiban

7 years ago
Have you found solution for this problem
7 years ago
in struts 2 how to get the values from db and show in jsp using display tag or iterator tag
7 years ago
Hi All,



<table class="col-1">
<html:form action="/clientsForm" styleId="contacts-form">
<tr>
<td>
<bean:message key="clientscomment.title3"/><br/>
</td>
<td>
<html:text property="name"/>
</td>
<td>
<html:errors property="name"/><br/>
</td>
</tr>
<tr>
<td>
<bean:message key="clientscomment.title8"/>

</td>
<td>

<html:select property="typeofbusiness" onchange="call(this);">

<html:option value="">Select TypeofBusiness</html:option>
<html:option value="1"><%="NemoTravels"%></html:option>
<html:option value="2">NemoHotels</html:option>
<html:option value="3">NemoCorporateTravels</html:option>
<html:option value="4">NemoAgriCulture</html:option>
<html:option value="5"><%="NemoConstructions"%></html:option>
<html:option value="6">NemoFoundation</html:option>
<html:option value="7">NemoItSolutions</html:option>
<html:option value="8">Nemo</html:option>
<html:option value="9">Nemo</html:option>
<html:option value="10">Nemo</html:option>
<html:option value="11">Nemo</html:option>

</html:select>
</td>

<td>
<html:errors property="typeofbusiness"/><br/>

</td>
</tr>

<tr>
<td colspan="3">
<select id="combo" name="combo2"/>
<%--<html:select property="typeofbusiness" onfocus="combo" onchange="combo2" />--%>
</td>
</tr>
<tr>
<td>
<bean:message key="clientscomment.title4"/>
</td>
<td>

<html:text property="email" />
</td>
<td>
<html:errors property="email"/>
</td>
</tr>
<tr>
<td>
<bean:message key="clientscomment.title7"/>
</td>
<td>
<html:text property="contactno" />
</td>
<td>
<html:errors property="contactno"/>
</td>
</tr>
<tr>
<td>
<bean:message key="clientscomment.title5"/><br/>
</td>
<td>
<html:text property="state" />
</td>
<td>
<html:errors property="state"/>
</td>
</tr>
<tr>
<td>
<bean:message key="clientscomment.title6"/>
</td>
<td>
<html:textarea property="message" />
</td>
<td>
<html:errors property="message"/>
</td>
</tr>
<tr class="wrapper">
<td colspan="3">
<html:submit value="SUBMIT" styleId="submit"/>
</td>
</tr>
</html:form>
</table>


in the above code hot to convert this code <select id="combo" name="combo2"/> to <html:select>

can any one help me

thanks in advance
parthiban
8 years ago
Hi All,


I need a help for drop down list box.
I have to show new drop down list box if a particular option is selected.
For Eg: iam having 5 options travels,hotels,education,foundation,corporate solutions.
here for particular option i may have some other option to chose
for Eg: for travels i may have sub types car,bus and for education- school,college.
if travels or education option is selected new drop down box should be shown
and if other options or selected no drop down box should be displayed.



can any one help me.

thanks in advance
parthi
8 years ago