You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by shanmugampl <sh...@india.adventnet.com> on 2002/10/04 13:50:52 UTC
Getting the name of the context
Hi,
I have a requirement where i need to know the name of the context i am
in.Say i have a servlet class present in my <Tomcat_Home>/webapp/myapp/.
Now i want to get the name of the application(in this case 'myapp') from
my servlet. Is there a way of doing it. One of the way i found was
specifying a name for the <display-name> attribute present in the
web.xml. This name can be retrieved from the ServletContext. The problem
here is two contexts can have the same display name which is not desired.
Thanks
Shanmugam.PL
Re: I need to run a servlet periodically
Posted by Malachi de AElfweald <ma...@tremerechantry.com>.
Unless you are just trying to do refresh, in which case you
could use the meta-tags to do auto-refresh and server-push.
If you were trying to do a servlet that managed something
always running, then you would want a daemon that could handle
live-updates.
Please be more clear on the usage.
Malachi
10/5/2002 3:47:59 AM, Nikola Milutinovic <Ni...@ev.co.yu> wrote:
>Filip Rachunek wrote:
>
>> Hello,
>> is it possible to have a servlet in Tomcat container
>> which is invoked automatically each gived time period?
>> [e.g. each 10 minutes] And I would also need this
>> special servlet to access other resources of my web
>> application [connection pool, ...].
>
>You're making a mistake. A Java Servlet is a Java component that responds to a
>web request. That's it - nothing more, nothing less, just what it is designed for.
>
>It is not designed to be a "cron job". Something like that doesn't belong to a
>web application - or should we say, to the web GUI part of a web application. In
>a full JEE application which has a web portal (like Tomcat), you would place
>such a "cron job" somewhere other than a web interface. I'm not sure where, I'm
>no expert on JEE (yet).
>
>This was like asking "can CGI script be configured to run at regular
>intervals?". Of course you could run a cron job that would act as a web client
>and send a request that would fire up that CGI or Servlet. But that is going
>slightly around it. And doing it at the wrong point.
>
>Web applications are request driven application and should not be twisted into
>something unnatural. Use a regular cron job for this.
>
>Nix.
>
>
>--
>To unsubscribe, e-mail: <ma...@jakarta.apache.org>
>For additional commands, e-mail: <ma...@jakarta.apache.org>
>
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: I need to run a servlet periodically
Posted by Nikola Milutinovic <Ni...@ev.co.yu>.
Filip Rachunek wrote:
> Hello,
> is it possible to have a servlet in Tomcat container
> which is invoked automatically each gived time period?
> [e.g. each 10 minutes] And I would also need this
> special servlet to access other resources of my web
> application [connection pool, ...].
You're making a mistake. A Java Servlet is a Java component that responds to a
web request. That's it - nothing more, nothing less, just what it is designed for.
It is not designed to be a "cron job". Something like that doesn't belong to a
web application - or should we say, to the web GUI part of a web application. In
a full JEE application which has a web portal (like Tomcat), you would place
such a "cron job" somewhere other than a web interface. I'm not sure where, I'm
no expert on JEE (yet).
This was like asking "can CGI script be configured to run at regular
intervals?". Of course you could run a cron job that would act as a web client
and send a request that would fire up that CGI or Servlet. But that is going
slightly around it. And doing it at the wrong point.
Web applications are request driven application and should not be twisted into
something unnatural. Use a regular cron job for this.
Nix.
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
I need to run a servlet periodically
Posted by Filip Rachunek <fi...@yahoo.com>.
Hello,
is it possible to have a servlet in Tomcat container
which is invoked automatically each gived time period?
[e.g. each 10 minutes] And I would also need this
special servlet to access other resources of my web
application [connection pool, ...].
Thanks.
Filip Rachunek
__________________________________________________
Do you Yahoo!?
Faith Hill - Exclusive Performances, Videos & More
http://faith.yahoo.com
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Getting the name of the context
Posted by "Craig R. McClanahan" <cr...@apache.org>.
On Sat, 5 Oct 2002, shanmugampl wrote:
> Date: Sat, 05 Oct 2002 09:22:23 +0530
> From: shanmugampl <sh...@india.adventnet.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> shanmugampl@india.adventnet.com
> To: tomcat-user@jakarta.apache.org
> Subject: Re: Getting the name of the context
>
>
> Thanks for your suggestion, but i load the servlet on startup by giving
> it in the <load-on-startup>. In the servlets init method i will be
> initializing some basic parameters. Here I want the name of the context
> for regestering it. I do not have access to the request object from my
> init method. How do i get the name in this case.
>
You can't.
The main reason is that you are making an incorrect assumption that your
webapp has only *one* context path (or even one virtual host). It is
quite common for the same webapp instance to be exposed under more than
one name -- the most common example is the large number of websites that
are available under both "foo.com" and "www.foo.com" hostnames. It is
also possible to make the same webapp available under multiple context
paths on the same server.
The bottom line is that there is no such thing as *the* (single) context
path for a particular web application.
Craig
>
> Craig R. McClanahan wrote:
>
> >Use request.getContextPath().
> >
> >Craig
> >
> >On Fri, 4 Oct 2002, shanmugampl wrote:
> >
> >
> >
> >>Date: Fri, 04 Oct 2002 17:20:52 +0530
> >>From: shanmugampl <sh...@india.adventnet.com>
> >>Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> >> shanmugampl@india.adventnet.com
> >>To: tomcat-user@jakarta.apache.org
> >>Subject: Getting the name of the context
> >>
> >> Hi,
> >>
> >>I have a requirement where i need to know the name of the context i am
> >>in.Say i have a servlet class present in my <Tomcat_Home>/webapp/myapp/.
> >>Now i want to get the name of the application(in this case 'myapp') from
> >>my servlet. Is there a way of doing it. One of the way i found was
> >>specifying a name for the <display-name> attribute present in the
> >>web.xml. This name can be retrieved from the ServletContext. The problem
> >>here is two contexts can have the same display name which is not desired.
> >>
> >>Thanks
> >>Shanmugam.PL
> >>
> >>
> >>
> >
> >
> >
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
How to avoid the staus code (-1) being sent from Servlet to Applet? Tomcat experts please Help!!
Posted by sunita desai <su...@cisco.com>.
Hi,
To explain my problem, I have a plain Applet-Servlet communication.
The servlet just reads an backend socket connection contents and keeps
sending every 50 lines of information to the Applet.
And the applet after receiving every 50 lines, displays it in TextArea
without interpreting the data.And invokes the Servlet again as a URL.
After every invocation of Servlet when I check the
HttpConnection.getResponseCode
in the Applet, it gives me status code 200 and message "OK". And everything
is O.k, in the sense the Applet displays only the actual data or the content
being sent from Servlet.But sometimes, eventhough it is the same URL that is
being invoked and Servlet is sent the next 50 lines as ususal, I get the
Status code as "-1" and the HttpConnection.getResponseMessage returns me
"null". And when this happens the actual HTTP header content(along with some
HEX codes) is being displayed as data in the Applet display area, which
distorts the actual data coming from the Socket connection.
And then the next invocation of Servlet works fine as usual with status code
200. And the whole logic is working within a loop, so there can't be problem
with that specific invocation of Servlet. If so then what could be the
problem for sending "-1" status code.
But this behaviour is observed only sometimes,It happends randomly,Please
give any pointers or suggestions as to how I can avoid this problem?Please
advice.
Is this some kind of known problem with Apache tomcat version 4.0.3?
The Applet display output before and after the error looks like this:
h323-ivr-out=reroute-count:0
h323-ivr out=route:INCCARRIER|Z1_SP_NTKG|11011|0|2|Z1_HK_OP|Z1_HK_
OP1_TG2|11009|0|
Acct_in_octets:742
Acct_out_octets:806
Acct_in_packets:39
HTTP/1.1 200 OK
Content-Type: text/html
Date: Wed, 18 Sep 2002 20:07:08 GMT
Transfer-Encoding: chunked
Server: Apache Tomcat/4.0.3 (HTTP/1.1 Connector)
5c
Acct_out_packets:46
1
62
Acct_session_time:20 secs
1
7d
h323-disconnect-time=10:54:56.709 EST Sun May 5 2002
1
63
h323-disconnect-cause=10
1
69
h323-remote-address=10.15.89.150
1
5d
h323-voice-quality=0
1
78
alert-timepoint=10:54:34.559 EST Sun May 5 2002
1
70
gw-rxd-cdn=ton:1,npi:1,#:00161414444756
1
76
gw-final-xlated-cdn=ton:1,npi:1,#:61414444756
1
73
gw-rxd-cgn=ton:4,npi:1,pi:0,si:1,#:8381756
1
59
info-type=speech
1
I appreciate any help in this regard,
Thanks in advance,
Sunita
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Getting the name of the context
Posted by shanmugampl <sh...@india.adventnet.com>.
Thanks for your suggestion, but i load the servlet on startup by giving
it in the <load-on-startup>. In the servlets init method i will be
initializing some basic parameters. Here I want the name of the context
for regestering it. I do not have access to the request object from my
init method. How do i get the name in this case.
Craig R. McClanahan wrote:
>Use request.getContextPath().
>
>Craig
>
>On Fri, 4 Oct 2002, shanmugampl wrote:
>
>
>
>>Date: Fri, 04 Oct 2002 17:20:52 +0530
>>From: shanmugampl <sh...@india.adventnet.com>
>>Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
>> shanmugampl@india.adventnet.com
>>To: tomcat-user@jakarta.apache.org
>>Subject: Getting the name of the context
>>
>> Hi,
>>
>>I have a requirement where i need to know the name of the context i am
>>in.Say i have a servlet class present in my <Tomcat_Home>/webapp/myapp/.
>>Now i want to get the name of the application(in this case 'myapp') from
>>my servlet. Is there a way of doing it. One of the way i found was
>>specifying a name for the <display-name> attribute present in the
>>web.xml. This name can be retrieved from the ServletContext. The problem
>>here is two contexts can have the same display name which is not desired.
>>
>>Thanks
>>Shanmugam.PL
>>
>>
>>
>
>
>
Re: Getting the name of the context
Posted by "Craig R. McClanahan" <cr...@apache.org>.
Use request.getContextPath().
Craig
On Fri, 4 Oct 2002, shanmugampl wrote:
> Date: Fri, 04 Oct 2002 17:20:52 +0530
> From: shanmugampl <sh...@india.adventnet.com>
> Reply-To: Tomcat Users List <to...@jakarta.apache.org>,
> shanmugampl@india.adventnet.com
> To: tomcat-user@jakarta.apache.org
> Subject: Getting the name of the context
>
> Hi,
>
> I have a requirement where i need to know the name of the context i am
> in.Say i have a servlet class present in my <Tomcat_Home>/webapp/myapp/.
> Now i want to get the name of the application(in this case 'myapp') from
> my servlet. Is there a way of doing it. One of the way i found was
> specifying a name for the <display-name> attribute present in the
> web.xml. This name can be retrieved from the ServletContext. The problem
> here is two contexts can have the same display name which is not desired.
>
> Thanks
> Shanmugam.PL
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
Re: Getting the name of the context
Posted by Tim Funk <fu...@joedog.org>.
HttpServletRequest.getContextPath() returns the context path name.
jon wingfield wrote:
> you could extract it from servletContext.getRealPath("/");
>
> -----Original Message-----
> From: shanmugampl [mailto:shanmugampl@india.adventnet.com]
> Sent: 04 October 2002 12:51
> To: tomcat-user@jakarta.apache.org
> Subject: Getting the name of the context
>
>
> Hi,
>
> I have a requirement where i need to know the name of the context i am
> in.Say i have a servlet class present in my <Tomcat_Home>/webapp/myapp/.
> Now i want to get the name of the application(in this case 'myapp') from
> my servlet. Is there a way of doing it. One of the way i found was
> specifying a name for the <display-name> attribute present in the
> web.xml. This name can be retrieved from the ServletContext. The problem
> here is two contexts can have the same display name which is not desired.
>
> Thanks
> Shanmugam.PL
>
>
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>
RE: Getting the name of the context
Posted by jon wingfield <jo...@mkodo.com>.
you could extract it from servletContext.getRealPath("/");
-----Original Message-----
From: shanmugampl [mailto:shanmugampl@india.adventnet.com]
Sent: 04 October 2002 12:51
To: tomcat-user@jakarta.apache.org
Subject: Getting the name of the context
Hi,
I have a requirement where i need to know the name of the context i am
in.Say i have a servlet class present in my <Tomcat_Home>/webapp/myapp/.
Now i want to get the name of the application(in this case 'myapp') from
my servlet. Is there a way of doing it. One of the way i found was
specifying a name for the <display-name> attribute present in the
web.xml. This name can be retrieved from the ServletContext. The problem
here is two contexts can have the same display name which is not desired.
Thanks
Shanmugam.PL
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>