This week's book giveaways are in the Refactoring and Agile forums.
We're giving away four copies each of Re-engineering Legacy Software and Docker in Action and have the authors on-line!
See this thread and this one for details.
Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization 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:
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic