@Repeatable Annotation in Java 8

java-thumbnail

There are many features in the Java 8 release. Only few of them are discussed in the blogs and few are not noticed by many developers are not advertised as it is not popularly used by the common developers. One of such feature is the introduction of @Repeatable¬†annotation which tells the compiler that that annotation […]

Struts 2 + Log4j Integration

struts2-thumbnail

This example demonstrates how to integrate log4j to your struts 2 project. Add log4j.jar file in your project lib folder Create log4j.xml file with loggers and appenders. Here I have added file and console appenders. Each log message will be printed in console and a file. Make sure that log4j.xml file is in the classpath. […]

HttpServletContext in Struts 2 Action Class

struts2-thumbnail

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. […]

HttpServletResponse in Struts 2 Action Class

struts2-thumbnail

There are two ways to get the servlet response object inside struts 2 action class’s execute method. ServletActionContext : Directly accessing the getresponse method from the ServletActionContext class will return the response object. ServletResponseAware : If you implement the action class with ServletResponseAware interface, then struts controller will send the response object through setServletResponse method. […]

HttpServletRequest in Struts 2 Action Class

struts2-thumbnail

There are two ways to get the servlet request object inside struts 2 action class’s execute method. ServletActionContext : Directly accessing the getRequest method from the ServletActionContext class will return the request object. ServletRequestAware : If you implement the action class with ServletRequestAware interface, then struts controller will send the request object through setServletRequest method. […]

Struts 2 Interceptors Example

struts2-thumbnail

Interceptors are powerful mechanism to control the flow of each request. These are custom and default implementations which can be enforced to work as the callback methods at certain point of time. Struts 2 provides handful of default interceptors behind the scenes. One example is the exception handling at action level. Also we can write […]

Struts 2 + JSON Integration

struts2-thumbnail

Struts 2 provides struts2-json-plugin.jar for supporting the conversion of result type to JSON strings. Nowadays every framework supports the JSON formats because it is the most preferred format for the REST web services. This example shows how you can integrate Struts 2 and JSON. Get the struts2-json-plugin.jar and add to the lib folder In the […]

Struts 2 Annotation Example

struts2-thumbnail

Struts 2 supports annotations out of the box in its latest release without even a single line of configuration changes. You are not needed to create struts.xml file and there is no need to mention the scanning path anywhere like we mention in the spring framework. You have to add one extra JAR file struts2-convention-plugin.jar […]

Struts 2 Resource Bundle Example

struts2-thumbnail

It is best practice to have all the labels used in your application in the centralized location. Tradionally these message resources are stored in the property files using the key=value pairs and loaded on demand by the forms. Every framework supports this basic feature to configure the message resources. This example shows how to load […]

Struts 2 + Spring Integration Example

struts2-thumbnail

Struts 2 provides plug-ins for integration to any other frameworks. If you are using Spring for your bean management, then it is very easy for you to integrate Spring container to Struts 2 application. Spring can manage the beans and struts actions classes as beans. You have to just specify the bean name in the […]