Re: web.xml question

2000-12-05 Thread Kedar Choudary

Hi,

You dont *have* to register any servlet in web.xml.
Registering servlet in web.xml is only required if you want to access the
servlet by a "nickname".
Typically one creates a nickname for his servlet in web.xml to
1) Hide the actual implementation class name being exposed to the world in
the URL
2) To create short name, espicially to drop that long list of package
prefixes.

But you can verywell access any servlet, that is present in WEB-INF/classes
directory, by URL /yourcontext/servlet/package.prefix.classname.

Regarding the second question, unfortunately, there seems to be no way to
specify a servelt, in place of a "welcome-file". So, I guess, easiest way to
setup your servlet as welcome-file, will be to have a index.jsp in your
context's root directory which simply forwards the request to your servlet,
using jsp:forward.

Kedar Choudhary.

- Original Message -
From: Vanja Vlaski <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 05, 2000 3:58 PM
Subject: web.xml question


> Since I am new to the tomcat I have one probably stupid question.Do I have
> to register all the servlets I use in web.xml or just the first servlet
that
> is called?
>
> Also how can I call the servlet at the beging instead of index.html?
>
> Thanks
>

_
> Get more from the Web.  FREE MSN Explorer download :
http://explorer.msn.com
>
>




Re: Error 404

2000-12-05 Thread Kedar Choudary

Hi,

There seems to be bug in Tomcat 3.2. It sends 404 on ANY
FileNotFoundException.
So if the precessing in you alter.jsp involves accessing certain file, which
is not present, it will throw FileNotFoundException. The exception will be
caught by Tomcat and it will send 404.
Try putting whole of your jsp code with try/catch block, catch the
exceptions and do printStackTrace to locate real problem

Kedar.

- Original Message -
From: nitin mundada <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Tuesday, December 05, 2000 4:09 PM
Subject: Error 404


> Hi all
> I am facing a strange problem. I am getting error 404:
> File not Found, though file is there.
> I'll explain -- I want to connect to new.jsp, and
> alter.jsp through start.html. when i click on link for
> new.jsp, it works perfectly, but when i link on link
> for alter.jsp, it shows Error 404.
> alter.jsp is there in on the server.
>
> I tried with other combinations also, like uploading
> new.jsp(as this link was working properly) by other
> name like new1.jsp, and trying to access it, it again
> fails.
>
> i.e. i am able to access only new.jsp and no other
> file
>
>
> Thank u in advance
> Nitin
>
> 
> Do You Yahoo!?
> Get your free @yahoo.co.uk address at http://mail.yahoo.co.uk
> or your free @yahoo.ie address at http://mail.yahoo.ie




Re: Servlet in the middle... in the middle.. in the middle

2000-12-04 Thread Kedar Choudary

I have rewritten following reply to MVC thread.
Hope it helps.
-
guess, there IS a way to forward the .jsp processing to tomcat's
jsp-servlet, even when you have registered your own servlet to process all
.jps requests.

Instead of using
ServletContext.getRequestDispatcher(url).forward(request, response);
use

ServletContext.getNamedRequestDispatcher("jserv-servlet").forward(request,
response);

It worked for me.

Note: This method does not work if you want to "re-write" the url in your
handler servlet. JSP files processed by the jserv-servlet is always the URL
of the original request.
---
Kedar Choudhary.

- Original Message -
From: Craig R. McClanahan <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, December 01, 2000 1:23 AM
Subject: Re: Servlet in the middle... in the middle.. in the middle


> "Bragg, Casey" wrote:
>
> > Is there a way to do the following?
> >
> > Let's say a user requests /foo/junk.gif, or /foo/test.jsp.
> >
> > I'd like all requests to /foo/* to first be processed by a servlet.
> > The servlet performs some operation (user authentication specifically).
> > If the servlet processing performs normally, I want the request
forwarded to
> > the page actually requested (in the case of .jsp files, the page must be
> > processed by the jsp engine first of course).
> >
> > I've set my Tomcat 3.1 up as defined below.  The result is an infinite
loop.
> > A request of /foo/junk.gif is redirected to the servlet and then to
> > /foo/junk.gif (which then is redirected to the servlet and then to
> > /foo/junk.gif... and so on).
> >
>
> This question came up earlier today as well.  The bottom line is that you
cannot
> do what you are after in Tomcat 3.x (which is based on the servlet 2.2
> specification).  You can do it by using a Filter from the servlet 2.3 API
(which
> Tomcat 4.0 supports).  See my expanded explanation on a thread with
subject "MVC
> problem".
>
> >
> > Thanks so much for your help!
> >
> > ...Casey
> >
>
> Craig McClanahan
>
>




Re: MVC problem

2000-12-04 Thread Kedar Choudary

I guess, there IS a way to forward the .jsp processing to tomcat's
jsp-servlet, even when you have registered your own servlet to process all
.jps requests.

Instead of using
ServletContext.getRequestDispatcher(url).forward(request, response);
use

ServletContext.getNamedRequestDispatcher("jserv-servlet").forward(request,
response);

It worked for me.

Note: This method does not work if you want to "re-write" the url in your
handler servlet. JSP files processed by the jserv-servlet is always the URL
of the original request.

Kedar


- Original Message -
From: Craig R. McClanahan <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Cc: <[EMAIL PROTECTED]>
Sent: Thursday, November 30, 2000 11:27 PM
Subject: Re: MVC problem


> See below.
>
> "Aiken, David" wrote:
>
> > > hi all..
> > >
> > > We're hitting a problem with the MVC approach in tomcat.
> > >
> > > Our controller is designed to intercept all requests for URLs within
our
> > > web application so that it can handle internationalization and
security
> > > checks centrally.
> > >
> > > The problem is as follows:
> > > - the controller servlet registers interest in URLs of the form
'*.jsp'
> > > - a request for 'a.jsp' arrives and the controller checks security and
> > > negotiates the locale settings
> > > - the controller includes the contents of 'a.jsp' in the response
> > >
> > > At this point it seems that tomcat takes over. Unfortunately, it
doesn't
> > > retrieve the contents of the page - it just resubmits the request to
the
> > > controller again, resulting in an endless loop. This also occurs for a
> > > 'forward'. Not good.
> > >
> > > One of the workarounds is to use URLs of the form '.do' to request
page
> > > content. This allows the controller to forward to a .jsp URL without
> > > getting into a loop. The problem is that someone who knows the
structure
> > > of the www site can submit requests for '.jsp' directly and bypass any
> > > security checks. The obvious workaround for this is to put tags into
the
> > > .jsp pages and java calls into any servlets to perform the security
check
> > > - but this negates any advantage to the MVC approach (and forces
> > > page/servlet developers to remember to place checks into all of their
> > > content).
> > >
> > > We're probably missing something - it seems difficult to believe that
the
> > > MVC approach has such a fundamental flaw.
> > >
> > > thanks!
> > > David Aiken
> > > BMC Software
>
> What you are hitting is primarily a limitation of the way that servlet
mappings
> work in servlet 2.2.  If you define a servlet mapping that maps the
"*.jsp"
> extension to the JSP servlet (as Tomcat does by default), then the JSP
servlet
> will be executed -- bypassing your security checks.  If you register the
"*.jsp"
> extension to your own servlet, then you will receive the request -- but
there is
> no way to forward control later to get the JSP page executed.
>
> This kind of issue was one of the motivating factors for the Filter API of
the
> new servlet 2.3 spec (which Tomcat 4.0 supports).  This lets you register
> filters that can preprocess (and postprocess, if you want) requests to
> particular URI patterns, completely independently of which servlets will
> actually process those requests.
>
> For your use case, you could write a filter that is mapped to the "*.jsp"
> extension.  It would look at the request, before the JSP system ever sees
it.
> If your security checks are satisfied, simply pass the request on through
the
> filter chain, which will cause the page to be executed in the usual way.
If a
> check fails, you can redirect the user to an error page instead.
>
> Craig McClanahan
>
>




RE: question about RequestDispatcher.forward() in tomcat

2000-11-14 Thread Kedar Choudary

Following code will do the job
-
import javax.servlet.*;
import javax.servlet.http.*;

import java.io.*;
import java.util.*;

public class Controller extends HttpServlet {
public void service(ServletRequest req, ServletResponse res) throws
ServletException, IOException {
res.setContentType("text/html");
PrintWriter out = res.getWriter();
out.println("This is from Contrller\n");
out.flush();

ServletContext ctx = getServletContext();
RequestDispatcher rd = ctx.getNamedDispatcher("jsp");
rd.include(req, res);
}
}
---

-Original Message-
From: Lacerda, Wellington (AFIS) [mailto:[EMAIL PROTECTED]]
Sent: Monday, November 13, 2000 4:03 PM
To: '[EMAIL PROTECTED]'
Subject: RE: question about RequestDispatcher.forward() in tomcat


I wrote a small MVC framework and I have my controller mapped to a common
name like "dispatch.htm" and I send all requests directly to it, with a
parameter specifying the action. So, all the requests are always like:

do something

It's working fairly well.

Wellington Silva
UN/FAO

-Original Message-
From: Chen, Kevin [mailto:[EMAIL PROTECTED]]
Sent: 09 November 2000 00:32
To: '[EMAIL PROTECTED]'
Subject: question about RequestDispatcher.forward() in tomcat


I am trying to implement a MVC system. the controller
will intercept all request for .jsp page, then forward
it to the jsp page after some checking.

I am using TOMCAT to run the servlet. and using
extension rul mapping, i.e.:(in web.xml)

 controller 
 *.jsp 

My test controller just forward the page to another jsp page,
the code looks like:
RequestDispatcher dis;
dis=getServletContext().getRequestDispatcher("/index.jsp");
dis.forward (req, res);
//dis.include (req, res);

the problem with above approach is that, my controller will
intercept the index.jsp too. which will cause the page cannot
be displayed. looks like the servlet container resend the
index.jsp page to me again and again.


Is there anyway around it?

Appreciate any help.
kevin