Results 1 to 3 of 3
  1. #1
    rdangelo is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default 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

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    11,450
    Rep Power
    18

    Default 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.

  3. #3
    rdangelo is offline Member
    Join Date
    Jun 2012
    Posts
    5
    Rep Power
    0

    Default Re: class attributes vs instance attributes in web apps

    Thanks again Tolls, actually the only reason was to test this very question. I'll go ahead and switch to instance variables

Similar Threads

  1. Attributes vs Parameters
    By java4amanda in forum Java Servlet
    Replies: 1
    Last Post: 01-18-2012, 11:46 AM
  2. setting attributes(variables) in an Abstract class
    By tashimoto in forum New To Java
    Replies: 2
    Last Post: 12-01-2010, 08:45 PM
  3. Parsing XML attributes
    By javanewbie2020 in forum XML
    Replies: 1
    Last Post: 11-02-2010, 12:39 PM
  4. Get CSS Attributes using Java
    By justinmifsud in forum Advanced Java
    Replies: 0
    Last Post: 09-20-2010, 04:11 PM
  5. Replies: 2
    Last Post: 12-04-2007, 10:49 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •