社区
Web 开发
帖子详情
上传文件,在form标签里加了enctype="multipart/form-data"属性后,action收到的其它
内容中文乱码
封号码农
2014-05-15 06:25:31
jsp代码
<%@ page language="java" import="java.util.*" pageEncoding="GBK"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<base href="<%=basePath%>"
</head>
<body>
<form name="form" action="applyNewCourseAction" method="POST" enctype="multipart/form-data">
<table width="100%" border="0" cellpadding="5" cellspacing="1" bgcolor="#CCCCCC" >
<tr>
<th width="20%" bgcolor="#EEEEEE" scope="row">课程名称</th>
<td bgcolor="#FFFFFF"><div class="FrameDivNormal" id="usrFrameDiv"><input name="courseName" type="text" id="courseName" maxlength="16" ></div>
</td>
</tr>
<tr>
<th width="20%" bgcolor="#EEEEEE" scope="row">课程简介</th>
<td bgcolor="#FFFFFF"><div class="FrameDivNormal" id="usrFrameDiv"><textarea rows="5" cols="90" name="courseShortIntro"></textarea></div>
</td>
</tr>
<tr>
<th width="20%" bgcolor="#EEEEEE" scope="row">课程详细介绍</th>
<td bgcolor="#FFFFFF"><div class="FrameDivNormal" id="usrFrameDiv"><textarea rows="10" cols="90" name="courseIntro"></textarea></div>
</td>
</tr>
<tr>
<th bgcolor="#EEEEEE" scope="row">选择课程封面</th>
<td bgcolor="#FFFFFF">
<input type="file" name="upload"></td>
</tr>
<tr>
<th bgcolor="#EEEEEE" scope="row"> </th>
<td bgcolor="#FFFFFF">
<input type="submit" name="submit" value="提交" >
<input type="button" onclick="javascript:history.back(-1);" value="返回" >
</td>
</tr>
</table>
</form>
</body>
</html>
接受的action
public class CourseOperateAction extends ActionSupport {
private CourseDAO courseDao;
private String courseName;
private String courseShortIntro;
private String courseIntro;
private File upload;
private String uploadFileName;
private String savePath;
<--省略get和set-->
private static void copy(File src, File dst) {
InputStream in = null;
OutputStream out = null;
try {
in = new BufferedInputStream(new FileInputStream(src), 16 * 1024);
out = new BufferedOutputStream(new FileOutputStream(dst),
16 * 1024);
byte[] buffer = new byte[16 * 1024];
int len = 0;
while ((len = in.read(buffer)) > 0) {
out.write(buffer, 0, len);
}
} catch (Exception e) {
e.printStackTrace();
} finally {
if (null != in) {
try {
in.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if (null != out) {
try {
out.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
public String addCourse() throws Exception {
HttpSession session=ServletActionContext.getRequest().getSession();
courseName=new String(courseName.getBytes("iso-8859-1"),"GBK");
courseShortIntro=new String(courseShortIntro.getBytes("iso-8859-1"),"GBK");
courseIntro=new String(courseIntro.getBytes("iso-8859-1"),"GBK");
Course course=new Course();
course.setCName(courseName);
course.setCFlash(courseShortIntro);
course.setCIntro(courseIntro);
course.setCCheck("0");
course.setTId((Long)session.getAttribute("userid"));
String dstPath="E:\\Graduate design\\mooc\\WebRoot\\images\\course\\"+ " " + (Long)session.getAttribute("userid")+this.getUploadFileName();
System.out.println(dstPath);
File dstFile = new File(dstPath);
copy(this.upload, dstFile);
String c_pic="images/course/"+(Long)session.getAttribute("userid")+this.getUploadFileName();
course.setCPic(c_pic);
courseDao.save(course);
return SUCCESS;
}
}
所有的编码格式都为GBK。
...全文
428
7
打赏
收藏
上传文件,在form标签里加了enctype="multipart/form-data"属性后,action收到的其它<input>内容中文乱码
jsp代码 <base href="" <form name="form" action="applyNewCourseAction" method="POST" enctype="multipa
复制链接
扫一扫
分享
转发到动态
举报
AI
作业
写回复
配置赞助广告
用AI写文章
7 条
回复
切换为时间正序
请发表友善的回复…
发表回复
打赏红包
tony4geek
2014-05-16
打赏
举报
回复
ourseName=new String(courseName.getBytes("iso-8859-1"),"GBK"); courseShortIntro=new String(courseShortIntro.getBytes("iso-8859-1"),"GBK"); courseIntro=new String(courseIntro.getBytes("iso-8859-1"),"GBK"); 这些先不转,获取先看看。
samuel072
2014-05-16
打赏
举报
回复
首先一点 就是使用上传功能必须是post提交,而使用post提交就必须需要再Servlet中 接收参数前设置你的编码方式,使用ServletActionContext 来设置编码方法 你试试看
DwGoing
2014-05-16
打赏
举报
回复
你看下数据库的编码格式
封号码农
2014-05-15
打赏
举报
回复
写过过滤器,无效就撤了 package filter; import javax.servlet.*; import javax.servlet.http.*; import java.io.*; import java.util.*; public class SetCharacterEncodingFilter extends HttpServlet implements Filter { protected String encoding = null; protected FilterConfig filterConfig = null; protected boolean ignore = true; // Handle the passed-in FilterConfig public void init(FilterConfig filterConfig) throws ServletException { this.filterConfig = filterConfig; this.encoding = filterConfig.getInitParameter("encoding"); String value = filterConfig.getInitParameter("ignore"); if (value == null) { this.ignore = true; } else if (value.equalsIgnoreCase("true")) { this.ignore = true; } else if (value.equalsIgnoreCase("yes")) { this.ignore = true; } else { this.ignore = false; } } // Process the request/response pair public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { // Conditionally select and set the character encoding to be used if (ignore || (request.getCharacterEncoding() == null)) { String encoding = selectEncoding(request); if (encoding != null) { request.setCharacterEncoding(encoding); response.setCharacterEncoding(encoding); } } // Pass control on to the next filter chain.doFilter(request, response); } protected String selectEncoding(ServletRequest request) { return (this.encoding); } // Clean up resources public void destroy() { this.encoding = null; this.filterConfig = null; } }
封号码农
2014-05-15
打赏
举报
回复
不好意思,说错了,是在<form> 把method属性设置为POST时乱码,不管enctype的事
teemai
2014-05-15
打赏
举报
回复
直接打印这个看下先:courseName 为什么不写过滤器
封号码农
2014-05-15
打赏
举报
回复
springmvc ajaxFileUpload
上传文件
(前后台彻底分离的情况下)
首先是导入jar包: web.xml: 1
2
mvc-dispatcher
3
个人渗透笔记
【 拿shell 】 1.直接上传asp asa jsp cer php aspx htr cdx 格式的木马,不行就利用IIS6.0解析漏洞":1.asp;1.jpg/1.asp;.jpg/1.asp;jpg/1.asp;.xls 2.上传图片木马遇到拦截系统,连图片木马都上传不了,记事本打开图片木马在代码最前面加上gif89a,一般就能逃过拦截系统了。 3.上传图片木马把地址复制到数据库
struts2的
上传文件
与下载文件
前言:在数据库中,我们一般都是保存文件的信息(保存的路径,文件名等等),而不会把文件当作Clob打字段保存在数据库中。所以
上传文件
和下载文件的思路就清晰了很多。限于时间,这里只记录大概思路,具体详细
内容
可以根据根据文中提到的关键字google,相信很快能解决,有时间再完善吧。 上传: 1、把文件通过
Input
Stream传送到服务器指定的磁盘或文件夹 2、把文件的对应信...
SpringMVC
课程来自b站尚硅谷springmvc相关视频教程SpringMVC 2021新版教程 课程主要
内容
: 1. springMVC入门 1.1 简介 1.2 入门案例 helloworld pom.xml: <?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSche
asp经典例子
主 题: ASP常见问题及解答征集中,请大家积极参与~~~~~~~~ 作 者: awaysrain (绝对零度)(新的一年,新的开始) 等 级: 信 誉 值: 155 所属论坛: Web 开发 ASP 问题点数: 200 回复次数: 160 发表时间: 2003-11-07 14:09:24Z 征集常见问题及解决方法,禁止灌水,否则将删除!格式分 类
Web 开发
81,122
社区成员
341,744
社区内容
发帖
与我相关
我的任务
Web 开发
Java Web 开发
复制链接
扫一扫
分享
社区描述
Java Web 开发
社区管理员
加入社区
获取链接或二维码
近7日
近30日
至今
加载中
查看更多榜单
社区公告
暂无公告
试试用AI创作助手写篇文章吧
+ 用AI写文章