How To Display Error Message In Jsp Using Struts
This Site Careers Other all forums Forum: Struts how to display error messages in jsp sanjeev katthi Greenhorn Posts: 19 posted 8 years ago hai,I have a webapplication,using servlets and jsp's.In login page, i have to show validation error messages,like in struts.how can i do this? Is it possible using struts provided html taglibrary?or is there any other taglibraries to achieve this functionality.Please help me. Thanks in advance. Bear Bibeault Author and ninkuma Marshal Posts: 65271 95 I like... posted 8 years ago Please be sure to post Struts questions in the Struts forum. I've moved this there for you. [Asking smart questions] [About Bear] [Books by Bear] Niklas Rosencrantz Ranch Hand Posts: 49 posted 8 years ago The standard way to do it is with struts html:errors like this: <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> Of course, your form needs to be a struts form for this to work. Regards, Niklas R Post Reply Bookmark Topic Watch Topic New Topic Similar Threads How to handle 'Success Messages' in Spring MVC in a manner similar to 'Error Messages' Form Bean Error Struts Validator Messages Property Messages displayed only if I use saveErrors() Returning Custom data type from a web service All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter Contact Us | advertise | mobile view | Powered by JForum | Copyright © 1998-2016 Paul Wheaton
& JSP Hibernate Ajax SOAP Web Services Core Java JDBC Tutorial XLS -XLSX -CSV I/O FTP in Java Soap-UI SOAPUI Tutorials Soap UI Updates Home » Struts 1 » ActionError & ActionMessage Example in Struts 2 ActionError & ActionMessage Example in Struts 2 Posted by Mohaideen Jamil on Apr 18, 2013 in Struts 1, Struts 2 Tutorial, Struts-2 | 5 comments In this tutorial we will learn about ActionError & ActionMessage class and its usage. a) https://coderanch.com/t/58282/Struts/display-error-messages-jsp ActionError class is used to send error feedback message to user and it get rendered in jsp by using tag. b) ActionMessage class - is used to send information feedback message to user, and it get rendered in jsp using tag. ** UPDATE: Struts 2 Complete tutorial now available here. In this http://www.simplecodestuffs.com/struts-2-actionerror-actionmessage-example/ tutorial we will use the previous tutorials example to implement the functionality of ActionError and ActionMessage class. Here’s a simple login form, display the error message (actionerror) if the username is empty, Otherwise redirect to another page and display the a welcome message (actionmessage). 1. Folder Structure Action Class The action class, do a simple checking to make sure that the username is not empty, if the userName is not valid then the action class set the error message with addActionError() , if its valid then it set the successful message with addActionMessage(). package com.action; import com.opensymphony.xwork2.ActionSupport; public class LoginAction extends ActionSupport { private static final long serialVersionUID = 6677091252031583948L; private String userName; public String execute() { return SUCCESS; } public String getUserName() { return userName; } public void setUserName(String userName) { this.userName = userName; } public void validate() { if (userName.isEmpty()) { addActionError("Username can't be blanked"); } else { addActionMessage("Welcome " + userName + ", You have been Successfully Logged in"
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more http://stackoverflow.com/questions/16506852/struts-error-message-not-getting-displayed-in-ui about Stack Overflow the company Business Learn more about hiring developers or posting ads http://stackoverflow.com/questions/16672435/displaying-validation-error-messages-in-struts2 with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Struts Error Message not getting Displayed in UI up vote 0 down how to vote favorite I am using Struts 1.2 for my application. I have a validate method for my form where I am doing some validation for the inputs provided by the user. Below is the code for the userName provided by the user: @Override public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { System.out.println("Validating the Form..."); ActionErrors errors = new ActionErrors(); if(userName != null && userName.length() <= 0) errors.add("userName",new ActionError("Invalid UserName")); return errors; how to display } If the userName is not wntered by the user, then the above error message should be displayed in the UI. Below is the code I used in the jsp file for displaying the above error message: But it did not displayed any error message. I also tried this alternative but this also did not worked.: When I try debugging the code, the validate method is getting executed in the form and the execute method is not triggered since there are validation errors. In the UI, no error message is getting displayed. Kindly let me know how to fix this. java struts struts-1 struts-validation struts-action share|improve this question asked May 12 '13 at 11:25 user182944 1,7081652119 add a comment| 1 Answer 1 active oldest votes up vote 2 down vote accepted ActionError does not take the error message itself. Instead, it takes a key to the error message in the application's MessageResources bundle. From the Struts documentation on Automatic Form Validation: Return an ActionErrors instance containing ActionMessage's, which are classes that contain the error message keys (into the application's MessageResources bundle) that should be displayed. So, you should do something li
here for a quick overview of the site Help Center Detailed answers to any questions you might have Meta Discuss the workings and policies of this site About Us Learn more about Stack Overflow the company Business Learn more about hiring developers or posting ads with us Stack Overflow Questions Jobs Documentation Tags Users Badges Ask Question x Dismiss Join the Stack Overflow Community Stack Overflow is a community of 4.7 million programmers, just like you, helping each other. Join them; it only takes a minute: Sign up Displaying Validation Error Messages in Struts2 up vote 1 down vote favorite 1 I am new to Struts 2, have worked in Struts 1 earlier. How can we bind a error message with a UI component (e.g. a Text box) ? I don't want the error message to be a global one. For achieving the same in Struts 1: In the form validate method, I used this: ActionErrors errors = new ActionErrors(); if(userName != null && userName.length() <= 0) errors.add("userName",new ActionError("error.userName.required")); and in the UI, for displaying the message: In Struts 2, If I extend the Action class with ActionSupport and use this: addActionError(getText("Please enter UserId")); Then it seems to be a global message which can be displayed in the UI using: Hence not sure how to achieve the same functionality in Struts 2. Kindly let me know on this. java web struts2 struts share|improve this question asked May 21 '13 at 14:22 user182944 1,7081652119 add a comment| 1 Answer 1 active oldest votes up vote 4 down vote accepted The tag would be the closest equivalent: On the Java side you'd use ValidationAware.addFieldError to add field-specific messages: public class AnyAction extends ActionSupport { public void validate() { addFieldError("userName", "User ID is required"); } } That said, for the low-level validations, I'd stick to the default XML-based mechanism when possible, since it does a lot of this work for you, and makes working with I18N/properties a little easier. share|improve this answer answered May 21 '13 at 15:46 Dave Newton 119k13162195 Thanks for the reply. If I us addFieldError in the java file and don't use any in the jsp file, then also the error message is getting displayed. And if I use the in the jsp along with the addFieldError in the java file, then some of the error messages are getting repeated. Why this sort of behavior? Also the UI is getting scrapped while displaying the messages :( –user182944 May 21 '13 at 16: