<%@page import="java.util.*,java.text.*,java.io.*"%> <% /* Inizializzare la variabile "FooterPagePrint" */ String nomeFile, argomenti, testo, inFile, outFile, strInizioStampa, strFineStampa,pathNews, FooterPagePrint; strInizioStampa = ""; strFineStampa = ""; FooterPagePrint = "Makinaitalia.com
powered by Telemar
"; pathNews = application.getRealPath(""); // String Ref = request.getHeader( "Referer" ).substring("http://".length(),request.getHeader( "Referer" ).length()); // nomeFile = Ref.substring(Ref.indexOf(java.io.File.separator)+1,Ref.length()); nomeFile = request.getParameter("f"); if (nomeFile.endsWith(".jsp")){ out.print(""); return; } try { java.io.File file = new java.io.File(pathNews,nomeFile); if (file.exists()) { Reader fRd = new FileReader(file); StringBuffer allfile = new StringBuffer(); try { BufferedReader fh = new BufferedReader(fRd); String line; while ((line = fh.readLine()) != null) { allfile.append(line); } fh.close(); } catch (IOException e) { } String MyAllTesto = allfile.toString().trim(); if (MyAllTesto.indexOf(strInizioStampa) >= 0 && MyAllTesto.indexOf(strFineStampa) >= 0){ int PosInizioStampa = MyAllTesto.indexOf(strInizioStampa); int PosFineStampa = MyAllTesto.indexOf(strFineStampa); StringBuffer MyTesto = new StringBuffer(); int Posbody = MyAllTesto.indexOf("
"); MyTesto.append(MyAllTesto.substring(PosInizioStampa+strInizioStampa.length(),PosFineStampa)); MyTesto.append("

").append(FooterPagePrint).append("
"); out.print(MyTesto.toString()); }else{ out.print(MyAllTesto); } out.print(""); } else { out.print(""); return; } }catch (Exception e){ out.print("Exception: " +e); } //Scrittura su file di log String Separator = java.io.File.separator; String Path = application.getRealPath("") + "log" + Separator; String FileName = "stampa.log"; Date now = new Date(); SimpleDateFormat hDay_format = new SimpleDateFormat("dd", Locale.ITALIAN); String NrDay = hDay_format.format(now); SimpleDateFormat hMonth_format = new SimpleDateFormat("MM", Locale.ITALIAN); String NrMonth = hMonth_format.format(now); SimpleDateFormat hYear_format = new SimpleDateFormat("yyyy", Locale.ITALIAN); String NrYear = hYear_format.format(now); SimpleDateFormat hTime_format = new SimpleDateFormat("HH:mm:ss", Locale.ITALIAN); String NrTime = hTime_format.format(now); String Data = NrDay + "/" + NrMonth + "/" + NrYear + " " + NrTime ; // FileOutputStream fwrite = null; try { java.io.File file_log = new java.io.File(Path,FileName); if (file_log.exists()) { } else { file_log.createNewFile(); } if (file_log.canWrite()){ fwrite = new FileOutputStream(file_log,true); String TestoRiga = Data + "," + request.getRemoteAddr() + "," + nomeFile; TestoRiga += "\r\n"; fwrite.write(TestoRiga.getBytes()); fwrite.close(); } } catch(Exception ex){ out.print("Error writing stampa log : " + ex); } finally{ try{ fwrite.close(); } catch(Exception ex){ } } %>