Results 1 to 3 of 3
- 06-24-2012, 03:34 AM #1
Member
- Join Date
- Jun 2012
- Posts
- 5
- Rep Power
- 0
class attributes vs instance attributes in web apps
Hello again! picking up from my previous thread (display image from database on jsp page), I have two form bean classes, one for new registration and one for profile. When I instantiate a bean from each class to populate them with submitted form info, and have them go through any database transactions, if there are any exceptions thrown or validation errors made, I put the error message string into an attribute to be displayed on the JSP page. Now, on the profile class, the error message goes into an instance attribute of any profile bean instantiated. On the registration class, the error message goes into a class attribute, so I can access it on any page in the application. On both cases, I immediately set them to null after they are displayed.
My question is this, are there any security or interference issues between users when I use the class attribute, because eventually I'll have to put my application into a real server someday!
Thanks in advance
- 06-25-2012, 11:06 AM #2
Moderator
- Join Date
- Apr 2009
- Posts
- 10,476
- Rep Power
- 16
Re: class attributes vs instance attributes in web apps
Yes.
The former (assuming there is one profile instance per session) is OK.
The latter will mean that it is quite likely you will end up displaying the wrong error message if you have multiple users hitting the server at the same time, since they will be sharing that one attribute.
Is there any reason you think you need to use a static variable for that, since static variables (rather than constants) are often a flag to check for possible concurrency issues.Please do not ask for code as refusal often offends.
- 06-26-2012, 12:39 PM #3
Member
- Join Date
- Jun 2012
- Posts
- 5
- Rep Power
- 0
Similar Threads
-
Attributes vs Parameters
By java4amanda in forum Java ServletReplies: 1Last Post: 01-18-2012, 11:46 AM -
setting attributes(variables) in an Abstract class
By tashimoto in forum New To JavaReplies: 2Last Post: 12-01-2010, 08:45 PM -
Parsing XML attributes
By javanewbie2020 in forum XMLReplies: 1Last Post: 11-02-2010, 12:39 PM -
Get CSS Attributes using Java
By justinmifsud in forum Advanced JavaReplies: 0Last Post: 09-20-2010, 04:11 PM -
getting attributes from one class to another in 2 different .java files
By Mr tuition in forum Java ServletReplies: 2Last Post: 12-04-2007, 10:49 AM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks