wood burning stoves 2.0
The moose likes Servlets and the fly likes What Is The Proper Way to Extend Another Class In JSP? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "What Is The Proper Way to Extend Another Class In JSP?" Watch "What Is The Proper Way to Extend Another Class In JSP?" New topic

What Is The Proper Way to Extend Another Class In JSP?

JiaPei Jen
Ranch Hand

Joined: Nov 19, 2000
Posts: 1309
I am writing JSP programs and run into a problem. I think that I don't know how to "extend" another JSP page. (In the case of Servlet programs, I should say that I am trying to extend an abstract class, and I don't know how to do it properly using JSP.) I have KidsBooksPage which extends CatalogPage. Allow me list the critical parts of my codes and ask several questions:
In KidsBooksPage.jsp, I have the following:
<%@ page extend="CatalogPage" %>
String[] ids = { "lewis001", "alexander001", "rowling001" };
setTitle("All-Time Best Children's Fantasy Books");
1. It should be <% page extend="CatalogPage" %> ? OR
<% page extends="CatalogPage" %>
2. Given that both KidsBooksPage.jsp and CatalogPage.jsp are in the bookstore subdirectory, should I change the statement to:
<% page extend="/bookstore/CatalogPage.jsp" %>
In CatalogPage.jsp (In fact, CatalogPage is an abstract class), I have:
<% page import="
private Item[] items;
private String[] itemIDs;
private String title;
<jsp:useBean id="item"
scope="session" />
<jsp:getProperty name="item" property="items" />
<jsp:getProperty name="item" property="title" />
1. should I change class="bookstore.Item" to
class="Item" ?
2. Were the CatalogPage.jsp a servlet, say, CatalogPage.java, I should have a statement
public abstract class CatalogPage extends HttpServlet {}
and I think the above statement is not necessary to be there in JSP. Am I right or I am wrong?
Please point out other mistakes that I have made. Thank you.
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
The best solution for your problem is better use java beans where you can easily subclass.Can you subclass a jsp page??Iam doubtful.
Scott Stirling

Joined: Mar 05, 2001
Posts: 24
You can subclass a JSP, but not the way the user is trying to do it.
First, the correct page attribute is "extends" not "extend." Don't you have a JSP syntax reference handy?
Second, you can't extend a *.jsp file, you can only extend a Java class. So you need to find out the name of the translated and compiled Catalog.jsp class and extend that. This can be tough because the name of the translated JSP will differ from one Servlet container to another. It would be wiser to write a servlet and extend that, especially since you want it to be an abstract class.
[This message has been edited by Scott Stirling (edited March 06, 2001).]

Scott Stirling<BR>Author of <A HREF="http://www.amazon.com/exec/obidos/ASIN/067231939X/ref=ase_electricporkchop/107-2476442-4883722" TARGET=_blank rel="nofollow">Java Server Pages Application Development</A>
I agree. Here's the link: http://aspose.com/file-tools
subject: What Is The Proper Way to Extend Another Class In JSP?
It's not a secret anymore!