aspose file tools*
The moose likes Struts and the fly likes Show Struts error in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Show Struts error in JSP" Watch "Show Struts error in JSP" New topic
Author

Show Struts error in JSP

Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
In my JSP file I have the request variable org.apache.struts.action.ERROR
But I cannot get the error message.
Whenever I get toString I get the class ID hash.

I need to access the error message in JSTL without using more Struts, but I do not know how.

Edit: I can access the message by <html:errors/>, but I do not want to use Struts tag, only JSTL og perhaps in last resort scriplets.

Somehow this post has been duplicated many times and not by my doing.
[ December 05, 2007: Message edited by: Sverre Moe ]
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
In a Struts application, the best practice is to use the Struts <html:errors /> or <html:messages /> tag to retrieve messages. While I agree that it's a good idea to use JSTL tags whenever there is a JSTL tag that will do the job as well or better than a Struts tag, I do not agree that one should always try to avoid Struts tags when writing a Struts application. In this particular case, the Struts tag does the job much more simply and elegantly than JSTL tags could.

However if you insist that you don't want to use Struts tags, the object you get with the org.apache.struts.action.ERROR key is of type org.apache.struts.action.ActionMessages. This object does not follow the JavaBean standard, and is therefore not easily used by JSTL tags. However, you can use it in a scriptlet. Its get() method returns an Iterator, which you can then use to iterate through the messages, which will be of type org.apache.struts.action.ActionMessage.


Merrill
Consultant, Sima Solutions
Brent Sterling
Ranch Hand

Joined: Feb 08, 2006
Posts: 948
Why the strong aversion to the html:errors tag? I can see using jstl instead of most of the logic tags but it sure seems to me that if you are using Struts without the html tags you are just making more work for yourself.

I would suggest that you take a look at the source code for the html:errors tag. That should point you in the right direction.

- Brent
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Originally posted by Brent Sterling:
Why the strong aversion to the html:errors tag? I can see using jstl instead of most of the logic tags but it sure seems to me that if you are using Struts without the html tags you are just making more work for yourself.

I would suggest that you take a look at the source code for the html:errors tag. That should point you in the right direction.

- Brent


Because I am working on an old application that was developed with Struts and we are now using Spring which we have been using more and more. Still some elements are Struts I have begun to remove the Struts on the JSP and replace it with JSTL wherever possible. This little snag is the only problem I have had so far.
Rahul Nair
Ranch Hand

Joined: Dec 01, 2007
Posts: 138
Hi,
I am using Struts 1.3.8 and Validate my form field using Struts validator Framework ...
In my JSP Page i am using <html:error > tag to display erroe messages in JSP page...This messages is displayed in my Upper side of my JSp page...

But,i want to show the error message near FORM FILED...not Upper Side of Page...

So How can i extract error messages in my page manually or using
<html:error> ???

so that it can be displayed near Field ??
[ December 11, 2007: Message edited by: Rahul Nair ]
Sverre Moe
Ranch Hand

Joined: Jul 10, 2007
Posts: 110
Originally posted by Rahul Nair:
Hi,
I am using Struts 1.3.8 and Validate my form field using Struts validator Framework ...
In my JSP Page i am using <html:error > tag to display erroe messages in JSP page...This messages is displayed in my Upper side of my JSp page...

But,i want to show the error message near FORM FILED...not Upper Side of Page...

So How can i extract error messages in my page manually or using
<html:error> ???

so that it can be displayed near Field ??

[ December 11, 2007: Message edited by: Rahul Nair ]


What if you put it in a <div> and add css style to put it somewhere else.
Rahul Nair
Ranch Hand

Joined: Dec 01, 2007
Posts: 138
Originally posted by Sverre Moe:


What if you put it in a <div> and add css style to put it somewhere else.


hi Sverre Moe,

I am not getting your answer..Please can you tell me in more details.

you are saying about using <html:error> tag in div ???
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Show Struts error in JSP