fbpx
Pages Navigation Menu

Coding is much easier than you think

Struts-2 Updates

Advertisements

File Download Example in Struts 2

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

File Download Example in Struts 2

  This tutorial will help you understanding how to create a Struts 2 action class that allows users to download files from server to their local computer.   struts.xml   Struts 2 provides a custom result type called “stream” that performs file download by “streaming” an InputStream of a file to the client through the HttpServletResponse. Here’s an example that shows how to define this result type element in struts.xml:   The struts.xml file should have the following...

read more

How to override struts 2.x file upload error messages?

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

How to override struts 2.x file upload error messages?

  In my previous tutorial I have explained about how to upload file in struts 2 web application. This article aims at overriding the default file upload error message which are added by file upload interceptor during file upload validation. 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...

read more

Struts 2 Dynamic Method Invocation using Action Wildcards

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

  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.   ** UPDATE: Struts 2 Complete tutorial now available here.   Action mapping From previous example   <struts> <package name="default" extends="struts-default"> <action...

read more

DispatchAction Functionality in Struts 2

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

  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...

read more

Difference between Action Chaining & Action redirect in Struts 2

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

  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     ** UPDATE: Struts 2 Complete tutorial now available here.   Difference between Action redirect & Action Chaining:   Difference between Action Chaining & Action redirect is, Action Redirect starts from scratch, it is like you called the other...

read more

Login & Logout Example in Struts 2

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

  In this tutorial we will see how to create a simple Struts 2 Login Application. The following files are needed to create a Login Application.   ** UPDATE: Struts 2 Complete tutorial now available here.   Final project structure     Create a New Dynamic Web Project in eclipse and give a name to your project   Action class   file : LoginAction.java package com.action; public class LoginAction { private String userName; private String password; public String execute() { if...

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.   ** UPDATE: Struts 2 Complete tutorial now available here.   In this tutorial let us learn how to use the Struts 2 Bean Tag with the help of a...

read more

Struts 2 Push Tag Example

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

Struts 2 Push Tag Example

  Struts 2 “push” tag is used to push a value into the ValueStack. The value we pushed using push tag will be on top of the ValueStack, so it can be easily referenced using the first-level OGNL expression instead of a deeper reference. The following code show how to do this.   ** UPDATE: Struts 2 Complete tutorial now available here.   Download It – PushTag    1. Action package com.simplecode.action; import com.simplecode.util.AuthorBean; //PushTag Action class public class...

read more

Integrating Quartz Scheduler in Struts 2 Web Application

Posted by on Aug 6, 2013 in Quartz Scheduler, Struts-2 | 1 comment

  In our previous article we learn about Quartz 2 hello world example along with types of Triggers in Quartz 2, In this article we shall learn to Integrating Quartz 2 Scheduler in Struts 2 web Application. To know more about Quartz please visit its Official website.   Library required   Commonly Required Struts 2 Jars commons-logging-1.1.1.jar log4j-1.2.16.jar quartz-2.2.1.jar slf4j-api-1.6.6.jar slf4j-log4j12-1.6.6.jar   Scheduler Job   Create a Quartz’s job package com.quartz; import...

read more

Creating Custom Interceptors in Struts2

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

In my previous post here I demonstrated about Concepts of Interceptor in Struts 2. In this post we will see how to create a simple interceptor that will execute and print a few lines to the server logs, both before and after an action is executed. A few points need to be kept in mind before writing your own interceptors; You can create your own custom interceptor in two ways a)Implement the Interceptor interface b)Extend the AbstractInterceptor class. If You are implementing the Interceptor interface, you have to provide implementations...

read more
%d bloggers like this: