|
||
<%@ page import="java.io.*,java.util.*" %> <% // This JSP file writes the IP address of its visitors into the file counter.txt // Pfad der Logdatei ermitteln String sSevletPath = request.getServletPath(); int iPos = sSevletPath.lastIndexOf("/"); String pfad = application.getRealPath(sSevletPath.substring(0, iPos)) + "/"; String datei="counter.txt"; // String pfad=application.getRealPath("/"); // String datei="rdvpn2/counter.txt"; String line="",content="", newContent=""; String sep1=";"; String sep2="."; String sep3=":"; String lsep=System.getProperty("line.separator"); GregorianCalendar cal=new GregorianCalendar(); int day=cal.get(Calendar.DATE); int month=cal.get(Calendar.MONTH)+1; int year=cal.get(Calendar.YEAR); int hour=cal.get(Calendar.HOUR_OF_DAY); int minute=cal.get(Calendar.MINUTE); int second=cal.get(Calendar.SECOND); String str_ipaddress = request.getRemoteAddr(); String data= str_ipaddress ; data = data + " Tag: "+day+sep2+month+sep2+year + " Zeit: " +hour+sep3+minute+sep3+second + lsep; File fileLoad=new File(pfad+datei); boolean bol=fileLoad.exists(); boolean re=fileLoad.canRead(); if(bol&&re) { try { FileReader fileInput=new FileReader(fileLoad); BufferedReader input=new BufferedReader(fileInput); while((line=input.readLine())!=null){ content=content+line+lsep; } input.close(); int pos=content.indexOf(""); String firstPart=content.substring(0,pos); String secondPart=content.substring(pos+14,content.length()); newContent=firstPart+""+lsep+data+secondPart; } catch(IOException ioex) { out.println("Dateilade-Fehler: "+ioex); } } else { out.println("
-- HOB index.jsp -- HTML Datei existiert nicht oder kann nicht gelesen werden!
"); } boolean rw=fileLoad.canWrite(); if(rw) { try { FileWriter fileOut=new FileWriter(fileLoad); BufferedWriter output=new BufferedWriter(fileOut); output.write(newContent); output.close(); } catch(IOException ioex) { out.println("-- HOB index.jsp -- Dateischreibe-Fehler: "+ioex); } } else { out.println("-- HOB index.jsp -- HOB count txt file kann nicht geschrieben werden!
"); out.println(pfad); } %>