Felix

No yr not crazy, just a littl masochistic maybe  :-)
(either that or I've missed the point)

instead of ...

>    public void service(HttpServletRequest Req, HttpServletResponse Res)
>           throws ServletException, IOException
>    {

why don't you try ...

 public void doGet(HttpServletRequest Req, HttpServletResponse Res)
           throws ServletException, IOException
 {
   theRestOfIt(Req, Res);
 }

 public void doPost(HttpServletRequest Req, HttpServletResponse Res)
           throws ServletException, IOException
 {
   theRestOfIt(Req, Res);
 }

 private void theRestOfIt(Req, Res)
           throws ServletException, IOException
 {
     what you really need to do here...
 }

the documentation says pretty clearly not to use 'service' -- "This
method is rarely overridden."


Hasan


> From: "Felix A. Milovanov" 
>  Subject:  Am I crazy???
>  Date:  Mon, 09 Apr 2001 17:48:14 -0700
>    Hello all,
> 
>    now I start using Tomcat and servlet/JSP programming. I was need
>  to make some
>  activity BEFORE invoking any servlet/JSP. I've created a very simple
>  class :
> 
>  import java.io.*;
>  import java.sql.*;
>  import java.lang.*;
>  import java.util.*;
>  import javax.servlet.*;
>  import javax.servlet.http.*;
>  import javax.servlet.jsp.*;
> 
>  public abstract class baseServlet extends HttpServlet implements
>  HttpJspPage
>  {
> 
>    public void _jspService(HttpServletRequest Req,
>  HttpServletResponse Res)
>           throws ServletException, IOException {}
> 
>    public void jspInit() {}
>    public void jspDestroy() {}
> 
>    public void service(HttpServletRequest Req, HttpServletResponse
>  Res)
>           throws ServletException, IOException
>    {
>      String Path = Req.getServletPath();
> 
>      System.out.println("URL called : " + Path);
> 
>      /* Invoke original handler */
>      if (Path.endsWith(".jsp")) _jspService(Req, Res);
>                           else  super.service(Req, Res);
>    }
> 
> 
>  }
> 
>    I can inherit any servlet/JSP from this class, and now I just
>  print to
>  console the URI of requested WEB resource.
> 
>    Ok, everything works. Then I tried to handle error 404 with Tomcat
>  - I've
>  already described 404 handler for apache :
> 
>  ErrorDocument 404 /404.jsp
> 
>    /404.jsp works excellent, but when I tried to run something non-
>  existed
>  URI like "/servelt/bla-bla-bla", I got an error from Tomcat instead
>  of
>  /404.jsp. Ok, I read the documentation and found how it should be
>  done:
> 
>  <web-app>
>   <error-page>
>    <error-code>404</error-code>
>    <location>/404.jsp</location>
>   </error-page>
>  </web-app>
> 
>    For now these lines are all in my web.xml. I've restarted tomcat,
>  tried
>  to access /servlet/hmm and got the following message ( insted of my
>  own /404.jsp ) :
> 
>  Error: 400
>  Location: /servlet/hmm
>  HTTP method GET is not supported by this URL
> 
>    The most strange issue is... I'VE GOT MESSAGE "URI called :
>  /servlet/hmm"
>  ON THE CONSOLE!!!
> 
>    I do not understand anything... WHY MY CODE IS INVOKED???
> 
>    Sincerely,
>                                                          Felix.
>

Reply via email to