when filewriter(file, true) second attribute is true, the output is written twice.?
why does my out put file "log.txt" has the output written twice?
here is my code:
package productsupport;
import java.io.FileWriter;
import java.io.IOException;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.util.*;
import java.util.GregorianCalendar;
public class setAtt extends HttpServlet {
private String driver, dburl;
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws IOException, ServletException
{
BufferedWriter log = new BufferedWriter (new FileWriter("log.txt",
true));
response.setContentType("text/html");
response.setHeader("pragma", "no-cache");
String ip = request.getParameter("ip");
String port = request.getParameter("port");
String sid = request.getParameter("sid");
String user = request.getParameter("user");
String password = request.getParameter("password");
String schema = request.getParameter("schema");
String parkId = request.getParameter("parkId");
String attId= request.getParameter("attId");
String attValue= request.getParameter("attValue");
String query = "";
String siteId="";
Calendar now = new GregorianCalendar();
for (int i=0; i< request.getParameterValues("siteId").length ;
i++ ){
if (i != (request.getParameterValues("siteId").length -1) ){
siteId = siteId + request.getParameterValues("siteId")[i] +
",";
}else {
siteId = siteId + request.getParameterValues("siteId")[i];
}
}
driver = "oracle.jdbc.driver.OracleDriver";
dburl = "jdbc:oracle:thin:" + user + "/" + password +
"@" + ip + ":" + port + ":" + sid;
PrintWriter out = response.getWriter( );
out.println("<HTML>");
out.println("<HEAD>");
/* java scripts*/
out.println("<script type=\"text/javascript\">");
/**
* function sumbitForm
*/
out.println("function submitForm(actionPage) {");
out.println("document.getElementById('setAttForm').action=actionPage;");
out.println("document.getElementById('setAttForm').submit();");
out.println("return 0; ");
out.println("}");
out.println("</script>");
out.println("<TITLE>");
out.println("Please Select the Park you want to update.");
out.println("</TITLE>");
out.println("</HEAD>");
out.println("<BODY>");
out.println("<H3>");
out.println("Please select the park you want to update.");
out.println("</H3>");
out.println("Site id: " + siteId);
/* connection details*/
out.println("<form id='setAttForm'>");
out.println("<br> Host or IP: <input type=text id=ip size=15
name=ip value="+ip+" / >" );
out.println("Port: <input type=text id=port name=port size=5
value="+ port +" />");
out.println( "sid: <input type=text id=sid name=sid size=3
value=" + sid +" />");
out.println( "User: <input type=text id=user name=user
value="+user+" />");
out.println( "Password: <input type=text id=password
name=password value=" + password+" />");
out.println( "Schema: <input type=text id=schema
name=schema value=" + schema+" /><br>");
out.println( "Park id: <input type=text id=parkId
name=parkId value=" + parkId+" /><br>");
out.println("<br> Attribute ID: " + attId);
out.println("<br> Attribute Value: " + attValue);
/*check which attribute to update,
* and only update attribute when attribute value was
provided
*/
log.newLine();
log.append("log file opened");
if (attId.equals("218")&& !attValue.equals("")){
for (int i=0; i< request.getParameterValues("siteId").length;
i++ ){
out.println("<br><br> Update site id: " +
request.getParameterValues("siteId")[i]);
query = "update "+schema+".p_prd_attr set
attr_value='"+attValue+"' where attr_id=" +
attId +" and prd_id=" +
request.getParameterValues("siteId")[i]+ " ";
out.println("<br>query: "+ query);
try{
out.println("<br>start logging ");
log.newLine();
log.write(now.get(Calendar.HOUR) +":"+
now.get(Calendar.MINUTE)+":"+
now.get(Calendar.SECOND)+": "+ query);
out.println("<br>end logging ");
dbAccess dbase = new dbAccess (driver, dburl);
//ResultSet rs =
dbase.conn.createStatement().executeQuery(query);
} catch (Exception e){
e.printStackTrace();
out.println("<br>Error: " + e);
}
log.newLine();
log.write("closing log");
log.close();
}
}
/* display Change Schema Button */
out.println("<br> <input type='submit' value='Change Schema' " +
"onClick=javascript:submitForm('login'); >" );
/* display Change Park Button */
out.println("<br> <input type='submit' value='Change Park' " +
"onClick=javascript:submitForm('selectPark'); >" );
/* display Change Site Button */
out.println("<br> <input type='submit' value='Display Sites' " +
"onClick=javascript:submitForm('selectSites'); >" );
out.println("</form>");
out.println("</BODY>");
out.println("</HTML>");
out.close();
}
}