Say that again?  If you have a servlet, it extends HttpServlet, and you most
certainly have access to the Request object, as well as the Response object.

John Turner
[EMAIL PROTECTED]


-----Original Message-----
From: Christian J. Dechery [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, July 10, 2002 1:00 PM
To: [EMAIL PROTECTED]
Subject: Re: Need Ideas... big problem! (long)


But I want the code I would write in the A class... cuz I will create a
Servlet to provide a connection to the JSPs, but I don't wanna change the
JSPs... inside my Servlet (A) I don't have access to the request object.
 
Could u write some example code for the A class to figure in which context
the method doSomething() was called?
 
Thanks...
 
.:| Christian J. Dechery
.:| FINEP - Depto. de Sistemas
.:| [EMAIL PROTECTED]
.:| (21) 2555-0332

>>> [EMAIL PROTECTED] 10/07/02 13:51 >>> 


On Wed, 10 Jul 2002, Christian J. Dechery wrote: 

> Date: Wed, 10 Jul 2002 13:27:26 -0300 
> From: Christian J. Dechery < [EMAIL PROTECTED] > 
> Reply-To: Tomcat Users List < [EMAIL PROTECTED] > 
> To: [EMAIL PROTECTED] 
> Subject: Re: Need Ideas... big problem! (long) 
> 
> I'm having some difficulty understanding the solution u guys provided
me... maybe I explained my problem badly, so u aren't fully understanding
it... 
> 
> but I have a question that is quite simple: Is it possible for a class 
> (or Servlet) located in $tomcat_home\common\classes - that will be 
> accessed from all webapps - to know from which context a JSP/Servlet 
> called it? 
> 
> for example... I have a class A in common\classes and it has a method
doSomething()... say I have a JSP $tomcat_home\webapps\test\1.jsp that looks
something like: 
> 
> <%@page import="A"%> 
> <% 
> String x = A.doSomething(); 
> %> 
> 
> so... would it be possible for A to know that when doSomething() was 
> called, the context was "test"? 
> 

Sure ... that's really easy. You've got at least the following options: 

* Call request.getContextPath() and you'll get the context path of the 
web application that is responding to this request. 

* The "application" object in a JSP page is in fact the ServletContext 
for the current webapp, so you can call things like 

<% 
Properties props = new Properties(); 
InputStream stream = 
application.getResourceAsStream("/WEB-INF/myprops.properties"); 
props.load(stream); 
stream.close(); 
%> 

to load a properties file from inside the WEB-INF subdirectory of your web 
application. 

As a general note, however, you should really be doing this sort of thing 
in startup code of a servlet, which stashes the results as servlet context 
parameters for everyone else to use. Using scriptlets to mix functional 
logic into your JSP pages is going to cause you maintenance nightmares 
over time. 

Craig 


-- 
To unsubscribe, e-mail: < mailto:[EMAIL PROTECTED]
> 
For additional commands, e-mail: <
mailto:[EMAIL PROTECTED] > 




--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to