title: How to display errors in jsp using spring mvc
body: <p>I am unable to got error message in jsp page.Actually, i trying to check the username and password is correct or not in database.Iam thrown dataexception from dao and catch at controller check the below code</p>
  
  <p><strong>SimpleFormController</strong></p>
  
  <pre><code>public ModelAndView onSubmit(HttpServletRequest request, HttpServletResponse response,Object command,BindException errors) throws Exception {
  
          log.info("onSubmit handleRequest method"+request.getParameter("username"));
          boolean isError=false;
          String username="",password="",errMessage="";
          username=request.getParameter("username");
          password=request.getParameter("password");
  
          UserBean ubean=null;
          try{
               ubean=userservice.chkUsername(username,password);
          }catch(DataException ex){
  
              errMessage=ex.getMessage();
              isError=true;
              //throw ex;
          }
          if(isError==true){
              System.out.println("errMessage handleRequest method"+errMessage);
              errors.reject(errMessage);
              return showForm(request, response, errors);
          }
          log.info("After shownform method called");
          HttpSession session=request.getSession(true);
          session.setAttribute("User",ubean);
          return  new ModelAndView("UserPage");
          }
  
  
  
  public ModelAndView showForm(HttpServletRequest request, HttpServletResponse response,BindException errors) throws Exception {
                   //Displaying Count size
      log.info("Show form Error Count"+errors.getErrorCount()+getFormView());
      return new ModelAndView(getFormView());
  }
  </code></pre>
  
  <p>Iam trying to display in two ways in jsp page i.e.,</p>
  
  <p><strong>Jsp Page:-</strong></p>
  
  <pre><code>1)
                  &lt;spring:hasBindErrors name="UserBean"&gt;
                       &lt;h3&gt;You have errors in your input!&lt;/h3&gt;  
      &lt;font color="red"&gt;  
                      &lt;c:forEach items="${errors.allErrors}" var="error"&gt;  
       &lt;spring:message code="${error.code}" text="${error.defaultMessage}"/&gt;  
      &lt;/c:forEach&gt;  
      &lt;/font&gt;  
                     &lt;/spring:hasBindErrors&gt;
  2) &lt;form:form action="userpage.htm" method="post"  onsubmit="javascript:fun()"&gt;
                      &lt;tr&gt;
                       &lt;form:errors path="*"/&gt; 
                        --------
                         --------
    &lt;/form:form&gt;
  </code></pre>
  
  <p>i trying to dispaying above two ways in jsp.But finally i didn't got any thing.is there any issues with above code.plz help me</p>