• 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
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

Struts Validation not working

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I have written below sample program for struts validation attached here. When I submit the form, the validation is not happening. Can anyone take a look and let me know what the issue was.

struts-config.xml


validation.xml



ApplicationResources

errors.suffix=

errors.required='{0} is required'.
errors.minlength='{0} can not be less than {1} characters'.
errors.range='{0} is not in the range {1} through {2}'.

exampleForm.name=Name
exampleForm.age=Age


web.xml



ExampleAction.java



Ex1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<head>
<title>JSP for exampleForm</title>
</head>
<body bgcolor="cyan">
<center>
<html:form action="example1.do">
<html:errors/>
Name : <html:text property="name" />

Age : <html:text property="age" />

<html:submit value="Send"/>
</html:form>
</center>
</body>
</html>


Ex2.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
<html>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<head>
<title>JSP for exampleForm</title>
</head>
<body bgcolor="yellow">
<center>
<html:form action="example2.do">
<html:errors/>
Name : <html:text property="name" />

Age : <html:text property="age" />

<html:submit value="Send"/>
</html:form>
</center>
</body>
</html>



 
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Suresh,

Please check validation.xml you shown in your post, please correct it.
 
kalle suresh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the correction under validation.xml
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It is struts-config.xml you placed in place of validation.xml.
 
kalle suresh
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

By mistake I placed the struts-config.xml twice. Below attached is my validation.xml

 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you put validator-rules.xml xml in your WEB-INF as you mentioned in struts-config.xml.

you can get nice example for validator framework HERE
 
I didn't say it. I'm just telling you what this tiny ad said.
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic