Posts Tagged ‘web’

Simple concurrent In-memory cache for web application using Future

Wednesday, March 11th, 2009

In-memory cache’s can be extremely useful for small web applications where you don’t want to full-blown cache system like ehCache or simply can’t afford one. I recently had such a requirement and I must say that I kind of made a mess of it. The requirement was to cache User objects so that we didn’t have to make too many calls to the database. Let me just say outright that while such a cache is not the best idea in the world, it isn’t the worst either. When you simply need to cache a few objects to reduce the load on the db in a moderately loaded web-app, this implementation works just fine.

The service layer was my choice for the cache, I use the Controller -> Service -> DAO model in all my webapps mainly because it keeps the code clean and also because it makes it much easier to manage transactions across DAO’s. (more…)

Tracking logged in user’s using spring-security and HttpSessionListener in java web application

Thursday, February 19th, 2009

If you haven’t already, please first read my article on configuring spring security and after that the article on writing a custom AuthenticationprocessingFilter. It is imperative that you know how to do both before you continue.

We always want to know who is on our website, how many users are logged in and how many visitors are present. Not only is the information useful, it also looks good. :) I tried looking for pluggable solutions to track users but couldn’t find any. Having implemented spring security in a few web apps, I decided to see if there was an easy way to do this. (more…)

Registering PropertyEditors’s with spring for custom objects

Saturday, February 14th, 2009

More often than not people come to the spring forums asking about PropertyEditor’s. PropertyEditors are needed when you want to convert a string value to an object. Say for example, your command object contains a reference to a User object and the list of user’s is shown in the jsp with the value of the option box serving as the id of the user. Once the form is submitted, unless you have a custom property editor for your user class, you will receive validation errors. (more…)

Pagination & sorting in jsp’s with the displaytag taglib & spring

Friday, February 13th, 2009

I hate writing pagination code. Infact I hate it so much, I try not to paginate my lists at all. ( I know, i know, very bad on my part) :) . Writing pagination code totally destroys the code reuse in an application, developers generally just copy paste the very same pagination code all over the place over and over again. Not to mention decorating such pagination displays is a pain in the ass as well. So while searching for a more concrete solution to my problem I stumbled upon displaytag.

Display tag is by far the most comprehensive pagination solution that I have ever come across. Not only is the library extremely stable, (more…)

Automatically redirecting all requests to SSL in web application

Wednesday, February 11th, 2009

More often than not you are required to secure your login pages and certain admin resources using secured socket layer (SSL) or TLS. This can be quite a task if you go around manually redirecting all your http requests to https and then configuring your server. Whats worse is that another team member may forget to secure certain resources thereby exposing them through “un-safe” means.

The best way to secure such resources is to use the (more…)