You could call this method in the init() method of your servlet. You can also look into implementing ServletContextListener and calling it in the contextInitialized(ServletContextEvent) method.
If you are trying to subtract 2 days from the date as your comment line says, look into the add() method of the Calendar class:
To get the difference between any dates, get the time in milliseconds and divide until you get to the unit you want.
I ran into a problem using the Java comm api running on Windows where information from the Windows device manager is not being refreshed in the Java code. For example, we have a port, COM5, that is a USB to serial converter. This port only exists if the USB device is plugged in. If we do not have the device plugged in and run the following code:
We get a NoSuchPortException thrown, which is what we expect. However, if we then plug in the device so the port now exits and run the same line of code we get the same exception. It seems as if the getPortIdentifier method does not see the updated device list. The only way we are able to get this to execute successfully is to kill the JVM and start it again.
If the port exists the first time CommPortIdentifier.getPortIdentifier("COM5"); is called, then it works, but it cannot update dynamically.
Does anyone have any idea why this is or how to get around it?
The issue is being caused because Tomcat was being run as a service and the service did not have authority to interact with the desktop (Service properties->Log On tab->Allow service to interact with desktop). Checking this box resolves the issue, however, it causes multiple pop-ups to display asking the user if it's alright for the service to do what it is doing (even with UAC turned off).
To get around this, I stopped running Tomcat as a service and started it with the following command:
This starts Tomcat as an application instead of as a service which gives it more authority to interact with Windows. Now the VBS script from my example executes as intended with no user interaction.
I have Tomcat 6 running on Windows 7. The web application running on this server has one jsp and one servlet. The servlet's only responsibility is to call a vbs script and return to the jsp page. I use the following code to execute the script:
This does not cause any errors and no exceptions are thrown, but the vbs script doesn't run. If I run the same command from the command line, or double click the Alert.vbs file, the script executes correctly. This also works running on Tomcat 4.0 running on Windows 2000 and Tomcat 6.0 running on Windows XP.
To verify the problem is with Tomcat on Win7, I created a simple Swing app that executes the same command when a button is clicked and this works correctly.