项目中的表单需要多上传,这个使用Upload组件就OK了,但是表单验证就出现问题了:
1、首先,上传项是必须项,不能无提交;
2、已上传的可以删除;
3、后端要求提交的为md5格式,通过上传接口获取的md5值,这样就不能直接使用表单提交时获取的 value值,因 为它的值是本地路径,所以我通过model中上传获取md5的值存在model的state中 (这个问题是最棘手的)。
保存地址,类似“~/Images/UserId/facepng”
那么这个属于服务器端相对地址
string dir=@"\UserFiles\Images\";
string phyPath = RequestPhysicalApplicationPath;
string virPath = dir + ServerHtmlEncode(FileUpload1FileName);
string savePath = phyPath + virPath;
fileUploadSaveAs(savePath);
那么你往数据库里保存的就是 virPath 这个虚拟路径。
virPath = ServerMapPath(dir + FileUpload1FileName);
这也是转换正相对URL。
您好,不一定要设置cookie里的,手动附值也行的~~ {"uid":1394}
post_params: {"name":"123","id":"123","sel":"new"},这是我的设置,3个参数,在servlet里面用
String name = >
1首先是jsp
<button class="btn button uploadAndNext" id="importWhiteBtn" type="button">
<span class="button">提交导入</span>
</button>
2然后是js
$(function(){
var uploadCom = null;
function uploadIt() {
$("#importWhiteBtn")click(function() {
var uploadId = "#" + $(this)attr("id");
var btn = $(this);
uploadCom = new AjaxUpload( uploadId + "" , {
action : "whitePhoneNumberdoaction=importFile",
onSubmit: function(file, ext) {
if ((ext && /^(txt)$/test(ext))) {
alert("请先下载导入模板readmetxt参考,您上传的文档格式不对,请重新选择!");
return false;
}
$blockUI({
message:"正在上传到服务器"
})
},
onComplete: function(file, response) {
$unblockUI();
if(response=="success"){
alert( "导入成功");
$('#whitePhoneList')flexReload();
}else{
alert( "导入失败,"+response);
}
}
});
});
$("uploadAndNext")click();
}
uploadIt();
firstClick = false;
})
3最后是action
public ActionForward importFile(ActionMapping mapping, ActionForm form,
>
参考例子如下,相关注释已经在代码中写明;
#region 文件上传
/// <summary>
/// 上传文件(自动分割)
/// </summary>
/// <param name="filePath">待上传的文件全路径名称(@"E:\FTP\ftproot\20070228DQCKzip")</param>
/// <param name="hostURL">服务器的地址</param>
/// <param name="byteCount">分割的字节大小</param>
/// <param name="userID">主机用户ID</param>
/// <param name="cruuent">当前字节指针</param>
/// <returns>成功返回"";失败则返回错误信息</returns>
public string UpLoadFile(string filePath, string hostURL, int byteCount, string userID, long cruuent)
{
string tmpURL = hostURL;
byteCount = byteCount 1024;
SystemNetWebClient WebClientObj = new SystemNetWebClient();
FileStream fStream = new FileStream(filePath, FileModeOpen, FileAccessRead);
BinaryReader bReader = new BinaryReader(fStream);
long length = fStreamLength;
string sMsg = "版式上传成功";
string fileName = filePathSubstring(filePathLastIndexOf('\\') + 1);
try
{
#region 续传处理
byte[] data;
if (cruuent > 0)
{
fStreamSeek(cruuent, SeekOriginCurrent);
}
#endregion
#region 分割文件上传
for (;cruuent <= length; cruuent = cruuent + byteCount)
{
if (cruuent + byteCount > length)
{
data = new byte[ConvertToInt64((length - cruuent))];
bReaderRead(data, 0, ConvertToInt32((length - cruuent)));
}
else
{
data = new byte[byteCount];
bReaderRead(data, 0, byteCount);
}
try
{
hostURL = tmpURL + "&action=upload" + "&filename=" + fileName + "&userid=" + userID + "&npos=" + cruuentToString();
//hostURL = tmpURL + DateTimeNowToString("yyyyMMddHHmmssfff") + "txt";
byte[] byRemoteInfo = WebClientObjUploadData(hostURL, "POST", data);
string sRemoteInfo = SystemTextEncodingDefaultGetString(byRemoteInfo);
// 获取返回信息
if (sRemoteInfoTrim() != "")
{
sMsg = sRemoteInfo;
break;
}
}
catch (Exception ex)
{
sMsg = exToString();
break;
}
}
#endregion
}
catch (Exception ex)
{
sMsg = sMsg + exToString();
}
try
{
bReaderClose();
fStreamClose();
}
catch (Exception exMsg)
{
sMsg = exMsgToString();
}
GCCollect();
return sMsg;
}
#endregion
以上就是关于antd 表单验证如何快速定位到错误的地方全部的内容,包括:antd 表单验证如何快速定位到错误的地方、使用FileUpload上传图片,怎样获取图片的URL、java后台怎么获取swfupload控件传过来的绝对路径等相关内容解答,如果想了解更多相关内容,可以关注我们,你们的支持是我们更新的动力!
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)