Adding the application name to links in a Web application

Application servers can run a number of applications. A single Tomcat instance, for example, will create a separate web application for each WAR file it finds in its webapps directory.
The applications will be named the same as their WAR files and can be accessed using URLs that start with that name. For example, to [...]

Identifying number of account logins on Sybase

If you quickly need to see how many logins there are for each account in sybase, you can use this query:

select dbname=db_name(dbid),login=suser_name(suid), #connections=count(suid)
from master..sysprocesses
–where suser_name(suid) like '%dblogin%'
group by dbid, suid
order by count(suid)

Quick formatting of Date using a Java String format expression

For quick reference, this is how you can format a date as:
dd/mm/yyyy at hh:mm:ss
System.out.printf("Date: %1$te/%1$tm/%1$tY at %1$tH:%1$tM:%1$tS%n", new Date());
The % characters mark a placeholders for String content, the 1$ indicates that the first vararg should be used for each placeholder (there is only one varag value supplied), the letter ‘t’ in each placeholder indicates a [...]

Searching for files in an Ant script

This is a simple technique for determining whether or not files matching a given pattern exist within your project. Unlike the available task, this does not require that you need to know the exact name of the file when creating the build file. It is therefore very useful for checking existence of generated/downloaded artefacts.
I’ll demonstrate [...]

Adding a thread timeout to methods in Java

When calling a method that could potentially take longer that you’d like to complete, it is possible to write code that will back out after a given time period.
This can happen in numerous circumstances where you’d like an application to maintain a degree of liveness. I’ve used it recently in an application that needed [...]

What info can you get from an HttpServletRequest?

There are many methods on an HttpServletRequest, and if you’re anything like me, you’ll forget exactly what each of them returns. Rather than a long winded investigation into them all, here’s a sample URL:

https://localhost:8443/test/welcome?a=1&b=2

The ‘/test’ in the URL will map to a servlet called test. The servlet will dispatch the request to a JSP for [...]

Implementing Flash Scope in Java Web Applications

While working recently on a Spring MVC project I found myself wishing it supported flash scope. I hunted around for a simple solution but couldn’t find anything that didn’t rely on having to import large framework libraries. After a little thought I came up with the following simple and lightweight solution that has worked really [...]

Finding tables and columns by name in a large Sybase database

When working with a large Sybase database, especially one that you are not too farmiliar with, the following SQL snippets can be really useful for finding your way around.

select name,type from sysobjects where (name like '%Sales%') and type = 'U'

The sysobjects table stores data about various items in the database including tables (note that [...]

Using recursion to program in JSP

I needed to render a tree structure in a JSP and wanted to use a recursive solution like this:

<jsp:include page="renderTree.jsp">
<jsp:param name="nodes" value="${node.children}"/>
</jsp:include>

After a while of not getting very far with this and trying to figure out why I was getting stack overflow errors, I figured out that the jsp:param tag was [...]

Address in Use Error using Tomcat on Windows XP

Occasionally you might get an error like this when launching Tomcat:
java.net.BindException: Address already in use: JVM_Bind <null>:8080
This can be caused if you already have Tomcat running as it will hold onto a network port for handling HTTP requests. In the above example the port shown is 8080.
However, this error is sometimes apparent even when Tomcat [...]