When is PageContext available?
Hi! I want to do certain initializations before a jsp page is rendered. I plan to do this by using the 'extends' keyword in my jsp page and write a class that extends GenericServlet and implements HttpJspPage. The problem is that I want to get a handle to PageContext before page rendering is started, but I can't get it! I only get null. It seems PageContext is made available somewhere between the call to _jspService() and the jsp-page is entered. Below is the code. How do I get a working handle to PageContext? If it is not possible, can I somehow get a handle to JspWriter before the call to _jspService()? I am using Tomcat 4.0.2 Thanks, Claes Holmerson public abstract class TemplateJspPage extends GenericServlet implements HttpJspPage { /** * Constructor. */ public TemplateJspPage() { } /** * Initalizes the page. * @see javax.servlet.Servlet */ public void init(ServletConfig config) throws ServletException { super.init(config); jspInit(); } /** * Stub implementation here, only the JSP page may redefine. * @see javax.servlet.jsp.HttpJspPage */ public void jspInit() { } public void service(ServletRequest request, ServletResponse response) throws ServletException, IOException { HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; PageContext pageContext = JspFactory.getDefaultFactory().getPageContext(this, request, response, null, true, JspWriter.DEFAULT_BUFFER, true); System.out.println(TemplateJspPage pageContext = + pageContext); //pageContext is null //render... _jspService(req, resp); } /** * Abstract here, the JSP engine will implement, * the JSP page may _not_ redefine. * @see javax.servlet.jsp.HttpJspPage */ public abstract void _jspService(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException; /** * @see javax.servlet.Servlet */ public void destroy() { super.destroy(); jspDestroy(); } /** * Stub implementation here, only the JSP page may redefine. * @see javax.servlet.jsp.HttpJspPage */ public void jspDestroy() { } -- Claes Holmerson Polopoly - Cultivating the information garden Kungsgatan 88, SE-112 27 Stockholm, SWEDEN Direct: +46 8 506 782 59 Mobile: +46 704 47 82 59 Fax: +46 8 506 782 51 [EMAIL PROTECTED], http://www.polopoly.com -- To unsubscribe, e-mail: mailto:tomcat-user-unsubscribe;jakarta.apache.org For additional commands, e-mail: mailto:tomcat-user-help;jakarta.apache.org
I do not want to use 'webapps'
Hello! I am trying to set up Tomcat to work in the environment where we have been developing another application. In this environment we do not have a webapps directory. The output path for JBuilder is C:\sandbox\development, and this is also were the classpath points to when we test our builds. When we started developing servlets etc with JBuilder 4 we also used the docbase c:\sandbox\development So it looks something like this: C:\Sandbox\development\se\masystem\... C:\Sandbox\development\web-inf\web.xml etc C:\Sandbox\development\jsp C:\Sandbox\development\images etc.. As you see, no webapps directory. I do not want to change this structure because many things depend on this. With JBuilder 4, and its integrated tomcat 3.1 this works. I can start tomcat and get it to use a classpath that was in the same level as the docbase. That way I do not have to copy classes from C:\Sandbox\development to web-inf/classes. But now I want to be able to use tomcat independently this way. Is it possible to configure this? I guess I can do something in server.xml that I have not figured out yet? Thanks, Claes -- Claes Holmerson PipeChain AB Porfyrvägen 14 +46 (0)46 32 52 42 office phone SE-224 78 LUND +46 (0)709 89 52 42 mobile phone Sweden +46 (0)46 15 10 74 office fax http://www.pipechain.com/
inetinfo.exe crashes with Tomcat 3.2.3
Hello! I am trying to set up IIS 4.0 together with Tomcat 3.2.3 according to the Tomcat IIS howto. Big problems though. When I try to access http://localhost/examples/jsp/index.html, as the howto tells me, I get a Dr Watson dialog telling me that inetinfo.exe has crashed. It happens every time. I am using NT Server 4.0, sp 6a and IIS 4.0. Any clues to why? Thanks, Claes -- Claes Holmerson PipeChain AB Porfyrvägen 14 +46 (0)46 32 52 42 office phone SE-224 78 LUND +46 (0)709 89 52 42 mobile phone Sweden +46 (0)46 15 10 74 office fax http://www.pipechain.com/
RE: Problems with init-param
Ok, thanks for these advices. Then I have a related question: web.xml seems to be a very vital part of a web application. In it you can change parameters that you send to the applications, as well as define the urls that can be used to reach different servlets. But - when you write your servlets you can not access the url-pattern mappings in web.xml. So if you want to construct a link in one servlet to another servlet - which url do you use? The easiest one I can think of is the one with the class name, but now you say that the /servlet-prefix in it is nonstandard, or at least not specified. And using strings as specified in url-pattern in web.xml means that you have to maintain the same urls twice, manually, plus that if someone by mistake changes the url-patterns, your application will break invisibly. Is there no way to construct urls between servlets in a web-application that both gives you container independence AND compile time safety? With the latter I mean, you have to maintain the mappings in web.xml and you get no help from the compiler to find mistakes until runtime. Thanks, Claes
Problems with init-param
Hello! I can not get the init-parameters that I specify in web.xml to work correctly. When I invoke the servlet as http://localhost:8080/pipechain/servlet/se.masystem.pipeline.web.servlet.Log inServlet then in init(ServletConfig): config.getInitParameter(propertyfile); returns null, but if I invoke the servlet with http://localhost:8080/pipechain/login it works! Should not these urls be equivalent? (Tomcat 3.2.2) /Claes (please cc me as I don't subscribe to the list) Below is the relevant fragment from web.xml: servlet servlet-name Login /servlet-name servlet-class se.masystem.pipeline.web.servlet.LoginServlet /servlet-class init-param param-namepropertyfile/param-name param-valuestart.properties/param-value /init-param /servlet servlet-mapping servlet-name Login /servlet-name url-pattern /login /url-pattern /servlet-mapping -- Claes Holmerson PipeChain AB Porfyrvägen 14 +46 (0)46 32 52 42 office phone SE-224 78 LUND +46 (0)709 89 52 42 mobile phone Sweden +46 (0)46 15 10 74 office fax http://www.pipechain.com/