wood burning stoves 2.0*
The moose likes JSP and the fly likes jsp design question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "jsp design question" Watch "jsp design question" New topic
Author

jsp design question

Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Hi,
I hope this is an appropriate forum for this question.
I have a project on the go where users upload images to my site and then a page is dynamically displayed for them with these images. Once it's built the page seldom changes. When the user uploads the images the file names are all stored in my database and the images are stored in the users directory (that is also built dynamically).
What I'd like to do is avoid a lot of database calls. I have to use jsp's to call these images as an applet is involved as well and changes minor things depending on users input. (There is no need for more info from the db at this point though).
I've heard a little about server caching and wonder if this is a good approach. If not, any suggestions?
Thanks in advance,
-Pat
Shubhrajit Chatterjee
Ranch Hand

Joined: Aug 23, 2001
Posts: 356
You don't need the database at all to store file names ...
1. If you have a look at the API documentation for File, you wil find that methods exist to get all the names of files in a folder.
2. So, you go to the user folder, get all the names of files and iterate thru them to build the HTML


Shubhrajit
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Thanks for the reply :-)
I should have mentioned that I do need the images in the database because they are linked to a description and are searchable.
It's just the main page that displays a group of these images that will seldom ever change, if at all. Should a user search for specific info though, they may call up one of these images or description from the db and at that point be directed to the page that seldom ever changes.
-Pat
Sandep Chaturvedi
Ranch Hand

Joined: Aug 20, 2002
Posts: 49
You can create a singleton class where you cache the image information from the database. So you can pick up the name from there instead of hitting database. If you add a new image, just refresh the cache.
jawwad ahmed
Ranch Hand

Joined: Dec 01, 2001
Posts: 179
Posted By
Shubhrajit Chatterjee
You don't need the database at all to store file names ...
1. If you have a look at the API documentation for File, you wil find that methods exist to get all the names of files in a folder.

--------------------------------------------------
But isn't will be machine specific specifing drive also.Should'nt we put url (url part after localhost in the database) using some pattern like singlton as said.
Thanks.
Jawwad Ahmed
[ August 24, 2002: Message edited by: jawwad ahmed ]
[ August 24, 2002: Message edited by: jawwad ahmed ]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
If the image page only changes when a new image is uploaded or deleted (for example), you could have your upload/manage servlet create a static page when things change. Write this page to a file somewhere. Then, anyone who fetches the page only needs to fetch the pre-built static page.


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
James Carman
Ranch Hand

Joined: Feb 20, 2001
Posts: 580
Originally posted by Pat Wallwork:
Hi,
I hope this is an appropriate forum for this question.
I have a project on the go where users upload images to my site and then a page is dynamically displayed for them with these images. Once it's built the page seldom changes. When the user uploads the images the file names are all stored in my database and the images are stored in the users directory (that is also built dynamically).
What I'd like to do is avoid a lot of database calls. I have to use jsp's to call these images as an applet is involved as well and changes minor things depending on users input. (There is no need for more info from the db at this point though).
I've heard a little about server caching and wonder if this is a good approach. If not, any suggestions?
Thanks in advance,
-Pat


Why are you using an Applet here? Couldn't you just display the images by placing an <img> tag in your HTML? You will probably have to write some sort of image proxy servlet to retrieve the image files from disk and stream them back if you are not saving them in the document root of your server (or a subdirectory thereof). Other than that, I'd just use standard HTML <img> tags to display the images.


James Carman, President<br />Carman Consulting, Inc.
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Thanks again for the replies,
James: I need the applet because it displays certain images in a panoramic view. The rest of the images are regular images that I use the img tag for.
Frank: That is exactly what I'd be doing. It pretty much is a static page that changes only when an image is edited or deleted, which doesn't happen often.
Like I said, I'd heard about server side caching and wondered if that is the best approach. My other thought is exactly like what you said but with one little problem. It can't be a static HTML page as it has to be a jsp. There is a couple little important scriptlets included that I need. If I was to write this to a file from my servlet how do I include the scriptlets? Can I escape out <% for example?
Thanks again everyone,
-Pat
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
It can't be a static HTML page as it has to be a jsp. There is a couple little important scriptlets included that I need.
Do you really need these scriptlets to run every time the page is requested by a user? Or can you get by with having them run once, when the "static" page is created? Please tell us more about what you need these scriptlets for.
If I was to write this to a file from my servlet how do I include the scriptlets? Can I escape out <% for example?
Not and have the page make any sense. If you use scriptlets at all, you have to take the hit of the page being dynamically generated every time it is requested. Otherwise the scriptlets will never be processed.
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Frank,
Sorry, I really should have been more specific from the start. Here is the details:
I actually will be using 2 (almost) static jsp pages.
One page contains the applet which shows images in a panoramic view.
The second page displays still images.
Both pages display the current image in a viewer. (really just a fancy table) and the links for all images are on the page, both stills and panoramics.
Now the need for scriptlets is because if they click a link to a panoramic image while on the still page I append the pan image they want to the URL. The next page looks for this and if it finds a parameter it loads up the requested image. It displays a default image if it's the users first time to the page or an error occurs.
Vice versa if they are going from the panoramic page to the still page.
Currently, I create these pages by hand and upload them myself. If a request comes to change/delete an image I do this by hand and then upload the new jsp. I am now trying to automate this entire step...which leads me to these questions.
I really don't want to serve up these pages from the database as traffic can sometimes be pretty heavy and the 2 pages seldom change. If I could somehow dynamically write these 2 jsp pages I think that would be my best solution. I'm just not sure if it's possible to dynamically write a jsp that includes scriptlets.
Also, I'm open to other suggestions as well. This whole project is to automate the creation and editing of these pages that I currently do by hand.
Thanks again,
-Pat
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Ah. It all makes more sense now.
If it's just you needing the automated solution, I woudn't bother with a servlet-style solution. I'd build a tool (maybe an Ant script or a custom program) to process your images, generate the appropriate JSPs and FTP them to the server. That sounds like it would be a "one button" version of what you are doing now.
In the slightly longer term, I'm still not entirely sure about needing JSP scriptlets in all your pages. If all the scriptlets are doing is pre-loading an image based on a parameter, and that parameter is not otherwise used in the "static" pages, then this sounds like an ideal job for a Filter.
Do you have Filter capability (available since Servlets 2.3) on your server ?
Pat Wallwork
Ranch Hand

Joined: Sep 23, 2001
Posts: 72
Frank,
I'm not sure. I'll look into all of this as I'm not familiar with Ant or Filter.
As for the parameter it really is needed. I'm trying to create the impression that the user is always on the same page as the layout is the same for both.
I appreciate all your responses and I'm off to read more about Filters and Ant. Thanks again,
-Pat
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: jsp design question
 
Similar Threads
Add row dynamically in html table based on the number of records in the database using jsp
How to generate a "real dynamic" form bean?
Displaying images on JSP page
how to insert a picture in database
redirect with jsp