How to show error on JSP

I am using Struct framework in building JSP, and I am very new on Struct framework.


            <form name="user">
                  <field property="userName" depends="required,minlength,maxlength">
                        <arg0 key="aaa"/>
                        <arg1 key="${var:maxlength}" name="maxlength" resource="false"/>
                        <arg1 key="${var:minlength}" name="minlength" resource="false"/>

            <form-bean name="userRegistrationForm" type="strutsTutorial.UserRegistrationForm"/>
            <action path="/userRegistration" type="strutsTutorial.UserRegistrationAction" name="userRegistrationForm" attribute="user" input="/userRegistration.jsp">
                  <forward name="success" path="/regSuccess.jsp"/>
                  <forward name="failure" path="/regFailure.jsp"/>
      <message-resources parameter=""/>
      <plug-in className="org.apache.struts.validator.ValidatorPlugIn">
            <set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/>

My jsp page is like this
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<title>Untitled Document</title>

<html:form action="userRegistration">
<html:text property="userName"/>

But I don't get the error display on the jsp page after the user click on submit button with blank textbox,
may I know how to correct it?

Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

u r missing validate=true in your action mapping

<action path="/userRegistration" type="strutsTutorial.UserRegistrationAction" name="userRegistrationForm" attribute="user"
validate="true" // missing one
               <forward name="success" path="/regSuccess.jsp"/>
               <forward name="failure" path="/regFailure.jsp"/>
william007Author Commented:
Hi, I just put it, but still no luck.

Do we need to do any thing in the ValidationForm in order to display the error message at <html:errors/>? Or everything is done automatically as long as we set the validation.xml correctly?
validation.xml should be correct. As far as i see, you are not using the resources file to display the message..moreover,
the keys are duplicate

<arg0 key="aaa"/> // what is this for?
<arg1 key="${var:maxlength}" name="maxlength" resource="false"/>
should be arg2 <arg2 key="${var:minlength}" name="minlength" resource="false"/>

Learn SQL Server Core 2016

This course will introduce you to SQL Server Core 2016, as well as teach you about SSMS, data tools, installation, server configuration, using Management Studio, and writing and executing queries.

the action form should extend org.apache.struts.validator.ValidatorActionForm
william007Author Commented:
I have changed that, but still don't see the error to be appeared.
Followed is my Classes
package strutsTutorial;


import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.validator.ValidatorActionForm;

public class UserRegistrationForm extends ValidatorActionForm {

      private static final long serialVersionUID = 1L;

      private String userName;

      public String getUserName() {
            return userName;

      public void setUserName(String string) {
            try {
                  FileOutputStream fout = new FileOutputStream("c:\\log.txt");

                  // Print a line of text
                  new PrintStream(fout).println("hello world!");

                  // Close our output stream
            } catch (Exception e) {


            userName = string;
package strutsTutorial;

import org.apache.struts.action.Action;

public class UserRegistrationAction extends Action {
//Nothing for the moment      

the depends property is case sensitive... u should use
<field property="userName" depends="required,minLength,maxLength">
                    <arg0 key="${var:maxLength}" name="maxlength" resource="false"/>
                    <arg1 key="${var:minLength}" name="minlength" resource="false"/>
william007Author Commented:
Thanks, fargo.
Actually all the things is correct, other then
<message-resources parameter="" />
I should change it to
<message-resources parameter="MessageResources" />
as we do not need to include the properties extension.

Let me elaborate one by one
>>u r missing validate=true in your action mapping
I think it is by default, as I delete it still ok

>><arg1 key="${var:maxlength}" name="maxlength" resource="false"/>
>>should be arg2 <arg2 key="${var:minlength}" name="minlength" resource="false"/>
Actually nothing wrong here, since in the resource file
errors.maxlength={0} can not be greater than {1} characters.
errors.minlength={0} can not be less than {1} characters.


Very appreciate for your effort:-)

But since I have answered it myself, I would like to PAQ this question.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
good that you solve the problem!
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.