Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Init parameter null

 
Vinod Kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
web.xml

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd">

<web-app>
<servlet>
<servlet-name>TestServlet</servlet-name>
<servlet-class>test.servlets.TestServlet</servlet-class>
<int-param>
<param-name>adminEmail</param-name>
<param-value>mymail@mydomain.com</param-value>
</int-param>
</servlet>

<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/test</url-pattern>
</servlet-mapping>
</web-app>

Servlet Code:

public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException {


Enumeration enum = getServletConfig().getInitParameterNames();
String email ="default@web.com";

while (enum.hasMoreElements() ) {

email = getServletConfig().getInitParameter("adminEmail");
}

System.out.println("EMAIL: "+ email);


}
 
Vinod Kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am getting the output as "default@web.com". Could any one help me on this?
I am using Tomcat 5.0

Thanks in advance,
Vinod
 
Jayanthi Mani
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am wondering if it is just a typo:
Can u try changing <int-param> to <init-param> and see if it works?

From this:
<int-param>
<param-name>adminEmail</param-name>
<param-value>mymail@mydomain.com</param-value>
</int-param>

To this:
<init-param>
<param-name>adminEmail</param-name>
<param-value>mymail@mydomain.com</param-value>
</init-param>

Thanks,
Jayanthi.
 
Pabak Nanda
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Jayanthi is right. That was a typo. Again please see the servlet code which is having an infinite loop. As the loop has not any breaking condition, the loop will go for ever.

Thanks,
Pabak
 
Vinod Kumar
Ranch Hand
Posts: 75
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jayathi, that was a typo! :roll:
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic