Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Show Struts error in JSP

 
Sverre Moe
Ranch Hand
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Brent Sterling
Ranch Hand
Posts: 948
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 110
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 138
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ???
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic