RECENT POSTS
How to increase JVM heap size in Eclipse
To avoid getting java.lang.OutOfMemoryErrors, while running web application, we should increase heap size allocated by the JVM by using command line options. -Xms<size> set initial Java heap size -Xmx<size> set maximum Java heap size -Xss<size> set java thread stack size To do this, follow these steps: 1. Open the Server Configuration in Eclipse by double-clicking on the Server instance. 2. Click on “Open launch configuration” link 3. Click on...
read moreDatetime picker in struts 2 using jquery
Zip file – Jquery DatePicker Last time when I worked out how to get the dojo datetimepicker Well, it faced some issues like, I could not customize the size of the text box, and also its appearance. As an alternative I found out a plugin Struts2- Jquery which provide a lots of customizing features. ** UPDATE: Struts 2 Complete tutorial now available here. To create a date time pick component in struts 2, please follow this two steps : 1. Add struts2-jquery-plugin-3.6.1.jar in...
read moreHandling Exception in Struts 2
Zip file – Struts2Exception.zip The Struts 2 framework provides some easy way to handle any uncaught exceptions. It works on exception interceptor which is part of default-stack in struts-default.xml file. There are two ways to handle uncaught exceptions in Struts2: Global exception handling: specifies exception mappings which apply to all action classes in a Struts2. Exception handling per action: specifies exception mappings which apply to a specific action class. Both methods require...
read moreAutocompleter Textbox & dropdown in Struts 2
To create a Autocompleter component in struts 2, please follow this two steps : 1. Add struts2-dojo-plugin.jar in your class path. 2. Include the “struts-dojo-tags” tag and its header(shown below) in your jsp page <%@ taglib prefix="sx" uri="/struts-dojo-tags" %> <html> <head> <sx:head /> </head> ** UPDATE: Struts 2 Complete tutorial now available here. Action class AutoCompleteAction.java package...
read moreDifference between # , $ and % signs in Struts2
Use of # OGNL is used to refer to objects in the ActionContext as follows: myObject: object in the ValueStack, such as an Action property #myObject: object in the ActionContext but outside of the ValueStack… #myObject: ActionContext object that has been created using the Struts2 data tags with the default action scope (e.g., <s:set name=”data” value=”Some data” />, referenced by<s:property value=”#data” />) #parameters.myObject: request parameter #request.myObject:...
read moreCommon Support class for Action classes in Struts 2
When you are about to create a complex application in struts 2, it is better to create a Base action class for all your actions and make this class extend ActionSupport and implement all necessary interfaces such as SessionAware, ParameterAware, HttpServletRequest, HttpServletResponse etc and implement all other common logic for your actions in this class. So now when you are about to create an action class, just extending this support class will suit all your need in action class. ** UPDATE: Struts 2 Complete tutorial now...
read moreBest way to check a string against null in java?
String in Java is considered empty if its not null and it’s length is 0. But before checking length you should verify that String is not null because calling length() on null String will result in NullPointerException. Apache commons lang has a StringUtils class which has static method isEmpty(String input), which returns true if input string is null or has length equal to zero. Output of StringUtils for various input : StringUtils.isEmpty("value") = false StringUtils.isEmpty(" ") =...
read moreStruts 2 iterator tag example
Zip file – IteratorTag.zip War file – IteratorTag.war Struts 2 Iterator will iterate over a value. An iterable value can be any of: java.util.Iterator,java.util.Collection. In this tutorials, we will create a list and use Iterator tag to loop over it and get the iterator status with IteratorStatus. Using IteratorStatus object one can get information about the status of the iteration, such as: index: current iteration index, starts on 0 and increments in one on every...
read moreStruts 2 If, Else, ElseIf Conditional/Control tag example
Struts 2 If, ElseIf and Else tags are used to perform basic condition checking. These are the following scenario in real world application to check the condition. 1. Condition checking using Boolean variable. 2. Condition checking using String object. 3. Condition checking using collection object / bean object 4. Condition checking using integer data type ** UPDATE: Struts 2 Complete tutorial now available here. Now see the example on these scenario one by one. 1. Condition checking using Boolean...
read moreFile Download Example in Struts 2
Action Class package com.simplecode.action; import java.io.File; import java.io.FileInputStream; import java.io.InputStream; import com.opensymphony.xwork2.Action; public class DownloadAction implements Action { private InputStream fileInputStream; private String fileName; public InputStream getFileInputStream() { return fileInputStream; } public String execute() throws Exception { fileName = "MyFile.xls"; fileInputStream = new FileInputStream(new...
read more