You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by "Felix A. Milovanov" <fe...@terasystems.com> on 2001/04/10 02:48:14 UTC

Am I crazy???

  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.