aspose file tools*
The moose likes JSP and the fly likes 'Extend class' directive in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark " Watch " New topic
Author

'Extend class' directive in JSP

Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Hi all,
I am using JBoss and have made a simple jsp file which extends another class. I tried first with my own classes and got error(as described below), so I tried java classes next. My jsp page is as -

<!doctype html public "-//w3c/dtd HTML 4.0//en">
<%@ page extends = "java.lang.Thread" %>
<%!
public void run(){
System.out.println("In run");
}
%>

On invoking the page, this is the error I get -

org.apache.jasper.JasperException: Unable to compile class for JSP
C:\jboss-3.0.3\catalina\work\MainEngine\localhost\myjsp\directives2$jsp.java:54: Incompatible type for method. Explicit cast needed to convert org.apache.jsp.directives2$jsp to javax.servlet.Servlet.
pageContext = _jspxFactory.getPageContext(this, request, response,
^
1 error

at org.apache.jasper.compiler.Compiler.compile(Compiler.java:285)
at org.apache.jasper.servlet.JspServlet.loadJSP(JspServlet.java:548)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.loadIfNecessary(JspServlet.java:176)
at org.apache.jasper.servlet.JspServlet$JspServletWrapper.service(JspServlet.java:188)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:381)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:473)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:853)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:247)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:243)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:190)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.CertificatesValve.invoke(CertificatesValve.java:246)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardContext.invoke(StandardContext.java:2347)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:180)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.valves.ErrorDispatcherValve.invoke(ErrorDispatcherValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:170)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:468)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:564)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:174)
at org.apache.catalina.core.StandardPipeline.invokeNext(StandardPipeline.java:566)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:472)
at org.apache.catalina.core.ContainerBase.invoke(ContainerBase.java:943)
at org.apache.catalina.connector.http.HttpProcessor.process(HttpProcessor.java:1027)
at org.apache.catalina.connector.http.HttpProcessor.run(HttpProcessor.java:1125)
at java.lang.Thread.run(Thread.java:479)




Any ideas? Thanks
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

JSP is a templating technology.
The pages get converted into servlet code by the JSP compiler.

You are given the ability to change what servlet class you're going to inherit from with the extends directive but you can't just extend anything and expect it to work.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

Why do you even feel the need to try and extend the JSP?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Nupur Gupta
Ranch Hand

Joined: Aug 02, 2006
Posts: 45
Oh, I see, so only classes derived from Servlet classses. I was trying to extend other classes just to learn the functionality, I have been following a book, and thought I would try the directive. Thanks a lot.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Unless you're building a container or a framework that changes the fundamental behavior of JSPs you will probably never need to use the extends directive when programming with JSP.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: 'Extend class' directive in JSP
 
Similar Threads
Help wanted for first time JSP
Apache Tomcat/4.0.1 - HTTP Status 500 - Internal Server Error
Using The UseBean from Jsp
How do i correct this error
jdbc error....