public void createHpSearchJsp(HttpServletRequest request) {
String hostpath = request.getRealPath("/");
String hpTemplatePath = hostpath + "homepage/parts/hpsearchbarTemplate.jsp";
String outHpPath = hostpath + "homepage/parts/hpsearchbar.jsp";
File templateFile = new File(hpTemplatePath);
File searchbarFile = new File(outHpPath);
try {
FileInputStream fileInput = new FileInputStream(templateFile);
InputStreamReader inputStrReader = new InputStreamReader(fileInput, "UTF-8");
BufferedReader buffereReader = new BufferedReader(inputStrReader);
FileOutputStream fileOutput = new FileOutputStream(searchbarFile);
PrintWriter fileWrite = new PrintWriter(new OutputStreamWriter(fileOutput, "UTF-8"));
BufferedWriter buffereWriter = new BufferedWriter(fileWrite);
String line = "";
while ((line = buffereReader.readLine()) != null) {
buffereWriter.write(line);
buffereWriter.write("\r\n");
}
buffereReader.close();
inputStrReader.close();
fileInput.close();
buffereWriter.write("<script>");
List<SearchOptionBean> searchOpList = getAll();
if (searchOpList != null && searchOpList.size() > 0) {
JSONArray jsArray = new JSONArray();
JSONObject jsObject = null;
for (SearchOptionBean b : searchOpList) {
jsObject = new JSONObject();
jsObject.element("id", b.getId());
jsObject.element("searchname", b.getSearchname());
jsObject.element("searchcontent", b.getSearchcontent());
jsArray.add(jsObject);
}
String json = jsArray.toString();
buffereWriter.write("sch=" + json + ";");
}
buffereWriter.write("var _hpsearch=new HomePageSearch(sch,'_hpsearch');");
buffereWriter.write("</script>");
buffereWriter.close();
fileWrite.close();
fileOutput.close();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
posted on 2011-05-23 10:29
SIMONE 阅读(3359)
评论(0) 编辑 收藏 所属分类:
JAVA