把参数加后面试试。
script : xxx.action?appNo=201312261623request.getParameter("appNo");
script : xxx.action?appNo=201312261623request.getParameter("appNo");
解决方案 »
- Ext中toolbar的问题,高手请帮忙看看。。。
- 页面测试出现500错误提示
- 晕掉,第八行看不懂哪里错了!
- ★急!!怎样让服务器定时自动运行servlet??
- 关于js的方法实现(如有好答案,立即结贴.参与者均有分)
- 谁有jsp+sql server 2000做的一个简易的留言板啊?
- 请教一下:怎样操作才能把access数剧库和mysql数剧库导入oracle 9i?
- jsp联盟 我在这里邀请大家 希望长期在线 学jsp的朋友留下您的QQ 方便大家联系 在线交流
- 约瑟夫问题用数组求解!
- j2se swing方面的书帮忙推荐几本,谢谢
- hibernate怎么通过实体类创建数据库表
- 关于java,有谁能帮帮我啊,郁闷
嗯,我知道,但是我先要获取appNo才行啊
上传是插件做的,跳转的是servlet后面也不带参数的,我在看插件自己有没有什么参数能够把前台参数带到后台,貌似有个formdata和onUploadStart可以用用
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);是这个?
是取不到的
throws ServletException, IOException {
response.setCharacterEncoding("utf-8");
String savePath = request.getSession().getServletContext().getRealPath(File.separator+"AppImgPackage"+File.separator); DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setHeaderEncoding("utf-8");
List fileList = null;
try {
fileList = upload.parseRequest(request);
} catch (FileUploadException ex) {
ex.printStackTrace();
}
Iterator<FileItem> it = fileList.iterator();
String name = "";
String extName = "";
String category = "";
while (it.hasNext()) {
FileItem item = it.next();
String appNo = item.getString("appNo");
System.out.println("第三方应用多图片上传uploadify使用的UploadController中测试appNo:"+appNo);
if (item.isFormField()) {
if ("category".equals(item.getFieldName())) {
category = item.getString("utf-8");
}
} else if (!item.isFormField()) {
name = item.getName();
System.out.println("第三方应用多图片上传uploadify使用的UploadController中测试name:"+name);
if (name == null || name.trim().equals("")) {
continue;
}
// 扩展名格式:
if (name.lastIndexOf(".") >= 0) {
extName = name.substring(name.lastIndexOf("."));
}
savePath = savePath + category + "/";
File f1 = new File(savePath);
if (!f1.exists()) {
f1.mkdirs();
}
File saveFile = new File(savePath + name);
try {
item.write(saveFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
response.getWriter().print(name);
String appNo= new String(item.getString())
其中item是遍历出来的项。
item.getFieldName() 这是去表单里文本框或其他元素的名字。
item.getString() 取到值 。
试试吧
我这么弄的
<p>
<a href="javascript:$('#uploadify').uploadifySettings('scriptData',{'appNo':$('#appNo').val()})" onClick="javascript:uploadifyUpload()">开始上传</a>
<a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上传</a>
</p>后台这么取
String appNo = request.getParameter("appNo");
System.out.println("第三方应用多图片上传uploadify使用的UploadController中测试appNo:"+appNo);还是没取到呢
试了的下面3种方式
String appNo = item.getFieldName(); //显示 Filename
String appNo = request.getParameter("appNo"); //显示 null
String appNo = request.getParameterValues("appNo")[0]; //报错
String appNo= new String(item.getString())这俩一起用 就取出来了 你好好看 用点心
String appNo = "";
if("appNo".equals(item.getFieldName())){
appNo = new String (item.getString());
}
System.out.println("第三方应用多图片上传uploadify使用的UploadController中测试appNo:"+appNo);依然没有取到呢,哥么
HttpServletRequest request, HttpServletResponse response) {
UserInfo po =new UserInfo();
DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
// 最大允许大小5M
// upload.setSizeMax(1024 * 1024 * 5);
String appName=request.getContextPath();
String path="../webapps"+appName+"/files/";
String purl="";
try {
List<FileItem> items = upload.parseRequest((HttpServletRequest) request);
for (FileItem item : items) {
if (!item.isFormField()) {
String fname = item.getName();
path=path+fname;
purl="files/"+fname;
//System.out.println(path+"$$$"+purl);
File f=new File(path);
if(f.getParentFile().exists()) f.getParentFile().mkdirs();
f.createNewFile();
FileOutputStream fi=new FileOutputStream(f);
InputStream in=item.getInputStream();
byte buffer[] = new byte[8192];
int bytesRead=0;
while ( (bytesRead = in.read(buffer, 0, 8192)) != -1){
fi.write(buffer, 0, bytesRead);
}
in.close();
fi.close();
}else {
if("name".equals(item.getFieldName())){
String name = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setName(name );
}
if("city".equals(item.getFieldName()))
{
String city = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setCity(city);
}
if("number".equals(item.getFieldName())) {
String s=item.getString();
po.setNumber(s);
po.setBirthday(subStr(s));
};
if("province".equals(item.getFieldName())) {
String province = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setProvince(province);
}
if("sex".equals(item.getFieldName()))
{
String sex = new String(item.getString()
.getBytes("ISO-8859-1"),"UTF-8");
po.setSex(sex);
}
}
}
} catch (Exception e) {
e.printStackTrace();
}
po.setPurl(purl);
service.insert(po);
return mapping.findForward("susses");
}
if (filedName.equals("appNo")) {
String appNo= item.getString();
}
$('#uploadify').uploadifySettings('scriptData', {'appNo' : appNo});
$('#uploadify').uploadifyUpload();
}
</script> <script type="text/javascript">
$(document).ready(function() {
$("#uploadify").uploadify({
'uploader' : '<%=request.getContextPath()%>/uploadify.swf',
'script' : '<%=basePath %>/UploadController',
'cancelImg' : '<%=request.getContextPath()%>/images/cancel.png',
'queueID' : 'fileQueue',
'auto' : false,
'multi' : true,
'buttonText' : 'Browse file',
'fileExt': '*.jpg;*.gif;*.jpeg;*.png;*.bmp',
'fileDesc': '请选择jpg,gif,jpeg,png,bmp格式',
'queueSizeLimit' : 5,
'method' : 'GET',
onComplete: function (evt, queueID, fileObj, response, data) {
$('#appImg').val($('#appImg').val()+response+',');
},
onError: function(a, b, c, d) {
alert("文件上传失败");
}
}); });页面点击上传处代码
<p>
<a href="javascript:$('#uploadify').uploadifySettings('scriptData',{'appNo':$('#appNo').val()})" onClick="javascript:uploadifyUpload()">开始上传</a>
<a href="javascript:jQuery('#uploadify').uploadifyClearQueue()">取消所有上传</a>
</p>
页面代码放上了,用的Uploadify,刚看了下这篇文章http://www.uploadify.com/forum/#/discussion/5611/uploadifysettings-not-posting-new-script-data/p1
我尝试加上在uploadify方法中加上
'scriptData' : {'weddingId' : '201006-1120140', 'aspectRatio' : '16:9'},
上传插件就显示异常了
你在方法的最上边,用这个取一下试试 。
我就想不明白,你用
String filedName = item.getFieldName();
都取到表单的元素名了
String appNo= item.getString();
这个会取不到值?
你看看还有其他方法取值。纠结 你帖一下我看你怎么取得 ,
真纠结
throws ServletException, IOException {
response.setCharacterEncoding("utf-8");String savePath = request.getSession().getServletContext().getRealPath(File.separator+"AppImgPackage"+File.separator);DiskFileItemFactory fac = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(fac);
upload.setHeaderEncoding("utf-8");
List fileList = null;
try {
fileList = upload.parseRequest(request);
} catch (FileUploadException ex) {
ex.printStackTrace();
}
Iterator<FileItem> it = fileList.iterator();
String name = "";
String extName = "";
String category = "";while (it.hasNext()) {
FileItem item = it.next();String appNo = item.getString("appNo");
System.out.println("第三方应用多图片上传uploadify使用的UploadController中测试appNo:"+appNo);if (item.isFormField()) { String filedName = item.getFieldName();
if (filedName.equals("appNo")) {
String appNo= item.getString();
System.out.print(appNo);
} if ("category".equals(item.getFieldName())) {
category = item.getString("utf-8");
}
} else if (!item.isFormField()) {
name = item.getName();
System.out.println("第三方应用多图片上传uploadify使用的UploadController中测试name:"+name);
if (name == null || name.trim().equals("")) {
continue;
}
// 扩展名格式:
if (name.lastIndexOf(".") >= 0) {
extName = name.substring(name.lastIndexOf("."));
}
savePath = savePath + category + "/";
File f1 = new File(savePath);
if (!f1.exists()) {
f1.mkdirs();
}
File saveFile = new File(savePath + name);
try {
item.write(saveFile);
} catch (Exception e) {
e.printStackTrace();
}
}
}
response.getWriter().print(name);
form 里的 method="POST" enctype="multipart/form-data" 加了以后
表单提交 后台req是取不到的