I am developing file explorer java web application in Netbeans with tomcat server. When i call the server from command prompt, it must must fetch the directory we are currently in and use it as home directory for file explorer.
In order to pass that i have created a new batch file:
@echo off
REM Save the current directory
set “CURRENT_DIR=%cd%”
REM Set the JAVA_HOME environment variable if it's not already set
if "%JAVA_HOME%"=="" (
set "JAVA_HOME=C:Program FilesJavajdk-22"
)
REM Set the CATALINA_HOME environment variable
set "CATALINA_HOME=D:HomeApache Software FoundationTomcat 10.1"
REM Set the desired directory for user.dir
set "CATALINA_OPTS=-Duser.dir=%CURRENT_DIR% %CATALINA_OPTS%"
REM Print the value of CATALINA_OPTS to verify
echo CATALINA_OPTS is set to: %CATALINA_OPTS%
REM Start Tomcat
call "%CATALINA_HOME%bincatalina.bat" run
It is correctly echoing the current directory. But while accessing the directory thing i only get ‘null’.
Setting current directory in servlet:
public void init() throws ServletException {
// Retrieve the current directory set as a system property
FILE_DIRECTORY = System.getProperty("user.dir");
out.println("filedirectory:" + FILE_DIRECTORY);
}
can anyone tell me where i went wrong?
Hari priya is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.