Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

JSP best practices

Status
Not open for further replies.

lespaul

Programmer
Feb 4, 2002
7,083
0
0
US
So I'm trying to learn how to develop web pages using JSP and I can't believe the technique I've been shown for what I'm doing is the easiest/best/standard way of doing things.

Here's what I need to have at the end of my project:

A webpage that lists statutes (Active/Inactive/All) and allows the user to filter based on who enforces the statute (City, State, Local, County) and then allow editing/adding from a "detailed" page.

So:
[tt]
o Active o Inactive o All
o City (C) o State (S) o Local (L) o County (N) o All
RowID StatuteID Description Origin
14 1-12-42 FAIL ALLOW EMPLOYEE TIME VOTE S
15 10.1.1.4B PARK SANITATION (REFUSE) C
16 10.1.1.9 PARKS OPERATING POLICY (HOURS) C
17 10-1-1-10 PARK OPERATING POLICY C
18 10-1-1-4C GLASS CONTAINER IN PARK C
19 10-1-1-6B MOTOR VEH PROHIBITED IN PARK C
20 10-202F OCCUPANCY VIOLATIONS N
21 10-3-2-15 MAIN DRAINS C[/tt]

when the link is selected a form opens that allows editing of the detailed information.

Now, my coworker who started this project used a tokenizer but he was only dealing with a subset of all the statute fields. I think the tokenizer is a bunch of #$%@! Every field has to be added and extracted. The query has to have each field specified (instead of *). Is there a better/easier way to do what I'm trying to do? I was looking at the tutorial at and it says for what I need to do i should use beans (not real beans though...here's the specific page).

I currently have listRows.jsp which coincidentally lists the rows (shown above)...I have editForm.jsp which allows (surprise) editing of the statute in a form. I have a class Library that jaxtell helped me with in Thread695-1479415 but I'm assuming that needs to be modified in order to allow filtering on the type of statute.

I was able to get the information from the query into the editForm.jsp and turn off and on check boxes and radio buttons with some assistance from prosper in Thread695-1481383, but I feel like I'm just piecing together bits and pieces to make it work the way i want, but I'm not putting it all together correctly.

Any thoughts or suggestions?

Leslie

Have you met Hardy Heron?
 
Java Beans and tags is the way I do it. I have a home bean that has/runs my query, along with any optional filtering. It takes the result set and makes a linked list of value beans. I take that linked list and iterate through it, using some custom tags, to display the results. It might not be the best way, since you'll need to change every home bean if you change where/how your data is stored. Its not an issue for me, since the SQL I use will work on any database I might use. Using jstl, or custom tags, keeps all sciptlets out of your jsp making it very clean and easy to read.

-----------------------------------------
I cannot be bought. Find leasing information at
 
You do not need to be nervous that you should use the best practise when you start to learn how to write jsp web page.

Considering too much in best practise may hinder your learning.

When you have more experience in writing Java classes, jsp page, using taglib, you may know if there is way to write more efficient code.

You may read more about using MVC(Model View controller) pattern to write jsp page in books or in online tutorial.
Using Apache Struts make help you to know more about MVC.

After you read more books and the program examples from other people, you may learn some better practice gradually.
 
I guess the specific practice I was trying to understand was my co-worker using the tokenizer to create a "datarow" like this in the process that gets the data:
[tt]
datarow = 10-13-25-1%CHGABV%The short description%C%etc...[/tt]

so that on the page that displays the data I have to extract it all:
[tt]
dataRow = statuteList.get(index).toString();
StringTokenizer token = new StringTokenizer(dataRow,"%");
statute = token.nextToken();
abbrev = token.nextToken();
descrip = token.nextToken();
descripL = token.nextToken();
status = token.nextToken();
NCIC = token.nextToken();
effectiveDate = token.nextToken();
courtMand = token.nextToken();
fine = token.nextToken();
bond = token.nextToken();
chargeType = token.nextToken();
DMVCode = token.nextToken();
CrimHist = token.nextToken();
CrimHistTime = token.nextToken();
origin = token.nextToken();
RepositoryStat = token.nextToken();
user = token.nextToken();
ChsCat = token.nextToken();
IntPre = token.nextToken();
LastDateUpdated = token.nextToken();[/tt]

