In relation to the last two questions...

>>   another question is that i implement a thread in my servlet, however
>> it can only run() once, that is the first time the user invoke the
>> servlet. if the user tried another time (even if i reload the page),
>> the thread will never be executed until the system has been reboot. y
>> is this??....

Sounds like you're calling the thread from the init() method of the servlet.
This is only called once when the servlet is loaded by the web server. If
the web server keeps the servlet in memory it will not be called again. If
you want the thread to run every time the servlet receives a request, you
should put it in the doGet() or doPost() methods instead.


>>   within a servlet how do i redirect user to a html page and for every
>> 10 seconds the servlet will reload the page meaning that there will be
>> a loop within the servlet. my point here is to allow the servlet to
>> get new values from a file (the values inside the file will be changed
>> frequently) and display it to the same window everytime with updated
>> values.

If you want the page on the server to be updated so that the client always
gets the latest version, the you could start a new thread in the servlet's
init() routine which updates the HTML page every 10 seconds. That way the
client will always get the latest version.

However, if you want the client's page to be automatically refreshed every
10 seconds, so that they can sit back and watch the values changes, to the
best of my knowledge, you can't make a servlet do it. What you *can* do,
which has the same effect is include the following HTML META TAG in the
page...

<META HTTP-EQUIV="Refresh" CONTENT="10">

This will cause the *browser* to refresh the page every 10 seconds. The
servlet can then provide the latest version on each request.


One last point...
>>   i would like to call a another servlet from within a servlet and
>> passing in valueS to the other servlet into doGet(). how do i do
>> that?....would you tell me in details please.
>
>You can call another servlet from a servlet by getting the handle to the
>other servlet like below:
>>From BServlet's doGet(req,res) or doPost(req,res) you can call AServlet's
>doGet() or doPost() or any public methods.
>
>       AServlet login=
>
(AServlet)getServletConfig().getServletContext().getServlet("AServlet");
>                if(login != null)
>                        login.doGet(req,res);
>
>
>This method is possible if both the servlets are in the same server.
>
>if they are in different servers then use oreilly's class HttpMessage
>class to pass values. (www.oreilly.com).
>
>

The servlet 2.0 API says the following about the "getServlet()" method:

> Note: This is a dangerous method to call for the following reasons.
> * When this method is called the state of the servlet may not be known,
and this could cause problems with the server's servlet state machine.
> * It is a security risk to allow any servlet to be able to access the
methods of another servlet.

Can you not just use the HttpServletResponse.sendRedirect() method to
redirect the user to the other servlet? You could then pass the values in
the URL ("/servlets/otherservlet?val1=something&val2=somethingelse") and
they would be received in the doGet() method of the other servlet...


-----Original Message-----
From: Revathy Ravi <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
Date: Tuesday, April 13, 1999 12:31 PM
Subject: Re: servlet calling a servlet ?


>On Tue, 13 Apr 1999, ALEX L wrote:
>
>> Hi there,
>>   can anyone please help.
>>   i would like to call a another servlet from within a servlet and
>> passing in valueS to the other servlet into doGet(). how do i do
>> that?....would you tell me in details please.
>
>You can call another servlet from a servlet by getting the handle to the
>other servlet like below:
>>From BServlet's doGet(req,res) or doPost(req,res) you can call AServlet's
>doGet() or doPost() or any public methods.
>
>       AServlet login=
>
(AServlet)getServletConfig().getServletContext().getServlet("AServlet");
>                if(login != null)
>                        login.doGet(req,res);
>
>
>This method is possible if both the servlets are in the same server.
>
>if they are in different servers then use oreilly's class HttpMessage
>class to pass values. (www.oreilly.com).
>
>
>>   also it seems that if my client is an html client, the only (in
>> order to pass some values to the servlet) is by using FORM. is this
>> true or is there another way to do it. can i use i url link to the
>> servlet?
>
>You can use URL link and pass values as parameters.
>
><html>
><body>
><a href=/servlet/AServlet?user=name>AServlet</a>
><body>
><html>
>
>
>>   another question is that i implement a thread in my servlet, however
>> it can only run() once, that is the first time the user invoke the
>> servlet. if the user tried another time (even if i reload the page),
>> the thread will never be executed until the system has been reboot. y
>> is this??....
>>   within a servlet how do i redirect user to a html page and for every
>> 10 seconds the servlet will reload the page meaning that there will be
>> a loop within the servlet. my point here is to allow the servlet to
>> get new values from a file (the values inside the file will be changed
>> frequently) and display it to the same window everytime with updated
>> values.
>>
>> thanks a lot for you time.
>>
>> regards,
>> alex
>>
>>
>>
>> ______________________________________________________
>> Get Your Private, Free Email at http://www.hotmail.com
>>
>>
___________________________________________________________________________
>> 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
>>
>
>Hope my explanation helps!!!
>Revathy
>
>___________________________________________________________________________
>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

Reply via email to