Hi Joona:
What you need to do is supply your own Default Constructor plus the
Constructors that you want to use:
class FunkyServlet extends javax.http.HttpServlet
{
public FunkyServlet(){
}
public FunkyServlet(String arg)
{
System.out.println("I'm a funky servlet, instantiated like a
Java class");
System.out.println("I got an argument: "+arg);
}
You also have to make sure that the default Constructor is public. All
should be OK after that.
Chris Gow
[EMAIL PROTECTED]
> -----Original Message-----
> From: Joona Palaste [SMTP:[EMAIL PROTECTED]]
> Sent: Friday, August 20, 1999 3:33 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Constructors in servlets?
>
> At 12:11 PM 8/20/99 +0530, you wrote:
> >Hi Joona,
> > You can have constructors but those constructors cannot have
> arguments.
> > You can instead use the init() method as a substitute for
> constructor
> > with argument.
> >
> >Manu.
>
> Righto. But what if I need to use a servlet object without running it as a
> servlet? Here's what I want to be able to do:
>
> class FunkyServlet extends javax.http.HttpServlet
> {
> public FunkyServlet(String arg)
> {
> System.out.println("I'm a funky servlet, instantiated like a Java
> class");
> System.out.println("I got an argument: "+arg);
> }
> public void doGet(HttpRequest request, HttpResponse response) throws
> ServletException, IOException
> {
> System.out.println("I'm a funky servlet, run from a HTTP GET
> request");
> // here's where I write what the servlet does with doGet
> }
> }
>
> class ConsoleApplication
> {
> // there are some methods here
> public void someMethod()
> {
> new FunkyServlet("my argument");
> }
> }
>
> Is this in any way possible? If so, please tell me how! Thanks!
>
> Joona Palaste
>
> __________________________________________________________________________
> _
> 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