我在ParseJspUtils.getHtml组装html,再把html组装成邮件发出,所以只要能生成转化的html就可以,不需要返回。
public class ParseJspUtils {
/**
* 获取jsp产生的html
* @param path
* @param data
* @return
* @throws Throwable
*/
public static Map<String,Object> getHtml(String path,Map<String,Object> data){
Map<String,Object> result = new HashMap<String,Object>();
try {
//多线程这里会报空指针异常
HttpServletResponse response = Mvcs.getResp();
HttpServletRequest request = Mvcs.getReq();
RequestDispatcher rd = request.getRequestDispatcher(path);
ByteArrayOutputStream os = new ByteArrayOutputStream();
final PrintWriter pw = new PrintWriter(new OutputStreamWriter(os,
"UTF-8"));
HttpServletResponse rep = new HttpServletResponseWrapper(response) {
public PrintWriter getWriter() throws IOException {
return pw;
}
};
request.setAttribute("obj", data);
rd.include(request, rep);
pw.flush();
result.put(MainModule.JTABLE_RESULT_KEY, MainModule.JTABLE_RESULT_VALUE_OK);
result.put("html", os.toString("UTF-8"));
} catch (Exception e) {
result.put(MainModule.JTABLE_RESULT_KEY, MainModule.JTABLE_RESULT_VALUE_ERROR);
// TODO Auto-generated catch block
e.printStackTrace();
}
return result;
}
}