Question

The ServletContext is a powerful serlvet class to can provide a lot of information about your web application. Is there any way to get the ServletContext class in Wicket?

Answer

Yes, you can get the ServletContext class via Wicket’s WebApplication class like this :

import javax.servlet.ServletContext;
import org.apache.wicket.Page;
import org.apache.wicket.protocol.http.WebApplication;
import com.mkyong.hello.Hello;
 
public class CustomApplication extends WebApplication {
 
	@Override
	public Class<? extends Page> getHomePage() {
 
		ServletContext servletContext = WebApplication.get().getServletContext();
		return Hello.class; //return default page
 
	}
 
}
servlet-api
If Wicket application can not locate the ServletContext class, please import the servlet-api library into your project class path. For Maven, add this into your pom.xml file.

    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <version>2.4</version>
    </dependency>
Any Java questions or problems? please post at this JavaNullPointer.com forum, see you there ~
[ Read More ] You can find more similar articles at Apache Wicket Tutorials