Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7796083
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T23:15:45+00:00 2026-06-01T23:15:45+00:00

I have problem with displaying error message in spring Application.i am using Spring MVC

  • 0

I have problem with displaying error message in spring Application.i am using Spring MVC 3 and Apache Tiles. when i am having error in form than it will not displays error message.
please help me hear is the piece of code.

Web.xml

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
  <display-name>SpringExample</display-name>
  <welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
  </welcome-file-list>
  <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>
            org.springframework.web.servlet.DispatcherServlet
        </servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>
                /WEB-INF/spring/dispatcher-servlet.xml
            </param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>  

</web-app>  

dispatcher-Servlet.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xsi:schemaLocation="http://www.springframework.org/schema/beans
        http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
        http://www.springframework.org/schema/context
        http://www.springframework.org/schema/context/spring-context-3.0.xsd">

    <context:component-scan base-package="com.examples.spring" />


    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>

    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>


</beans>

tiles.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE tiles-definitions PUBLIC
       "-//Apache Software Foundation//DTD Tiles Configuration 2.0//EN"
       "http://tiles.apache.org/dtds/tiles-config_2_0.dtd">
<tiles-definitions>


    <definition name="create_account_success" template="/WEB-INF/jsp/account/SuccessJSP.jsp">
    </definition>

    <definition name="account_create" template="/WEB-INF/jsp/account/testForm.jsp">

    </definition>


</tiles-definitions>

testForm.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
    <%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
    <form:form id="form" modelAttribute="formCreate" method="post">
    <table>
        <tr>
            <td>Name :</td>
            <td><form:input path="name"/>
                <form:errors path="name"/>
            </td>
        </tr>
        <tr>
            <td>Password :</td>
            <td><form:input path="password"/>
                <form:errors path="password"/>
            </td>
        </tr>
        <tr>
            <td colspan="2"><input type="submit" /></td>
        </tr>
    </table>
    </form:form>
</body>
</html>

AccountRegistrationController.java

package com.examples.spring.controller;

import org.springframework.stereotype.Controller;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.servlet.ModelAndView;

import com.examples.spring.dto.AccountDTO;
import com.examples.spring.validator.AccountValidator;

@Controller
public class AccountRegistrationController {


    public static final String BASE_URL = "/account";

    @RequestMapping(value = BASE_URL + "/create" ,method = RequestMethod.GET)
    public ModelAndView accountCreate(){
        ModelAndView view = new ModelAndView();
        view.addObject("formCreate", new AccountDTO());
        view.setViewName("account_create");
        return view;
    }

    @RequestMapping(value = BASE_URL + "/create" ,method = RequestMethod.POST)
    public ModelAndView accountRegistration(@ModelAttribute AccountDTO accountDTO,BindingResult result ){

        ModelAndView view = new ModelAndView();

        AccountValidator validator = new AccountValidator();
        validator.validate(accountDTO, result);
        if (result.hasErrors()) {
            view.setViewName("account_create");
            view.addObject("formCreate", accountDTO);
            return view;
        }
        view.setViewName("create_account_success");
        return view;
    }

    @RequestMapping(value = BASE_URL + "/login" ,method = RequestMethod.GET)
    public ModelAndView accountLogin(){
        ModelAndView view = new ModelAndView();
        view.setViewName("account_login");
        return view;
    }
}

AccountValidator.java

package com.examples.spring.validator;

import org.springframework.validation.Errors;
import org.springframework.validation.ValidationUtils;
import org.springframework.validation.Validator;

import com.examples.spring.dto.AccountDTO;

public class AccountValidator implements Validator {

    @Override
    public boolean supports(Class<?> clazz) {
        return AccountDTO.class.isAssignableFrom(clazz);
    }

    @Override
    public void validate(Object result, Errors error) {
        AccountDTO accountDTO = (AccountDTO) result;

        ValidationUtils.rejectIfEmpty(error, "name", "require.name", "Name Requires.");
        ValidationUtils.rejectIfEmpty(error, "password", "require.password", "Password Requires.");
    }

}

AccountDTO.java

package com.examples.spring.dto;

public class AccountDTO {


    private String name;
    private String password;

    public AccountDTO() {
        // TODO Auto-generated constructor stub
    }

    public String getName() {
        return name;
    }
    public void setName(String name) {
        this.name = name;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }

}

My Code is working well but it does not displays error messages in <form:errors />.

please help me.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T23:15:47+00:00Added an answer on June 1, 2026 at 11:15 pm

    The third parameter to ValidationUtils.rejectIfEmpty is an error code. It should be a key to the actual message in your resource bundle. I don’t know how it behaves if it can’t find a value. You should change it to use a key, and optionally set a default message. See the api.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Now I have fixed the problem the T_ELSE parse error is not displaying anymore,
I have problem with displaying adsense ads in ie7 google adsense adds an iframe
I have a problem consistently displaying Facebook Comments on my AJAX driven website. Each
I have problem creating new instance of excel 2007 using VBA (from Access 2002).
I have problem with fancybox. I want to write a function that will run
I have a problem displaying validation errors that are triggered by ui components which
I'm writing a messaging application in GWT, and have a fairly difficult problem to
I have an MVC 3 application and am trying to display a custom validation
I have a web-application built with GWT (2.0.3) and run on Apache Tomcat 6.
We have an MS Access 2007 database with a simple form displaying table data.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.