提交 7a6292e3 编写于 作者: 黄勇

【I】合并 smart-framework 1.0.1 的代码

上级 9133ab6f
......@@ -3,11 +3,11 @@ Smart Framework
源码地址:
http://git.oschina.net/huangyong/smart-framework
应用示例:
http://git.oschina.net/huangyong/smart-sample
项目聚合:
http://git.oschina.net/huangyong/smart-parent
应用示例:
http://git.oschina.net/huangyong/smart-sample
系列博文:
http://my.oschina.net/huangyong/blog/158380
\ No newline at end of file
......@@ -18,11 +18,10 @@ public class ContainerListener implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext context = sce.getServletContext();
// 初始化相关 Helper 类
HelperLoader.init();
// 添加 Servlet 映射
addServletMapping(context);
addServletMapping(sce.getServletContext());
}
@Override
......
......@@ -18,7 +18,7 @@ public class EncodingFilter implements Filter {
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding(FrameworkConstant.CHARSET_UTF);
request.setCharacterEncoding(FrameworkConstant.UTF_8);
chain.doFilter(request, response);
}
......
......@@ -2,8 +2,7 @@ package com.smart.framework;
public interface FrameworkConstant {
String CHARSET_UTF = "UTF-8";
String CHARSET_ISO = "ISO-8859-1";
String UTF_8 = "UTF-8";
String APP_HOME_PAGE = "app.home_page";
String APP_JSP_PATH = "app.jsp_path";
......@@ -15,5 +14,4 @@ public interface FrameworkConstant {
String JSP_SERVLET_NAME = "jsp";
String PLUGIN_PACKAGE = "com.smart.plugin";
String MODULE_PACKAGE = "com.smart.module";
}
......@@ -75,7 +75,7 @@ public class UploadHelper {
String fieldName = fileItem.getFieldName();
if (fileItem.isFormField()) {
// 处理普通字段
String fieldValue = fileItem.getString(FrameworkConstant.CHARSET_UTF);
String fieldValue = fileItem.getString(FrameworkConstant.UTF_8);
fieldMap.put(fieldName, fieldValue);
} else {
// 处理文件字段
......@@ -92,6 +92,7 @@ public class UploadHelper {
}
// 初始化参数列表
paramList.add(fieldMap);
// 不管一个文件还是多个文件,都映射为 Multiparts 参数
if (CollectionUtil.isNotEmpty(multipartList)) {
paramList.add(new Multiparts(multipartList));
} else {
......
......@@ -19,7 +19,7 @@ public class CodecUtil {
public static String urlEncode(String str) {
String target;
try {
target = URLEncoder.encode(str, FrameworkConstant.CHARSET_UTF);
target = URLEncoder.encode(str, FrameworkConstant.UTF_8);
} catch (Exception e) {
logger.error("编码出错!", e);
throw new RuntimeException(e);
......@@ -31,7 +31,7 @@ public class CodecUtil {
public static String urlDecode(String str) {
String target;
try {
target = URLDecoder.decode(str, FrameworkConstant.CHARSET_UTF);
target = URLDecoder.decode(str, FrameworkConstant.UTF_8);
} catch (Exception e) {
logger.error("解码出错!", e);
throw new RuntimeException(e);
......@@ -43,7 +43,7 @@ public class CodecUtil {
public static String encodeBase64(String str) {
String target;
try {
target = Base64.encodeBase64URLSafeString(str.getBytes(FrameworkConstant.CHARSET_UTF));
target = Base64.encodeBase64URLSafeString(str.getBytes(FrameworkConstant.UTF_8));
} catch (UnsupportedEncodingException e) {
logger.error("编码出错!", e);
throw new RuntimeException(e);
......@@ -55,7 +55,7 @@ public class CodecUtil {
public static String decodeBase64(String str) {
String target;
try {
target = new String(Base64.decodeBase64(str), FrameworkConstant.CHARSET_UTF);
target = new String(Base64.decodeBase64(str), FrameworkConstant.UTF_8);
} catch (UnsupportedEncodingException e) {
logger.error("解码出错!", e);
throw new RuntimeException(e);
......
......@@ -120,7 +120,7 @@ public class FileUtil {
try {
FileUtil.createFile(filePath);
os = new BufferedOutputStream(new FileOutputStream(filePath));
w = new OutputStreamWriter(os, FrameworkConstant.CHARSET_UTF);
w = new OutputStreamWriter(os, FrameworkConstant.UTF_8);
w.write(fileContent);
w.flush();
} catch (Exception e) {
......
package com.smart.framework.util;
import com.smart.framework.FrameworkConstant;
import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics2D;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
......@@ -33,7 +31,7 @@ public class WebUtil {
try {
// 设置响应头
response.setContentType("application/json"); // 指定内容类型为 JSON 格式
response.setCharacterEncoding(FrameworkConstant.CHARSET_UTF); // 防止中文乱码
response.setCharacterEncoding(FrameworkConstant.UTF_8); // 防止中文乱码
// 向响应中写入数据
PrintWriter writer = response.getWriter();
......@@ -49,7 +47,7 @@ public class WebUtil {
try {
// 设置响应头
response.setContentType("text/html"); // 指定内容类型为 HTML 格式
response.setCharacterEncoding(FrameworkConstant.CHARSET_UTF); // 防止中文乱码
response.setCharacterEncoding(FrameworkConstant.UTF_8); // 防止中文乱码
// 向响应中写入数据
PrintWriter writer = response.getWriter();
......@@ -182,7 +180,7 @@ public class WebUtil {
public static void downloadFile(HttpServletResponse response, String filePath) {
try {
String originalFileName = FilenameUtils.getName(filePath);
String downloadedFileName = new String(originalFileName.getBytes("GBK"), FrameworkConstant.CHARSET_ISO);
String downloadedFileName = new String(originalFileName.getBytes("GBK"), "ISO8859_1"); // 防止中文乱码
response.setContentType("application/octet-stream");
response.addHeader("Content-Disposition", "attachment;filename=\"" + downloadedFileName + "\"");
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册