I apologize if I didn't answer your question, but you've honestly got me going in circles. You're saying that your servlet can't know it's context unless it gets something passed to it (which it does), and your servlet can't have something passed to it because you don't want to change JSP pages, but you're not understanding that there would be no change to JSP pages, the Request and Response objects are there automatically, and all you have to do is reference them in your class. It's so simple, I don't understand what else you need.
>From your posts, it seems blatantly obvious to me that all you need to do is reference the Request object in your class's method, and then simply call the Request object's getContextPath() method. Then parse that to know whether you have the string (like the "/test" you used in your example) that you need!! BTW, this exact same explanation was posted by Craig a couple of hours ago. So, the solution to your question has been posted twice. Reference the Request object which is automatically there (you DON'T need to change any JSP's!) and then call getContextPath. Done! Have fun! John Turner [EMAIL PROTECTED] -----Original Message----- From: Christian J. Dechery [mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 1:56 PM To: [EMAIL PROTECTED] Subject: RE: Need Ideas... big problem! (long) But that's exactly what I'm talking about... if doSomething() has to receive parameters, then the answer to my question (like 10 posts ago) is NO - there is no WAY a class/Servlet can know in which context its method was called. This can only be done if the something is passed to this class: the Context itself or the Request and Response objects... right? I know little of the Servlet spec, but my question was so simple... I guess I didn't make myself clear. Sorry to bother you all... I now know that my problem has no solution. :(( .:| Christian J. Dechery .:| FINEP - Depto. de Sistemas .:| [EMAIL PROTECTED] .:| (21) 2555-0332 >>> [EMAIL PROTECTED] 10/07/02 14:50 >>> Please, check some docs and some servlet examples. You most certainly DO HAVE both the Response object and the Request object EVERY TIME your servlet is called. That's just how it works. Whether you choose to use the objects in your class's methods is up to you. Just because you don't choose to use them doesn't mean they aren't there. For example, a servlet extends HttpServlet. Here is the HttpServlet spec, right from the source: http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/servlet/http/HttpServlet .html Please note how the methods are called. So, what you REALLY need to do, in your code, is not "doSomething() {}", but "doSomething(HttpServletRequest req, HttpServletResponse resp) {}". Check the docs! John Turner [EMAIL PROTECTED] -----Original Message----- From: Christian J. Dechery [ mailto:[EMAIL PROTECTED]] Sent: Wednesday, July 10, 2002 1:32 PM To: [EMAIL PROTECTED] Subject: Re: Need Ideas... big problem! (long) exaclty... I looked on HttpServlet... request and response are passed as parameters... so I don't HAVE it. And since it's passed as a parameter I would have to change 150 JSPs to pass this new parameter... and I don't wanna change anything, only create a new class... if in the solution comes changing all the JSPs and classes I'm sure that's not the best one... I may have asked the wrong question... let's say: public class TesteDispatcher extends HttpServlet { private static final String CONTENT_TYPE = "text/html"; //Initialize global variables public void init() throws ServletException { } //Clean up resources public void destroy() { } public String doSomething() { // this is the method... } } Is there anyway doSomething() can know in which Context it was called? Remember that this class is in \common\classes. thanks for ur patience .:| Christian J. Dechery .:| FINEP - Depto. de Sistemas .:| [EMAIL PROTECTED] .:| (21) 2555-0332 >>> [EMAIL PROTECTED] 10/07/02 14:23 >>> Hi, Christian. I would recommend now taking a good look at the Java Servlet Specification and letting all these suggestions digest while you go through that. Things should start to make more sense once you have a better handle on servlets. Maybe take a look at the Tomcat servlet examples too. Your servlet should definitely have access to the request object, since if you look at the specs on HttpServlet, you'll see that it is passed as a parameter to its various methods. HTH, -Jeff "Christian J. Dechery" To: < [EMAIL PROTECTED] > <christian@fin cc: ep.gov.br> Subject: Re: Need Ideas... big problem! (long) 07/10/02 12:30 PM Please respond to "Tomcat Users List" 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] > -- 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]>