[EMAIL PROTECTED] wrote:

> The config.getInitParameter() called from within a JSP page is
> returning null. After changing the web.xml file numerous times and
> trying all the suggestions from java.sun.com and the tomcat archives I
> still cannot resolve this problem.
> Does anyone know why we can't access the init parameters?
> thanks in advance
>
> Here is what my web.xml file looks like (does not work):
>
> <web-app>
>     <servlet>
>         <servlet-name>
>            Error
>         </servlet-name>
>         <servlet-class>
>             org.apache.jasper.runtime.JspServlet
>         </servlet-class>
>         <init-param>
>             <param-name>debug</param-name>
>             <param-value>true</param-value>
>         </init-param>
>     </servlet>
> </web-app>
>
> and my JSP code:
> <%
> String s = config.getInitParameter("debug");
> if (s == null) {
> out.println("Init param must be null!");
> }
> else{
> out.println("Init param is "+s);
> }
> %>

Hi :-)  I didn't ever use jsp to get init parameters, but I guess
the reasons is: in your WEB_INF/web.xml, you only define
a servlet definition with some init parameters, but you didn't
define a servlet-mapping; and/so I guess you invoked your
servlet without url-pattern(servlet-mapping name) -> I guess
you use: http://localhost:8080/myapp/servlet/Myservlet ,
so if you use Servlet, the following will return null:
 - config.getInitParameter(...)
-  this.getInitParameter(...)


I suggest you:
-  in WEB_INF/web.xml, when you define a servlet definition
   with some init parameters, At the same time define a
   servlet-mapping
-  then use url-pattern to invoke your Servlet:
   http://localhost:8080/myapp/XXX   (XXX is url-pattern)
- if you don't want to define a servlet-definition and servlet-mapping
  Pair in WEB-INF/web.xml, you also can define init parameters
  in servlet context definition in conf/server.xml, and get them in
  your servlet with the following way:
  this.getServletContext().getInitParameter(...)



Bo
Mar.08, 2001



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, email: [EMAIL PROTECTED]

Reply via email to