tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Thomas Heller" <th.hel...@mx4k.com>
Subject Tomcat/Jasper: jsp page extends="myOwnJspBase"
Date Mon, 14 Oct 2002 13:53:45 GMT
hi all,

i'm developing a little framework for some web applications i am going to
do. I wanted to build my own JspBase Model by creating a abstract class
(similar to HttpJspBase that comes with Jasper) implementing the
javax.servlet.jsp.JspPage interface.

all i wanted to do is to change the class from calling
"_jspService(HttpServletRequest, HttpServletResponse)..." from the
"service(ServletRequest, ServletResponse)" method to
"_jspService(MyServletRequest, MyServletResponse)...".

During the processing of the request i'll wrap a custom
HttpServletRequestWrapper, ResponseWrapper over the current request/response
objects.

currently i have a request, response object which are (if i do instanceof)
instances of my wrapper objects in my jsp. Howoever i have to do

MyServletRequest myrequest = (MyServletRequest)request;
MyServletResponse myresponse = (MyServletResponse)response;

in every Jsp to use any methods/object from my wrapped objects. im trying to
do that cause i don't want to use the "common" way [eg. put every object
into request.setAttribute, instead i wanted to have
request.getSomeInfoMyFrameworkHasForMe()]. All this works if i just cast it
in the jsp _but_ i wonder if there is a way to do it without casting and
just through my JspBase class.

if i try all this now i get

HTTP Status 503 - [javax.servlet.ServletException:
MyJspBase._jspService(LMyRequest;LMyResponse;)V]

from tomcat because he translates the jsp to the "wrong"
"_jspService(Http..., Http...)" and not "_jspService(My..., My...)"

Am I violating any jsp/servlet specs with what im trying to do or am i just
on the wrong way or is it a limitation from tomcat/jasper im running into?
Can i tell him somewhere that the variable request inside _jspService is an
instance of MyRequest not HttpServletRequest?

I hope this was understandable (trying to explain an idea i have in mind is
pretty hard sometimes :) and someone read this far. I really would
appreciate any comments/help on this. Maybe there is another way to do it
and i'm just overlooking it.

thanks in advance,
thomas

PS:
my JspBase class

[--- START: MyJspBase.java ---]

import java.io.IOException;
import javax.servlet.jsp.JspPage;
import javax.servlet.ServletConfig;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.ServletException;

public abstract class MyJspBase implements JspPage
{
 private ServletConfig config;

 public void init(ServletConfig config)
 {
  this.config = config;
 }

 public void destroy()
 {
 }

 public ServletConfig getServletConfig()
 {
  return config;
 }

 public String getServletInfo()
 {
  return "info";
 }

 public void service(ServletRequest request, ServletResponse response)
throws ServletException, IOException
 {
    // this shouldnt happen .. just for curiosity reasons .. remove soon
    if (response instanceof MyServletResponse)
        throw new ServletException("eeks, no framework response");
   _jspService((MyServletRequest)request, (MyServletResponse)response);
 }


 public void jspInit()
 {
 }

 public void jspDestroy()
 {
 }

 public abstract void _jspService(MyServletRequest request,
MyServletResponse response) throws java.io.IOException,
javax.servlet.ServletException;
}

[--- END: MyJspBase.java ---]

[--- START: test.jsp ---]

<%@ page extends="MyJspBase" %>
<%
  out.print("hmpf this isnt reached");
%>

[--- END: test.jsp ---]


--
To unsubscribe, e-mail:   <mailto:tomcat-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:tomcat-user-help@jakarta.apache.org>


Mime
View raw message