This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes inheriting from servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "inheriting from servlet" Watch "inheriting from servlet" New topic
Author

inheriting from servlet

Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
Hi, I have a general catalog that has two class variables: protected String title = "General Catalog Page";
protected String[] itemIDs = {"jacket", "windbreaker", "shirt", "notepad", "pen"};
And the servlet will println a HTML page with title and then print out each of the content keyed by itemIDs[i]. The problem is when I try to inherit from this servlet, and override protected String title = "Clothing Catalog Page";
protected String[] itemIDs = {"jacket", "windbreaker", "shirt"};
The child servlet still displays the same content as the General Catalog servlet. Can someone please help?
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12759
    
    5
Variable references are resolved at compile time - they don't get looked up dynamically like methods do. So - if you call a method in the parent class, it will use the variables it was compiled with.
IMHO you have taken a wrong turn in your program design by putting these details into the servlet class. If you can move them to a Catalog class - or maybe even define a Catalog interface or Catalog abstract class, I bet you will find it easier to continue development. This will simplify your servlet and make it easier to debug.
Bill

Bob Moranski
Ranch Hand

Joined: Nov 22, 2000
Posts: 177
thank you so much Bill!
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: inheriting from servlet
 
Similar Threads
opening database in servlet
session tracking remove item (urgent)
Can't redirect to another page
regarding session transfer from servlet to jsp
Sorry For Throwing Lengthy Codes At This Site, But I Really Need Help