Pages Navigation Menu

Coding is much easier than you think

Struts-2 Updates

Difference between # , $ and % signs in Struts2

Posted by on Oct 14, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Difference 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 more

Common Support class for Action classes in Struts 2

Posted by on Oct 14, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Common 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.   Following is a snippet of my...

read more

Struts 2 iterator tag example

Posted by on Oct 2, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Struts 2 iterator tag example

  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 iteration count: iterations so far, starts on 1. count is always index + 1 first: true if index == 0 last: true if...

read more

Struts 2 If, Else, ElseIf Tag example

Posted by on Oct 1, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Struts 2 If, Else, ElseIf 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   Jsp Page   <%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <%@taglib...

read more

Struts 2 File Download Example

Posted by on Sep 29, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Struts 2 File Download Example

  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

How to override struts 2.x file upload messages?

Posted by on Sep 28, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

How to override struts 2.x file upload messages?

  The file upload interceptor does the validation and adds errors. These error messages are stored in the struts-messsages.properties file. The values of the messages can be overridden by providing the text for the following keys:   struts.messages.error.uploading - error when uploading of file fails struts.messages.error.file.too.large - error occurs when file size is large struts.messages.error.content.type.not.allowed - when the content type is not allowed struts.messages.error.file.extension.not.allowed - when the file...

read more

Struts 2 Dynamic Method Invocation using Action Wildcards

Posted by on Sep 21, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Struts 2 Dynamic Method Invocation using Action Wildcards

  This tutorial is a continuation of previous example ( DispatchAction functionality ). In this example you will see about avoiding configuration of separate action mapping for each method in Action class by using the wildcard method. Look at the following action mapping to under stand the concept.   Action mapping From previous example   <struts> <package name="default" extends="struts-default"> <action name="Number"...

read more

DispatchAction Functionality in Struts 2

Posted by on Sep 12, 2013 in Struts 2 Tutorial, Struts-2 | 2 comments

DispatchAction Functionality in Struts 2

  In Struts 1 DispatchAction helps us in grouping a set of related functions into a single action. In Struts 2 all the Actions by default provide this functionality. To use this functionality we need to create different methods with the similar signature of the execute() method.   In our example the CalculatorAction class has all the methods related to a Calculator like add(), multiply(), division() and subtract() which are used for performing mathematical operation on two numbers and it displays the result in a single jsp based on...

read more

Action Chaining and Action redirect in struts.xml (Struts 2)

Posted by on Sep 8, 2013 in Struts-2 | 0 comments

Action Chaining and Action redirect in struts.xml (Struts 2)

  In Struts 2, sometimes you may want to process another action when one action completes. For example on successfully submitting a form you want to render output from other action.   This can be done by two methods   1) Action Chaining 2) Action redirect Difference between Action redirect & Action Chaining:   Action Redirect starts from scratch, it is like you called the other action class for the first time while Action Chaining keeps the values of the first Action class on the value stack and adds the variables of...

read more

Struts 2 Bean Tag

Posted by on Aug 12, 2013 in Struts 2 Tutorial, Struts-2 | 0 comments

Struts 2 Bean Tag

  The bean tag is like a hybrid of the set and push tags. The main difference is that you don’t need to work with an existing object. You can create an instance of an object and either push it onto the ValueStack or set a top-level reference to it in the Action-Context. By default, the object will be pushed onto the ValueStack and will remain there for the duration of the tag. In this tutorial let us learn how to use the Struts 2 Bean Tag with the help of a DollarConverter bean example. In this example we will convert dollars to...

read more
SimpleCodeStuffs located at 511/67 Huynh Van Banh , Ho Chi Minh, VN . Reviewed by 56 customers rated: 4 / 5