JSP 2.0 EL and Functions

In my last project I need to call some utility methods from my JSP to manipulate model data. I didn't wanted to use JSP scriplets within the JSP, so the solution was to use utility method via JSP2.0 EL feature.

Approach I folowed was:
1. Declare function in a tag library descriptor.


Image Utility functions
Image Utility Tag Library

java.lang.String getImagePath(java.lang.String, java.lang.String)

java.lang.String getImagePath(java.lang.String)

2. Store TLD under WEB-INF directory (/WEB-INF/tld/)
3. Specify the function's prefix and the library's Uniform Resource Identifier (URI) in JSP file

<%@ taglib uri="/WEB-INF/tld/ImageManip.tld" prefix="image"%>

Using Alert conditionally

In my last project I faced a lot of Bugs filed by QC team related to test Alert pop-ups coming which were introduced by developers for debugging and they forgot to remove those.

To get rid of this I used a wrapper function over alert() function which checks the value of a test variable if that is true then only alert() function will get called, this way I was able to control test alert pop-ups across the web application with single test variable.

DEBUG = false;
function prompt(text) {
if(DEBUG) {

Message Property Like functionality in Javascript

In my last project I was using JavaScript heavily which was using messages extensively.

Repetition of same kind of messages from multiple places was becoming unmanageable to handle that I have written a JavaScript class which provides Text message with respect to the message code provided.

This function works in two ways:
1. With code only (Messages.getText("error.text"))
2. With code and args (Messages.getText("error.invalid",args))
Here args is replacement for place holders like:
error.invalid = "Invalid input [1] for [0]"
So Invalid error message can be reused for multiple places where [1] will replace by value and [0] wil be replaced for Field name

For function overloading I have used addMethod - By John Resig as reference

function addMethod(object, name, fn){
var old = object[ name ];
if ( old )
object[ name ] = function(){
if ( fn.length == arguments.length )
return fn.apply( this, arguments );
else if ( typeof old == 'function' )
return old.apply( this, arguments );
object[ name ] = fn;

function MessageProvider() {
this.msg = new Object();
this.msg['error.Login'] = 'Please login to submit link';
this.msg['error.invalid'] = 'Invalid input [1] for [0] [0] is invalid';

addMethod(this, "getText", function(code){
return this.msg[code];
addMethod(this, "getText", function(code,args){
var text = this.msg[code];
for (var i = 0; i < args.length; i++) {
var re = new RegExp('\\[' + i + '\\]', 'g');
var dest = args[i];
//text = oldtext.replace(re,'’);
text = text.replace(re,dest);
return text;



var Messages = new MessageProvider();

Now to use centralized messaging in javascript you need to add this code to .js File and include in your html
Add all your messages to msg Object

like :

Conflicts faced While Load Testing

I was working on load testing of a web application last month, results were very conflicting when I was accessing application from browser response was very good but while executing script from Jmeter throughput was very less.

I had applied all possible optimizations like :
1. Query Caching
2. Output compression (mod_deflate)
3. Minify JS and CSS

but result was same.
I enabled logs to see compression ratio and realized that Jmeter was not sending accept-encoding HTTP header so Apache was not sending compressed result and that was affecting throughput.
After adding accept-encoding header throughput was as desired.