Note that there are some explanatory texts on larger screens.

plurals
  1. POThe problems in error handling using Struts validation framework
    text
    copied!<p>I have following defined in </p> <h3>struts-config.xml:</h3> <pre class="lang-xml prettyprint-override"><code>&lt;struts-config&gt; &lt;form-beans&gt; &lt;form-bean name="LoginForm" type="com.actionform.LoginForm"/&gt; &lt;/form-beans&gt; &lt;action-mappings&gt; &lt;!-- action for login --&gt; &lt;action input="/views/login.jsp" name="LoginForm" path="/Login" scope="session" type="com.actions.LoginAction" parameter="method" validate="true"&gt; &lt;forward name="success" path="/views/Frameset.html" /&gt; &lt;/action&gt; &lt;/action-mappings&gt; &lt;message-resources parameter="/WEB-INF/ApplicationResources"/&gt; &lt;!-- ========================= Validator plugin ================================= --&gt; &lt;plug-in className="org.apache.struts.validator.ValidatorPlugIn"&gt; &lt;set-property property="pathnames" value="/WEB-INF/validator-rules.xml,/WEB-INF/validation.xml"/&gt; &lt;/plug-in&gt; &lt;/struts-config&gt; </code></pre> <h3>The login form:</h3> <pre><code>public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { ActionErrors errors = new ActionErrors(); if (userName == null || userName.length() &lt; 1) { System.out.println("in validate ---"); errors.add("userName", new ActionMessage("error.userName.required")); // TODO: add 'error.name.required' key to your resources } if (password == null || password.length() &lt; 1) { errors.add("password", new ActionMessage("error.password.required")); // TODO: add 'error.name.required' key to your resources } return errors; } </code></pre> <h3>login.jsp:</h3> <pre class="lang-xml prettyprint-override"><code>&lt;html:form action="/Login?method=loginUser"&gt; &lt;html:errors/&gt; &lt;html:text name="LoginForm" property="userName" /&gt; &lt;html:messages id="err_userName" property="userName"&gt; &lt;bean:write name="err_userName" /&gt; &lt;/html:messages&gt; &lt;/html:form&gt; </code></pre> <h3>Property file:</h3> <pre><code>error.userName.required = User Name is required. error.password.required = Password is required. </code></pre> <p>Where am I doing wrong? I am getting the following error</p> <pre><code>javax.servlet.jsp.JspException: Cannot find bean error in any scope </code></pre> <p>I just want to display the error in the same JSP. </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload