• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

not validating

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have created one project in netbeans...
files are :--
index.jsp;
success.jsp;
struts.xml;
web.xml;
Employee-Validation.xmland one class Employee.java
now when i am running the project after submitting the form it should validate all fields but it is not validating directly it is submitting the form without validation.


this is index.jsp
<html>
<body>
<h2>Registration </h2>
<s:form action="empinfo" method="POST">
<s:textfield name="username" label="Username "/>
<s:password name="password" label="Password "/>
<s:password name="confirmPassword" label="Confirm Password "/>
<s:textfield name="email" label="Email Address " />
<s:textfield name="mobile" label="Mobile Number " />
<p/>
<s:submit value="Register"/>
<p/>
<s:actionerror/>
</s:form>
</body>
</html>

this is success.jsp

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Registration Completed</title>
</head>
<body>
Thank you <s:property value="username"/> for registering.
</body>
</html>

this is Employee-Validation.xml file

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE validators PUBLIC
"-//OpenSymphony Group//XWork Validator 1.0.2//EN"
"http://www.opensymphony.com/xwork/xwork-validator-1.0.2.dtd">
<validators>
<field name="username">
<field-validator type="requiredstring">
<message>Username is required </message>
</field-validator>
</field>
<field name="password">
<field-validator type="requiredstring">
<message>Password is required </message>
</field-validator>

<field-validator type="stringlength">
<param name="minLength">5</param>
<message>Password must contain at least ${minLength} characters</message>
</field-validator>
</field>
<field name="email">
<field-validator type="email">
<message>Email address is not valid</message>
</field-validator>
<field-validator type="requiredstring">
<message>Email address is required!</message>
</field-validator>
</field>

<field name="mobile">
<field-validator type="regex">
<param name="expression">^[0-9]{10}$</param>
<message>Mobile number must be of 10 digits</message>
</field-validator>
</field>

<validator type="expression">
<param name="expression">password == confirmPassword</param>
<message>Password and confirm password do not match!</message>
</validator>
</validators>

this is employee.java
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package com.valiadtor.form.vinay;

/**
*
* @author dell
*/
import com.opensymphony.xwork2.ActionSupport;
public class Employee extends ActionSupport {
private String username,password,confirmPassword,email,mobile;
public String getConfirmPassword() {
return confirmPassword;
}
public void setConfirmPassword(String confirmPassword) {
this.confirmPassword = confirmPassword;
}
public String getEmail() {
return email;
}
public void setEmail(String email) {
this.email = email;
}
public String getMobile() {
return mobile;
}
public void setMobile(String mobile) {
this.mobile = mobile;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
public Employee() {
}
public String execute() throws Exception {
// do the required process
return "success";
}
}

this is web.xml
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">

<display-name>Struts 2</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>

<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>

<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>

this is struts.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">

<struts>
<constant name="struts.devMode" value="true" />
<package name="helloworld" extends="struts-default">
<action name="empinfo" class="com.valiadtor.form.vinay.Employee">
<result name="success">/success.jsp</result>
<result name="input">/index.jsp</result>
</action>


</package>

</struts>
please help me ................
and please let me know that whether i need to configure my Employee-Validation.xml in web.xml also or not.
I have placed my Employee-Validation.xml file in the same package of .java
 
vinayGuddu Pandey
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I got the answer, actually java language is a case sensitive so I need to name my Employee-Validation.xml as a Employee-validation.xml ......its running
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!