Win a copy of Micro Frontends in Action this week in the Server-Side JavaScript and NodeJS forum!
  • 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
  • Paul Clapham
  • Bear Bibeault
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Tim Cooke
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Jj Roberts
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • salvin francis
  • Scott Selikoff
  • fred rosenberger

Struts Validation not working

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
What is the correction under validation.xml
 
Shailesh Narkhede
Ranch Hand
Posts: 368
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
 
If somebody says you look familiar, tell them you are in porn. Or in these tiny ads:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic