Yes, you need take a look at the servlet life-cycle. The init method is
processed only when the server loads this servlet class file. No other time
is the init method processed. Only the doGet() and doPost() methods are ran
when a user accesses the servlet (depending of course on which method(s) you
implement). Therefore there is no one accessing the servlet at the init and
no response can be sent. If one could be sent there would be no where to
send it to. You must do all processing and responses within the confines of
the doGet() and doPost() methods.
There have been many discussions on this list about user authentication
strategies. Check the archives and you should find a few good ideas and
examples.
Matt
On Fri, 20 Jul 2001, Milt Epstein wrote:
> On Fri, 20 Jul 2001, Ouyang, Jian wrote:
>
> > Thanks Richard.
> >
> > My project requires all and every pages be secured. So I have to
> > check the user before display any pages, even the index.html page.
>
> Why does this necessitate doing anything in init()? You simply do the
> check as the first thing in doGet()/doPost().
>
>
> > I do not get what you said. Can you be more specific? My problem
> > is that response is not available in the init method.
>
> I think you are misunderstanding the servlet lifecycle. There is no
> response (or request) in the context of init(), so what you are asking
> doesn't really make sense. There are lots of good sources that
> describe the servlet lifecycle -- like tutorials at Sun's web site or
> any decent servlet book.
>
>
> > -----Original Message-----
> > From: Richard Yee [mailto:[EMAIL PROTECTED]]
> > Sent: Friday, July 20, 2001 9:50 AM
> > To: [EMAIL PROTECTED]
> > Subject: Re: initial html page from init() method
> >
> >
> > Jian,
> > Can you tell us why you need to return a page directly from the init
> > method? You could just set a flag in one of your service methods that
> > causes it to return the proper page after the init method is first called.
> >
> > Regards,
> >
> > Richard
> >
> > At 09:32 AM 7/20/01 -0400, you wrote:
> > >Hi
> > >
> > >Can any body share with how to send a html page to the browser with
> > >in the init() method in a servlet?
> > >
> > >Thanks.
> > >
> > >Jian
>
> Milt Epstein
> Research Programmer
> Software/Systems Development Group
> Computing and Communications Services Office (CCSO)
> University of Illinois at Urbana-Champaign (UIUC)
> [EMAIL PROTECTED]
>
> ___________________________________________________________________________
> To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
> of the message "signoff SERVLET-INTEREST".
>
> Archives: http://archives.java.sun.com/archives/servlet-interest.html
> Resources: http://java.sun.com/products/servlet/external-resources.html
> LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
>
___________________________________________________________________________
To unsubscribe, send email to [EMAIL PROTECTED] and include in the body
of the message "signoff SERVLET-INTEREST".
Archives: http://archives.java.sun.com/archives/servlet-interest.html
Resources: http://java.sun.com/products/servlet/external-resources.html
LISTSERV Help: http://www.lsoft.com/manuals/user/user.html