Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Design questions with beans/JSP

bdc30bdc30 Member Posts: 3
Hey everyone,

I've been trying to learn web-apps recently, but I haven't used much Java before so I had a few design questions regarding JSP/beans.

Basically, my web-app uses CSS to define the layout, menu, etc. I use beans to build tables of information (such as messageboards, lists of users, etc.). Within the JSPs, I simply do things like checking the user's access status (i.e. whether an administrator or not) and displaying the appropriate content. I include the layout files in every JSP with the include file directive.

I wasn't quite sure of the best/most efficient way to do a few things. Is it OK to query the database within beans? Or should a servlet do this and save the results to a bean? Right now I have the bean doing it since a servlet on every page seemed like unnecessary overhead.

Next, regarding scope on beans - right now I have essentially everything set to session scope. I figured this would let me be more memory-efficient with objects. But a few problems arise with this model - for example, I need to issue clear commands to Vectors holding information every time a bean's "display" method is called. I'm not sure if this is good design on two counts: 1. Should I even be storing information from the DB in vectors, if I'm querying the DB each time a page is loaded? 2. I may be saving memory by using session scope, but is the clear method for vectors expensive? It just seems hack-ish to constantly clear vectors after displaying the output on each page.

Finally, I'm also writing a messageboard for use on the page. Right now, each message is represented as an object - I thought this made the most sense OOP-wise (since people can edit, delete individual messages), but I'm worried about memory usage again. Is it better to simply output query results as a single string to the page and save memory but repeat some code, or leave it the way it is with each message as an object?

Thanks for the help, and sorry for being so long-winded.

Comments

  • treshrtreshr Member Posts: 326

    You can use Vectors to store the information temporarily. But you can also use a JavaBean that holds a simple array.

    If you use the session scope you'll be able to login and logout users much easier. Don't use the appliaction or request scope, because they don't work that way with users etc. It doesn't take that much memory.

    I wouldn't treat text as an object. Because you can also edit and remove text in a database. Easier than using an object. If you create a good loop you'll have no more code than you're using now with your messageboard.

    Hop this helps you.


    --=][tReShR][=--

  • bdc30bdc30 Member Posts: 3
    Thanks for the answers, they helped quite a bit. I decided to redo the messageboard and get rid of Message objects, just storing everything as Strings. Also decided to get rid of Vectors for temporary storage, since they add unnecessary overhead and there's really no good way to cache data - I think you pretty much have to query the DB each time a page is reloaded because another logged in person could be adding stuff, and you can't tell what has been added without querying again.
  • treshrtreshr Member Posts: 326
    [b][red]This message was edited by Moderator at 2004-1-10 19:34:27[/red][/b][hr]
    The thing is with the queries in databases, databases are build to be get manu queries.
    They are build to have a lot of questions ay the same time and have index build with relatiuons so they get all the information easier for you.
    So why should you start processes that are not really needed.

    And it's what you've said, two different people could do different things with the database at the same moment.

    --=][tReShR][=--



  • MuthuvasanMuthuvasan Member Posts: 1
    : Hey everyone,
    :
    : I've been trying to learn web-apps recently, but I haven't used much Java before so I had a few design questions regarding JSP/beans.
    :
    : Basically, my web-app uses CSS to define the layout, menu, etc. I use beans to build tables of information (such as messageboards, lists of users, etc.). Within the JSPs, I simply do things like checking the user's access status (i.e. whether an administrator or not) and displaying the appropriate content. I include the layout files in every JSP with the include file directive.
    :
    : I wasn't quite sure of the best/most efficient way to do a few things. Is it OK to query the database within beans? Or should a servlet do this and save the results to a bean? Right now I have the bean doing it since a servlet on every page seemed like unnecessary overhead.
    :
    : Next, regarding scope on beans - right now I have essentially everything set to session scope. I figured this would let me be more memory-efficient with objects. But a few problems arise with this model - for example, I need to issue clear commands to Vectors holding information every time a bean's "display" method is called. I'm not sure if this is good design on two counts: 1. Should I even be storing information from the DB in vectors, if I'm querying the DB each time a page is loaded? 2. I may be saving memory by using session scope, but is the clear method for vectors expensive? It just seems hack-ish to constantly clear vectors after displaying the output on each page.
    :
    : Finally, I'm also writing a messageboard for use on the page. Right now, each message is represented as an object - I thought this made the most sense OOP-wise (since people can edit, delete individual messages), but I'm worried about memory usage again. Is it better to simply output query results as a single string to the page and save memory but repeat some code, or leave it the way it is with each message as an object?
    :
    : Thanks for the help, and sorry for being so long-winded.
    :

Sign In or Register to comment.