Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

listener tag makes the service false

 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Friends,

When i add the tag for listener in the web.xml, it makes the startup fails of my application. Below is my web.xml file.
Please help....

<?xml version="1.0" encoding="ISO-8859-1"?>
<web-app>
<context-param>
<param-name>companyName</param-name>
<param-value>not-dot-com.com</param-value>
</context-param>

<context-param>
<param-name>formerCompanyName</param-name>
<param-value>hot-dot-com.com</param-value>
</context-param>

<listener>
<listener-class>coreservlets.listeners.InitialCompanyNameListener</listener-class>
</listener>

<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>

</web-app>
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2339
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the error you get?
How does your listener class look like?
How is the structure of your web-app?

Regards,
Frits
 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error is that it could not deploy my application. It gives message like SEVERE: Error listenerStart

package myPkg;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
public class InitialCompanyNameListener implements ServletContextListener {
private static final String DEFAULT_NAME = "MISSING-COMPANY-NAME";

public void contextInitialized(ServletContextEvent event) {

ServletContext context = event.getServletContext();
setInitialAttribute(context,"companyName",DEFAULT_NAME);
setInitialAttribute(context,"formerCompanyName","");

}
public void contextDestroyed(ServletContextEvent event) {}


private void setInitialAttribute(ServletContext context,String initParamName,String defaultValue)
{
String initialValue = context.getInitParameter(initParamName);
if (initialValue != null) {
context.setAttribute(initParamName, initialValue);
}
else
{
context.setAttribute(initParamName, defaultValue);
}
System.out.println(initialValue+"PARAM: " + initParamName);
}
}


This file is within WEB-INF/classes/myPkg;
My web.xml is in WEB-INF


 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2339
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
change:

into:


That should help.

Regards,
Frits
 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello Frits,

Have done that, but it does not work. Actually have changed the package after the first post, so it was the earlier version.
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So put the most actual code you try to deploy. It's hard to guess what did you change...

Also try commenting your methods code - compile it and redeploy. You will now if the listener is properly initialized (empty) and if so, then you can modify it's code.

Rupal Rshah wrote:This file is within WEB-INF/classes/myPkg;


I hope you mean the *.class file of this source code, right? :-)

Cheers!
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2339
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, I included everything in my tomcat 5.5 server and it worked well.

How do you create your .war file? It looks like the wep-app can't find your listener....
What tomcat server are you using?

Regards,
Frits
 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am using Tomcat 7. I have not created .war file for this application
 
Frits Walraven
Creator of Enthuware JWS+ V6
Saloon Keeper
Pie
Posts: 2339
90
Android Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your problem might be caused by a directory structure problem, try to build a .war file by hand.

you can use the following instructions: HowToCreateWebApplicationWithoutAnIDE

Regards,
Frits
 
Rupal Rshah
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you all....My problem got solved
 
Piotr Nowicki
Ranch Hand
Posts: 611
1
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So, share with the rest what was the problem, so if someone else bump into the same problem, will not what you did to fix it :-)

Cheers!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic