aspose file tools*
The moose likes JSP and the fly likes The Rookie Throws in the Towel (Kind of) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "The Rookie Throws in the Towel (Kind of)" Watch "The Rookie Throws in the Towel (Kind of)" New topic
Author

The Rookie Throws in the Towel (Kind of)

Bernard Bobinski
Greenhorn

Joined: Aug 30, 2004
Posts: 14
As part of the Training Module that I authored for my police department I had to create a �Visual Calendar� in JSP. Training courses would be listed under each date (in the actual date box) provided there was a training course for that particular date. I tried to use a Function to do this but I could never get it to work. I ended up using JSP:INCLUDE statements and it works alright. I was wondering if creating a Class or using Function would speed up the searches. Also any advice on improving the code for the Function?

SQL Date Format is yyyy-mm-dd

Actual Calendar Code from HTML (from Body on)



INCLUDE PAGE Code (Test9.jsp)



FUNCTION Code (Which I had at the beginning of Test8.jsp which is Calendar itself)



Thanks


Respectfully,<br /> <br />Bernard J. Bobinski
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61766
    
  67

Ho Bernard, I'm a little unclear on what you are after, and I think it may just be a terminology issue.

You wrote:

I was wondering if creating a Class or using Function would speed up the searches.


The term "Function" really has no meaning in the JSP world (except for EL functions as defined by JSP 2.0, but that's not what I think you are asking about here).

Could you explain a little more about what you mean by that? Are you talking about creating methods on a bean to factor some of the Java out of your JSP page? Especially the include page that contains the SQL code?

If so, I don't think that that will gain you much in the way of performance, but it would surely create a better application structure. The less Java on your JSPs (preferably none) the better.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Bernard Bobinski
Greenhorn

Joined: Aug 30, 2004
Posts: 14
Bear,

I apologize for my lack of proper terminology as I am relatively still new to the world of Java. Unfortunately my forte with programming lies in PHP. This does not help me at work though because our primary application is written entirely in Java and JSP. Needless to say it has been a whirlwind education - far more than I would get at Graduate School. For my family website I wrote an event calendar that displayed an actual calendar along with any events (Birthday, Anniversary, etc) for each particular date. The events were actually displayed as a link which would take the user to another page where they could view the particulars about that specific event. I wrote the entire PHP event calendar on one page and created some PHP Functions to search the database and to actually create the calendar. It took me a week to write it but its smooth code wise. At work I wrote a training module to accommodate our training records. Part of the training module is scheduling training courses for the officers. I wanted to create the same type of event calendar only for training courses at work. Developing the actual calendar and getting it to display in JSP was not bad at all. Where I got stuck was the function to search the database (I could not figure it out in Javascript and I tried to write a CLASS but gave up). I ended up resolving the issue with using JSP:INCLUDE Statements. When the calendar is created and it's time to search the particular date for any training courses in the training courses table the page jumps to a second JSP page to search the database. The question I was asking was if I was able to create a Class to perform the database search would it speed up the functionality of the page � search time etc.? Is it worth it to use a Class in this situation or a 2nd JSP Page like I did?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Partitioning your code into beans and servlets will probably not speed it up any (unless doing so allowed you to cache some data instead of repeatedly looking up the same values from your database).

The main reason to move away from Model1 to a Model2 or Model, View, Controller, architecture is to separate the different concerns involved with a webapp. By moving all of your database code into beans, you allow it to be run , tested, and debugged from outside of the web application. All of my data access objects have a main method which allows them to be called from the command line without ever starting the app server.

Likewise, you can move all of your flow handling into a servlet.
Servlets, in my humple opinion, are the most elegant solution for handling the flow of a web application.

Once you've done this, your JSPs only have to handle the look and feel issues. You can easily set up multiple views (JSPs) to display data from the same servlet/bean combination.


There is one possible way that breaking your code into components can speed up your app. A calendar app tends to stay the same for at least a day at a time unless someone updates it. That means that there is a lot of potential for you to cache the results of your datase read operations.
If your calendar shows user specific events, then caching the calendarBean (I took the liberty of naming it for you ) in session would mean that each user would only have to read the data once per session. Any subsequent reads (which are pretty likely in a calendar app) would come from memory which is much faster than an DB operation. If the calendar is not user specific, than you could potentially limit disk reads to one a day (unless someone adds an event to the calendar) by caching it in application scope.

I have a very Simple MVC Example on my site that you're free to download and explore.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Jiang Xiaofeng
Greenhorn

Joined: Jul 19, 2005
Posts: 25
Originally posted by Bernard Bobinski:
Needless to say it has been a whirlwind education - far more than I would get at Graduate School.


Assuming that you're talking about a graduate program in Computer Science, that's not really a reasonable comparison to make. It seems as though you are learning a technology platform. A graduate degree in Computer Science is not about learning how to use a single technology but rather the theoretical background of Computer Science. Of course, I am simplifying all of this but learning the "how" is what you're doing now - graduate studies would show you the "why."

And the amount of Java in your JSP shows me that that education is not giving you the knowledge to do things well, in design and implementation, but just to get them done.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Originally posted by Jiang Xiaofeng:


And the amount of Java in your JSP shows me that that education is not giving you the knowledge to do things well, in design and implementation, but just to get them done.


Jiang,
The single, most important rule at Java Ranch is "Be Nice".
That the original post is asking the right questions and exploring better ways to write code tells me that his education has given him exactly the knowledge that it will take to do things well.
In his original post, he explained that his backround is in PHP, a fairly flat web scripting language. The JSP code that he posted looks like very typical PHP/ASP code -- and very clean at that.

Instead of taking shots like this, maybe you could suggest a refactoring strategy that would actually be of some assistance.

Looking forward to your future suggestions.
Welcome to Java Ranch.
-Ben
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: The Rookie Throws in the Towel (Kind of)