This code should be on the servlet side not on the jsp. You can move it on the handleservlet or make it a separate ItemHomeProcessor plugin enabled by default in dspace.cfg (the plugin will return early if versioning is disabled)