📄 htmlgenerator.java
字号:
package cn.js.fan.util.file;import java.io.*;import java.util.Calendar;import javax.servlet.*;import javax.servlet.http.*;import cn.js.fan.util.ParamUtil;import cn.js.fan.web.Global;public class HTMLGenerator { private String visualPath; public HTMLGenerator() { } public void exec(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String url = ""; String name = ""; String file_name = request.getParameter("fileName"); String p0 = ParamUtil.get(request, "p0"); String v0 = ParamUtil.get(request, "v0"); String p1 = ParamUtil.get(request, "p1"); String v1 = ParamUtil.get(request, "v1"); Calendar cal = Calendar.getInstance(); String year = "" + (cal.get(cal.YEAR)); String month = "" + (cal.get(cal.MONTH) + 1); String filepath = "article/" + year + "/" + month; url = "/" + file_name + ".jsp?" + p0 + "=" + v0; if (!p1.equals("")) url = url + "&" + p1 + "=" + v1; String realPath = Global.getRealPath(); name = v0 + ".htm"; visualPath = filepath + "/" + name; String fullPath = realPath + visualPath; RequestDispatcher rd = request.getRequestDispatcher(url); final ByteArrayOutputStream os = new ByteArrayOutputStream(); final ServletOutputStream stream = new ServletOutputStream() { public void write(byte[] data, int offset, int length) { os.write(data, offset, length); } public void write(int b) throws IOException { os.write(b); } }; final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os, "utf-8")); HttpServletResponse rep = new HttpServletResponseWrapper(response) { public ServletOutputStream getOutputStream() { return stream; } public PrintWriter getWriter() { return pw; } }; rd.include(request, rep); pw.flush(); FileOutputStream fos = new FileOutputStream(fullPath); os.writeTo(fos); fos.close(); response.sendRedirect(visualPath); } public void setVisualPath(String visualPath) { this.visualPath = visualPath; } public String getVisualPath() { return visualPath; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -