此方法在Hook中实现
folderName: search-hook\docroot\WEB-INF\src\portal-ext.properties 文件下定义想要保存的路径
要求保存的格式:
文件名: 201305.txt
文件内容:2013/05/05 15:25:25 "关键字" screenName
<%!
private void uploadFile(String keywords, HttpServletRequest request) throws Exception {String searchKeywordFolder = PropsUtil.get("folderName");
SimpleDateFormat fm = new SimpleDateFormat("yyyyMM");
User user = PortalUtil.getUser(request);
String screenName = "";
if(user != null) {
screenName = user.getScreenName();
}
String filePath = searchKeywordFolder;
File fileFolder = new File(filePath);
if (!fileFolder.exists()) {
fileFolder.mkdirs();
}
String fileName = fm.format(new Date()) + ".txt";
File file = new File(filePath + "/" + fileName);
RandomAccessFile raf = null;
try {
raf = new RandomAccessFile(file, "rw");
if (file.exists()) {
raf.seek(file.length());
}
SimpleDateFormat fmat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
String systemDate = fmat.format(new Date());
StringBuffer sb = new StringBuffer();
sb.append(systemDate);
sb.append(StringPool.SPACE);
sb.append(StringPool.QUOTE);
sb.append(keywords);
sb.append(StringPool.QUOTE);
sb.append(StringPool.SPACE);
sb.append(screenName);
sb.append(StringPool.RETURN_NEW_LINE);
String writeKeyworkd = sb.toString();
raf.write(writeKeyworkd.getBytes());
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != raf) {
try {
raf.close();
} catch (Exception e) {
e.printStackTrace();
}
}
}
}
%>
抛出的异常有可能的话,还是要处理一下