wood burning stoves 2.0*
The moose likes Struts and the fly likes not validating Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "not validating" Watch "not validating" New topic
Author

not validating

vinayGuddu Pandey
Ranch Hand

Joined: Aug 02, 2012
Posts: 30
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


vinay
vinayGuddu Pandey
Ranch Hand

Joined: Aug 02, 2012
Posts: 30
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: not validating
 
Similar Threads
validation using Resource Bundle
Struts 2 error
struts2 simple program, but Error 500--Internal Server Error
Location for ActionClass-validation.xml in web directory structure.
error in validation