Skip to main content

Posts

Showing posts from 2010

Using Multiple Struts Config Files

If you are working on a big web application which uses Struts and has huge number of action classes in it, action mappings for these classes will result a huge “struts-config.xml'” file. You might always find it difficult to change the struts config file that big. And it might be really helpful if you split the action mappings and put them in multiple config files, splitting can be based on any criteria – based on functionality or authorization levels, etc. Lets see how we can do this and use multiple ‘struts-config.xml’ files. Lets say that you’ve three struts config files namely “ struts-config-1.xml ”, “ struts-config-2.xml ”, and “ struts-config-3.xml ”. All you need to do is specify these configuration files as initialization parameter ‘config’ for “ActionServlet” in your ‘ web.xml ’ file. Make sure that all your config files should be separated with ‘comma’, see the example given below. <servlet>     <servlet-name>action</servlet-name>     <servlet-cl

Tooltip Component Using Java Script & CSS

A simple, small Java Script Component, which you can use to have custom Tooltips on your web page. Well why wait, let get right on to it. First lets see the styles used by the Tooltip popup box. .toolTipDef, .toolTip {             position: absolute;             background-color: #ccc;             border: 1px solid #000;             padding: 3px;         } .toolTipDef { display: none; } .toolTip { display: block; } All together we’ve to CSS classes, one ‘toolTipDef’ and ‘toolTip’. ‘toolTipDef’ is used when the tooltip need to be hidden, and when user mouse over the text, we’ll use ‘toolTip’ class to make the tooltip popup visible. These styles set standard attributes like background color for the tooltip popup, its border and text padding inside tooltip popup. ‘toolTipDef’ set the ‘display’ property to ‘none’ so that by default the popup is hidden and ‘toolTip’ sets the ‘display’ property to ‘block’ so that when used the tooltip popup gets displayed. To display tooltip text,

Ant Script To Sign A JAR File

To sign a JAR file you need a ‘keystore” first. You can create a sample keystore using the following simple command. keytool -genkey -keystore <filename.store> -alias <aliasname> After creating the keystore, you can add the following Ant tag to sign the JAR file using it. <signjar jar="<JAR file to be signed>" alias="<Keystore Alias Name>"                 keystore="<Keystorefile.store>" storepass="<Keystore password>"/> Attributes used are jar – The JAR file path which needs to be signed. alias – Keystore alias name, given in the ‘keytool’ command to create the keystore. keystore – Path to the keystore file, which was created using the ‘keytool’ command. storepass – Keystore password used while creating the keystore using ‘keytool’ command.

Ajax Form Submit GET/POST Methods

This example explains GET and POST methods of form submit using AJAX. Only code is posted for now, will try to update it later some time. Complete example can be downloaded using the link at the end of the post. package com.rakesh.ex.dto; public class EmployeeDTO {     private String empId;     private String name, email;     private String designation, department;     public EmployeeDTO(String empId) {         this.empId = empId;     }     public String getEmpId() {         return empId;     }     public void setEmpId(String empId) {         this.empId = empId;     }     public String getName() {         return name;     }     public void setName(String name) {         this.name = name;     }     public String getEmail() {         return email;     }     public void setEmail(String email) {         this.email = email;     }     public String getDesignation() {         return designation;     }     public void setDesignation(String designation) {         this.designation

File Uploading Using Servlets, JSP and Commons File Upload API

I’ve seen many developers who are at the early stages of their career have problems with this topic and seen many posts in forums asking how to do it – File Uploading using Servlets, JSP!; this article will provide an example using Commons File Upload API. I tried to make the example as simple as possible, hope it helps those early birds. Example uses JSP to provide the pages with form where user can select the file to upload with other form fields, Commons File Upload API to process submitted form and read form fields separately, and Servlets as middle layer between JSP and Commons File Upload API, example also has ANT build script to generate the distributables. All the code can be downloaded, links to these resources are provided at the end of this post, lets get on with the example then. The flow in this example is as depicted in the following picture. As you can see, user selects the file to upload and provides normal form data as well, using "index.jsp" and submi

Simple AJAX [, JSP] Example

You will find many examples to learn how AJAX [Asynchronous Java Script And XML] works, but this one is different. Its one of the best way of using AJAX in web applications. The difference -  many of the examples you find uses Java Script to parse the AJAX response, this example avoids that parsing Java Script and uses JSP to generate the HTML and uses simple Java Script just to make the asynchronous call and show the response. It shows simple way of using JSP and AJAX with as much less Java Script as possible. This article wont go into details of what AJAX is and how to make AJAX calls, it explains one good way among many to use AJAX. Lets get on with it then! The flow of this example is like this – A simple JSP page where user performs an action [button click in this example] to get list of employees, on this action we’ll make an Asynchronous call to a Servlet which will prepare the dummy employee data and sends that data to a JSP page. This JSP generates the HTML displaying the e

Eclipse Tips

In few situations, you want eclipse to refresh the project contents automatically. Its might be required when you changed the one/more files of an eclipse project in some other editor and you wanted eclipse to reflect those changes automatically. If you are using version control and when you get latest changes from repository, you want those changes to be reflected on your eclipse. This can be configured in eclipse easily. Go to Window –> Preferences , in this  window select General –> Workspace from the tree in the left panel. When you select Workspace, you’ll see workspace related configuration options in the right panel. The top section will have three checkboxes, one of them will " Refresh Automatically ". Select this checkbox and click OK. Another feature which could be handy is to see different Icons for different file types like Interfaces, Classes, Abstract Classes, etc. You can set this in Window –> Preferences window. In this window select General –&

Attaching Source/Java Doc - In Eclipse

Its really simple to attach Source code/Java Doc in eclipse, for a library you are using in your application. Select the project for which you want to do the changes. Go to Project Menu –> Properties Select Libraries Tab Select and expand the Jar file for which you want to add source code/Java doc. This will show you the options "Source attachment" and "JavaDoc Location". Select "Source attachment" option, this will enable 'Edit' button. Click on Edit button, this will open "Source Attachment Configuration" dialog. Here you need to provide the location of the source code to be attached. You can provide either compressed [jar/zip] file Or directory location of the source code. And after providing the location press OK. Simple isn't it. For attaching JavaDoc select the option "JavaDoc" instead of "Source attachment" in the above mentioned step, and click on Edit. For JavaDoc you can either provide URL

Changing Eclipse Workspace

Easy way to do this, go to “ File->Switch Workspace ”. This option will show you previously used workspaces. You can select workspace you want to use, if the one you want to use is listed in it. If not then select “Other” option. This will open “Workspace Launcher” dialog. This dialog will allow you to choose the directory which you want to use as workspace. Simple isn’t it! Well the hard way of doing this – Open the “ ECLIPSE_HOME/configuration/.settings ” directory, in this directory you’ll find a file “ org.eclipse.ui.ide.prefs ”. Open this file using any text editor like Notepad/Wordpad. This file contains workspace related configuration. “ SHOW_WORKSPACE_SELECTION_DIALOG ” and “ RECENT_WORKSPACES ” are the ones concerned to changing workspace. SHOW_WORKSPACE_SELECTION_DIALOG – This property will have either “true/false” value. If this property is set to true, then next time when you open eclipse, it’ll open “Workspace Launcher” dialog through which you can select the

Oracle SQL Developer & Named MSSQL Instance

Its a small tip to connect to a ‘ Named MSSQL Instance ’ using Oracle SQL Developer. Oracle SQL Developer allows you to connect to any database which has supported JDBC drivers. You can add these drivers either using “Help –> Check for Updates” and by selecting “Third Party SQL Developer Extensions” option. This will list available updates, from which you can select the needed drivers. Second option is adding these drivers from your local drive using “Tools –> Preferences” and by selecting the “Database –> Third Party JDBC Drivers” option from the tree given in the left column. If you installed needed driver for MSSQL database you’ll get the tab “SQL Server” on the New Database Connection window. If you observe this window, you’ll see that there is no text field/option to provide “Database Instance Name”. This window is simple to create a Database Connection to Unnamed MSSQL Database Instance. The big question is how do we create a connection to a Named MSSQL Database Insta

Auto Scrolling Java Script Component

Well after a long break, here I am, back with a component which might be useful for web developers/designers. In this post I’ll try to explain Auto Scrolling Java script component. You might think Auto Scrolling is very old topic and you’ll find many examples of this kind. Even I was thinking the same couple of months ago. I was supposed to work on something similar to this, I thought I can use some existing components with out putting effort to write my own. But ended up writing my own Auto Scrolling component. Reason – Those examples I found did not fit my requirement and are really complicated for a common developer to understand and plugin to existing code. This component is small, simple and can be plugged in to any piece of code [at least my perception] with out any effort. All the source code is free for every body to use [this is also one of the constraint I wrote my own], download it using the links provided a the end of this article. Why wait, lets get on with it. This