so now if the table is changed to add a new field I have to add that field to the class that gets the data and I have to add that field to this section to extract that field.

I'm just thinking there has got to be a better way....right? So I looked at the "form bean" as shown in the tutorial...is that what I should be doing?

What classes/pages should I have to do:

1. a dynamic query based on user selections
2. display a few of the fields in the query results as a list
3. allow selection of a specific row of information to open a 'detail' page and let the user modify the data.

Leslie
 
I will give you some comments on what you have to do.
Although a dynamic query based on user selections is very powerful function, it is only useful for very experienced user or it will be useful for developer. People may feel this function not user friendly. There is some chance that this function will break the integrity of data.

You can provide a searching function for a record. After user has input or select the criteria, display a list of matched list of record.

Searching criteria can be listing the 100 last modified records
(10 records in a page), searching the record with matched description.
The searching criteria should be words or something that user
can memorize.
 
Really? it's that difficult to create a dynamic query based on two criteria? It's not like a dynamic query that allows searching on any field....

[tt]
o Active o Inactive o All
o City (C) o State (S) o Local (L) o County (N) o All
[/tt]

The majority of the time the user is only going to need "Active" records, but they may need to see "All" or "Inactive" sometimes...I then want to filter by origin defaulting to all records but allowing the user to filter the recordset to see only "County" or "State" records.'

So you are saying that having the DataRow and splitting it up with token is the best way to present information in a webpage from a database?

Thanks,
Leslie

 
Using token or not is the decision in programming logic. I myself do not use token in this situation. After you have written lots of program, you can choose your programming logic or way to solve problem.
 
What is another option? How would you do it? That's what I want to know. I don't know what the other options are, but I know I don't like this way.
 
Young programmer may learn the way to solve problem from a more
experienced programmer.
After you have watched alot of programs from that experienced, you may know how to solve problem with different technique and logic.

When you are not experienced enough, you can learn how to solve
problem.
When you become more experienced, you may find that you have the ability to choose, fine tune(more efficiently) your way to solve problem.

I cannot always tell you the way to program. you need to do more programs and learn from how to achieve the user requirements.
 
Are you making this for your organization's production environment? It might be worth while to bring in an expert to help choose and implement best practices, as well as give some level of training to follow those practices. I use beans because that was the practice in place when I started this job. It works, and there are very few complaints, so we continue the practice.

-----------------------------------------
I cannot be bought. Find leasing information at
 
We are busy converting a lot of our programs to web apps and services. We have a legacy AS400 (with RPG green screens!) that has 25 years worth of court data; within the next year or two we are going to be converting to a canned case management system. There are some processes and activities that the new canned system doesn't do and these are what we are converting to web systems.

I am currently working on my first web development project. One of my co-workers started the project and now I'm expanding it. When he was working with the database tables, there were only a few fields he was interested in having...now I need all the fields. He used the token/data row on the four fields he needed and that seemed to work fine, but I'm using 20+ fields and it doesn't seem to be the "right" way. I just can't believe all the database driven websites use datarows and tokens to assemble and break apart the information between web pages!

Unfortunately we're a government agency and the likelihood of getting anyone in to develop, implement and train are nil. It's a learn as you go and I KNOW there has to be a better way than what we're doing.

Thanks!
leslie
 
So in case anyone finds this thread and wants something more informative that I got, I have decided to implement this using the MCV model.

I have created a Statute class, a SelectStatutes servlet and a web page that shows the results I need.

reading the Head First series has really helped in my understanding of Java, web programming and OOP in general. I would strongly recommend them to anyone struggling with these same issues.

Leslie
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top