GeeCON Prague 2014*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes listener tag makes the service false Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "listener tag makes the service false" Watch "listener tag makes the service false" New topic
Author

listener tag makes the service false

Rupal Rshah
Greenhorn

Joined: Aug 13, 2010
Posts: 19
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>


With Regards & Thanks

Rupal
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1686
    
  25

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

Joined: Aug 13, 2010
Posts: 19
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
Bartender

Joined: Apr 07, 2010
Posts: 1686
    
  25

change:

into:


That should help.

Regards,
Frits
Rupal Rshah
Greenhorn

Joined: Aug 13, 2010
Posts: 19
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

Joined: Jul 13, 2010
Posts: 610

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!


OCP Java SE 6 Programmer, OCM Java SE 6 Developer, OCE Java EE 6 JSPSD, OCE Java EE 6 EJBD, OCE Java EE 6 JPAD, Spring 3.0 Core Professional.
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1686
    
  25

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

Joined: Aug 13, 2010
Posts: 19
I am using Tomcat 7. I have not created .war file for this application
Frits Walraven
Creator of Enthuware JWS+ V6
Bartender

Joined: Apr 07, 2010
Posts: 1686
    
  25

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

Joined: Aug 13, 2010
Posts: 19
Thank you all....My problem got solved
Piotr Nowicki
Ranch Hand

Joined: Jul 13, 2010
Posts: 610

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!
 
GeeCON Prague 2014
 
subject: listener tag makes the service false