这个功能在html页面中是可以实现的,核心就是用ajax技术。
html核心代码
保存到本地
内容:
//servlet核心代码
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
process(request, response);
}
private void process(HttpServletRequest request,
HttpServletResponse response){
BufferedWriter bw = null;
try {
request.setCharacterEncoding("UTF-8");
response.setCharacterEncoding("UTF-8");
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String content = request.getParameter("content");
bw = new BufferedWriter(new OutputStreamWriter(new FileOutputStream("c:/content.txt")));
bw.write(content);
bw.flush();
pw.print("保存成功");
} catch (Exception e) {
e.printStackTrace();
}finally{
try {
if(bw != null){
bw.close();
bw = null;
}
} catch (IOException e) {
e.printStackTrace();
}
}
}