I have a requirement where on clicking a button, I have to empty the text area, which is populated from a file, and need to empty the file contents also.
My jsp page looks like this
<%@page import="com.hcentive.rule.DisplayLog"%>
<%@ page import="java.lang.*" import="java.util.Scanner"
import="java.io.FileReader" import="java.net.*"%>
<%
DisplayLog log = new DisplayLog();
log.display();
%>
<html>
<body>
<script>
function validate() {
alert("clear clicked");
document.getElementById("rule").value = "";
<%
log.clear();
%>
}
</script>
<br><br>
<FORM>
<textarea rows="20" cols="162" wrap="off" id="rule" ><%=log.getFileOutput()%></textarea>
<br><br>
<input type="button" value="Clear" onclick="validate();" >
</FORM>
</body>
</html>
In above code, DisplayLog is a java class. display method is used to read file contents and write in the text area and clear method is used to empty the file contents.
It is working fine when i click the clear button it empties the text area.The problem that i am facing is that on browser refresh, log.clear()
is also getting called which i don't understand.
Please someone help.