Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Storing errors in session  RSS feed

 
Karan Jain
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have to do error processing on my servlet and validator classes and want to store the errors for the validation in session, maybe in a ArrayList. Its a batch process and at the end of process i need to paint an error page with all the errors.

Is storing the errors in session sounds a right approach?
Are there some other good options for achieving this functionality?

Any code snippet would help...

Thanks in advance...
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You would only use session if the values you're storing need to last longer than one request/response cycle. (ie: when using response.sendRedirect)

If you're generating the error messages and showing them from within the same request/response cycle, then you can bind them to request scope.
Doing so means you won't have to worry about cleaning them up.
 
Amit Kumargupta
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the application variable also but it depends upon your application
beacuse Application variables are the variables which remain common for the whole applicationand their value can be used across the whole application And they die only when the application stops or probably when they are killed forcibily.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Considering errors to be specific to users , I would not recommend application context , rather go for request.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The danger of placing them in the session is that what goes in the session is true for the life of the session. For example if you store the fact that the operation failed on the session then forget to remove it from the session, then the user will always get an error message.

A slightly better approach is to provide a processing ID and then assign the messages to that ID on the session rather than to some 'global pool'. Then the user would be required to ask for the results for a particular process.
 
Remko Strating
Ranch Hand
Posts: 893
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why not logging the messages into a database with the userid and the sessionid and the time of the error.

This gives you an good overview of the error messages and gives you a change to analyze them. By saving to the database you don't have to worry about the scope of your error messages.

Off course you have to log message to a textfile when the database is not available, which unavailability might cause an error
 
Ashok Mor
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems very awkward to use database for storing an exception, because exception are different upon time and user.

SO once user get log off or complete the work with exceptions again we need to remove them from database, so it is not a beneficiary to use database for that. As it makes more tick with DB.

I think if you go with request scope for storing an exception is quit enough.


Ashok Mor
Ness Tech.
[ July 19, 2007: Message edited by: Ashok Mor ]
 
Amit Kumargupta
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you can store the error in request(if user related) or log file.
 
Asrar Hasan
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yup . The request is the best place to store the error / exception messages .
here is the snipts you can do
Make a java been class for Error Message like "ErrorMessage" with getter setter of properties like .
ErrorName
ErrorType
ErrorLevel
ErrorCause
ErrorMessage
ErrorProducingClass
ErrorProducingMethod.
ErrorWithUser
And Populate the ErrorMessage Class when error Occur And then creat new object for new error message.
And Stores the ErrorMessage class objects in Vector or List.

At the End page Populating the Collection of ErrorMessage Class and display in some explainatro and proper method.


If you want to know the error produced with respet to users at the same time , so you can store these ErrorMEssage objects colletions in a collection of Vector and at index of vector can user userid , for refrencing the coresponding ErrorMessage class.


If (you want to show messages collectively for more than one user, so you can use request scope for procesing and use the classes and object refrences (in memory) .So can get from class refrences from memory .


Regards
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66207
151
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Asrar Hasan:
Yup . The request is the best place to store the error / exception messages .


Only if, as has been pointed out, the message(s) can be processed and discarded in the current request life cycle. Otherwise, the session is required. And also, as has been pointed out, there must be a strategy in place to remove theses messages from the session once the user has completed or abandoned the multi-request operation.
 
Karan Jain
Ranch Hand
Posts: 82
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot for your responses...
I need to do all the processing in the same request on the server... so i think request would work for me...
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!