You are currently browsing the daily archive for September 1st, 2008.

Q:how take server(tomcat, Jboss)context path for any work e:g file upload.

A:here is the solution
make a class of any name and implements ServletContextListener(its servlet calss)

write body of contextInitialized(ServletContextEvent event) method

like this

public void contextInitialized(ServletContextEvent event) {

yourUtilitiesClass.FILES_PATH = event.getServletContext().getRealPath(””) + File.separator + “files” + File.separator;
yourUtilitiesClass.IMAGES_FILES_PATH = event.getServletContext().getRealPath(””) + File.separator + “images” + File.separator;
yourUtilitiesClass.MY_RATES_XML_PATH = event.getServletContext().getRealPath(””) + File.separator + “flash” + File.separator;
}

add follwing tag in the web.xml of you web application and give your class name in the listener-class tag (that you write above)

<listener>
<listener-class>com.myproject.portal.utilities.ContextListener</listener-class>
</listener>

now what happend
on every event on your web application server.xml call the listen and set the paths in your static(calss level) variable so you can use any where in the project.

this is the sample calss

import java.io.File;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;

public class ContextListener implements ServletContextListener {

public ContextListener() {
super();
}

public void contextInitialized(ServletContextEvent event) {
yourUtilities.FILES_PATH = event.getServletContext().getRealPath(“”) + File.separator + “files” + File.separator;
yourUtilities.IMAGES_FILES_PATH = event.getServletContext().getRealPath(“”) + File.separator + “images” + File.separator;
yourUtilities.VOPIUM_RATES_XML_PATH = event.getServletContext().getRealPath(“”) + File.separator + “flash” + File.separator;
}

public void contextDestroyed(ServletContextEvent event) {

}

}

cheeerrrrrrrrs!!!

Blog Stats

  • 696 hits

 

September 2008
M T W T F S S
« Aug   Apr »
1234567
891011121314
15161718192021
22232425262728
2930  

Flickr Photos

midnight city still

More Photos