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 + JSON Integration
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
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
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
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 …
Struts 2 TextArea Tag Example
Struts 2 TextArea field is helpful for entering the multiple lines in the input box. It is similar to the textfiled tag, but in the textfield tag only one line can be entered. Lets look at the example. 1. Action Class 2. TextArea Tag Example TextArea.jsp Result.jsp 3. Struts.xml 4. TextArea Tag Demo If you …
Struts 2 Hidden Tag Example
Struts 2 Hidden Tag is helpful for passing the hidden values from one page to another page. In the latest web development there is very less need for using this kind of tags for the functionality. If your framework is not handling the values by default, you need to define the hidden fields and then …
Struts 2 Select Tag Example
Struts 2 Select tag is helpful for implementing the drop down list where user can select one value from the list. Either these values can be send from the bean or it can be defined in the select tag itself. This tutorial shows a simple example to implement this tag. Lets look at the below …