java - Issue with getting init parameters -


out.println("<br>" + getservletconfig().getinitparameter("ad")); out.print("<br>" + getservletcontext().getinitparameter("email")); 

i have jsp page.

when run app returns null, instead of email.

but when use in servlet code runs fine.

here complete code:

<%  list styless = (list) request.getattribute("styles"); int n = styless.size(); (int = 0; < n; i++) {     out.print("<br>" + styless.get(i)); } out.println("<br>" + getservletconfig().getinitparameter("ad")); out.print("<br>" + getservletcontext().getinitparameter("email")); %>  

in code neither servletconfig or servletcontext working both returning null,but same thing working in servlet

web.xml

<servlet>      <servlet-name>ch3 beer</servlet-name>      <servlet-class>action.beerselect</servlet-class>      <init-param>          <param-name>ad</param-name>          <param-value>hawc91@gmail.com</param-value>      </init-param>  </servlet> <context-param>      <param-name>email</param-name>      <param-value>rnsal28@yahoo.com</param-value>  </context-param>  

as code described in question, email parameter should display both in jsp , servlet (and does, tested it) using code getservletcontext().getinitparameter("email").

now ad parameter, displays null (correctly) in jsp because parameter in local servlet. ad available(and that's should be) inside servlet code , can accessed using getservletconfig().getinitparameter("ad")


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -