I created a function in java that verifies the existence of a file properties and if it exists, it retrieves its contents, otherwise it creates it by writing it inside. Starting this function from java application via eclipse, it runs correctly, while calling the function from jsp pages does not find the file and give an error.
this is my java function:
private static File fileName = new File("properties.properties");
Properties props = new Properties();
public void writeProperties() throws FileNotFoundException, IOException{
if(fileName.exists()){
props.load(new FileInputStream(fileName));
}
boolean equal = false;
if(!UtilsFunction.isEmpty(props.getProperty("table-list"))){
String [] arr = props.getProperty("table-list").split(",");
for(int i=0;i<arr.length;i++){
if(arr[i].trim().equals(tableName)){
equal = true;
break;
}
}
if(!equal){
props.setProperty("table-list", props.getProperty("table-list")+","+tableName);
}
}else{
props.setProperty("table-list", tableName);
}
OutputStream out = new FileOutputStream(fileName);
props.store(out, "properties tables");
}
This is my JSP page:
<% ClassNameJava tableExecute = new ClassNameJava(tableName);%>
<% tableExecute.writeProperties(); %>
This is the error:
HTTP Status [500] – [Internal Server Error]
Type Exception Report
Message java.io.FileNotFoundException: properties.properties (The system cannot find the file specified)
Description The server encountered an unexpected condition that prevented it from fulfilling the request.
Exception
java.io.IOException: java.io.FileNotFoundException: properties.properties (The system cannot find the file specified)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:471)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Root Cause
java.io.FileNotFoundException: properties.properties (The system cannot find the file specified)
java.io.FileInputStream.open0(Native Method)
java.io.FileInputStream.open(Unknown Source)
java.io.FileInputStream.<init>(Unknown Source)
packageTableManager.TableExecute.writeProperties(TableExecute.java:233)
org.apache.jsp.config_jsp._jspService(config_jsp.java:199)
org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:385)
org.apache.jasper.servlet.JspServlet.service(JspServlet.java:329)
javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Note The full stack trace of the root cause is available in the server logs.
Apache Tomcat/8.
5.15