There are two ways to get the servlet context object inside struts 2 action class’s execute method. ServletActionContext : Directly accessing the getContext method from the ServletActionContext class will return the context object. ServletContextAware : If you implement the action class with ServletContextAware interface, then struts controller will send the context object through setServletContext method. …
Java
Get URL Content using Java
This example shows how to download a URL content to your local machine. If you look at the below example, it simply takes an URL as the input and get the content and save it to the local system. File Upload and Download Using Java
java.lang.ClassNotFoundException: javassist.ClassPath
When you work with Hibernate or Thymeleaf, it is probably that you would get the below exception. It may happen any other projects too if that library has the dependency with javaassist library. I have got this exception when I started developing my first Hello World application using Thymeleaf template framework. The reason for the …
Binary Search Tree Traversal Implemented in Java
Most of the students fresh out of their engineering studies or those who are still studying will have the concept of Binary Search Trees fresh in their minds. But with most of the people who have been out of college for many years now will kind of be having a not so clear idea of …
Jersey : The ResourceConfig instance does not contain any root resource classes
When you are working with Jersey REST web services, you would encounter the following exception. This is occurred either of two reasons. com.sun.jersey.config.property.packages doesn’t exist in your web.xml. com.sun.jersey.config.property.packages included a package path, but that is not included any jersey services. If you check the above two reasons and resolve it, the below exception will …
java.lang.NoClassDefFoundError: org/objectweb/asm/ClassVisitor
When you work on Hibernate, Jersey or any third party API, most of these APIs have the dependency with the asm.jar file. ASM is an all purpose Java bytecode manipulation and analysis framework. This is a common framework used by many of the thrird part frameworks internally, that is the reason many projects have this …
Expected Exception Test in JUnit 4
In my previous article I have written down the sample code for Junit 4 testing using annotations. In this tutorial I would like to write about expected exception testing and Rules which is introduced from JUnit 4.7. JUnit 4 introduced the expected parameter, which makes a test succeed if and only if a certain exception is thrown. In …
JUnit 4 Annotation Example
This tutorial explains the basic usage of JUnit 4 annotations. JUnit is the most popular Unit testing framework most widely used by the Java developers. After the release of Java 5.0 annotations, JUnit 4 has updated to support the annotation programming for the testing methods. Also it introduced @BeforeClass and @AfterClass methods which has to …