Pages Navigation Menu

Coding is much easier than you think

RECENT POSTS

Struts 2 If, Else, ElseIf Conditional/Control tag example

Posted by in Struts 2 Tutorial, Struts-2

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

File Download Example in Struts 2

Posted by in Struts 2 Tutorial, Struts-2

File 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

How to override struts 2.x file upload messages?

Posted by in Struts 2 Tutorial, Struts-2

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

read more

How to create a AUTO_INCREMENT column in Oracle?

Posted by in Oracle

How to create a AUTO_INCREMENT column in Oracle?

  A lot of databases have a column autoincrement attribute or an autoincrement data type. They are used to create unique identifiers for a column. However in Oracle, there is no such thing such as “auto_increment” columns. But we can implement this feature with a Sequence and a Trigger:   ** UPDATE: Complete JDBC tutorial now available here.   Table definition :   CREATE TABLE EMPLOYEE( USER_ID NUMBER(5) NOT NULL , USERNAME VARCHAR(20) NOT NULL, CREATED_BY VARCHAR(20) NOT NULL);   ALTER TABLE...

read more

DispatchAction Functionality in Struts 2

Posted by in Struts 2 Tutorial, Struts-2 | 5 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 in Struts-2 | 2 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   ** UPDATE: Struts 2 Complete tutorial now available here.   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...

read more

JDBC Batch Updates

Posted by in JDBC, JDBC Tutorial

JDBC Batch Updates

  You can send multiple queries to the database at a time using batch update feature of Statement/PreparedStatement objects this reduces the number of JDBC calls and improves performance.   Note : Batch Update is not limit to Insert statement, it’s applied for Update and Delete statement as well.   Statement Batch Updates   To issue a Batch update , call the addBatch() and executeBatch() methods as shown below.   dbConnection.setAutoCommit(false); statement =...

read more

Comparison Chart between different Collection

Posted by in Java

Comparison Chart between different Collection

Comparison Chart between different Collection    

read more

How to retrieve SQLWarning in java?

Posted by in JDBC

How to retrieve SQLWarning in java?

  SQLWarning objects are a subclass of SQLException that deal with database access warnings. Warning simply alerts the user when something did not happen as planned. A warning can be reported on a Connection, ResultSet and Statement object. Each of these classes has a getWarnings() method, which we must invoke in order to see the warning reported on the calling object. E.g. SQLWarning statementWarning = statement.getWarnings(); while (statementWarning != null) { System.out.println("Error code: " +...

read more