gpt4 book ai didi

mysql - org.springframework.web.multipart.MultipartException : Current request is not a multipart request

转载 作者:行者123 更新时间:2023-11-29 18:42:33 25 4
gpt4 key购买 nike

我尝试从项目详细信息页面添加图像。图像添加成功,但是当我尝试在 itemdetails 页面显示图像时,出现异常 org.springframework.web.multipart.MultipartException: Current request is not a multipart request

JSP:

<div class="panel panel-info">
<%-- <form:form method="POST" name="moduleForm1" modelAttribute="DocumentEntity"> --%>
<input type="hidden" name="selectedId3" value="${DocumentEntity.documentSeq}" />
<div class="panel-heading clearfix">
<div class="col-lg-6 col-md-6 col-sm-12 col-xs-12">
<h4 class="pull-left">Item Images</h4>
</div>
<div class="col-lg-1 col-md-1 col-sm-12 col-xs-12">
<h4 class="pull-left">Select File</h4>
</div>
<div class="col-lg-3 col-md-3 col-sm-12 col-xs-12">
<%-- <html:file name="ItemForm" property="desc" styleClass="form-control"></html:file> --%>
<input type="file" name="file" id="file" enctype="multipart/form-data"/>
</div>

附件服务:

    package com.groups.attachements;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.hibernate.Query;
import org.hibernate.Session;

import com.groups.GroupsConstants;
import com.groups.GroupsCustomeException;
import com.groups.GroupsFileManager;
import com.groups.GroupsObjectImpl;
import com.groups.GroupsUtils;
import com.groups.dao.DropDownListBean;
import com.groups.dao.GroupsBaseAccess;
import com.groups.dao.GroupsDAOContext;
import com.groups.dao.GroupsDAOContextFactory;
import com.groups.spring.annotations.GroupsRequest;

@GroupsRequest
public class AttachmentServiceImpl extends GroupsObjectImpl implements
AttachmentService
{
String appID = "IMS";

String sponsorID;

long sponsorSeq;

String moduleID;

DocumentEntity documentEntity;

public static final String ITEM_ENTITY = "ITEM";

public AttachmentServiceImpl()
{
appID = GroupsConstants.getApplicationDependable().getAppID();

}

@Override
public Long createAttachment(InputStream is, String moduleType,
String moduleRecordSeq, String createUser, String fileName)
throws IOException, Exception
{

ensureSponsorIDVal();

String homeDir = GroupsConstants.getApplicationDependable()
.getAttachmentsDir(sponsorID);

String attachFileDir = moduleType + File.separator + moduleRecordSeq;

homeDir = homeDir + File.separator + attachFileDir;

File parentDir = new File(homeDir);

GroupsFileManager.createDir(parentDir.getAbsolutePath());

File uploadingFile = new File(parentDir, fileName);

FileOutputStream fos = null;

try
{

fos = new FileOutputStream(uploadingFile);

GroupsFileManager.write(is, fos);
}
catch (Exception ex)
{
throw ex;
}
finally
{
if (fos != null)
{
fos.close();
}
}



DocumentEntity ae = new DocumentEntity();

int dcid = GroupsUtils.generateUniqueId();

ae.setFileName(fileName);

String extension = "";

int i = fileName.lastIndexOf('.');
int p = Math.max(fileName.lastIndexOf('/'), fileName.lastIndexOf('\\'));

if (i > p)
{
extension = fileName.substring(i + 1);
}

String docid = ("FS" + dcid);

String documentId = ("FS" + dcid + "." + extension);

ae.setDocumentId(documentId);

String path = attachFileDir + File.separator + docid;

ae.setModuleRecordSeq(moduleRecordSeq);
ae.setModuleType("ITEM_ENTITY");

ae.setAppID(appID);

ae.setVersionNo(1);

ae.setFileSystem("FS");

ae.setPath(path);

// String sponsorSeq =
// nullToEmptyString(DocumentEntity.getSponsorSeq());

ae.setSponsorSeq(sponsorSeq);

ae.setCreateUser(createUser);
// Date createDate=now();
ae.setCreateDate(new Date());

Session s = getSessionHibernate();
s.save(ae);
s.flush();

return ae.getDocumentSeq();





}

private String ensureSponsorIDVal() throws SQLException
{
sponsorSeq = GroupsUtils.getLong(GroupsUtils.getSponsorSeq());

if (sponsorID == null)
sponsorID = GroupsUtils.getSponsorID(sponsorSeq + "",
getConnection());

return sponsorID;

}

@Override
public void createAttachment(File file, String moduleType,
String moduleRecordSeq, String createUser, String fileName)
throws IOException, Exception
{
InputStream is = null;

try
{
if (file != null)
is = new FileInputStream(file);

createAttachment(is, moduleType, moduleRecordSeq, createUser,
fileName);
}
catch (Exception ex)
{
ex.printStackTrace();
throw ex;
}
finally
{
if (is != null)
is.close();
}

}

@Override
public List<DocumentEntity> getAttachments(String moduleType,
String moduleRecordSeq) throws IOException, Exception
{
String query = " from DocumentEntity where moduleType='" + moduleType
+ "'and moduleRecordSeq='" + moduleRecordSeq
+ "'and sponsor_seq='" + sponsorSeq + "' ";
Query q = getSessionHibernate().createQuery(query);

List<DocumentEntity> documentEntityBeans = q.list();

return documentEntityBeans;
}

@Override
public AttachmentEntity getAttachmentEntity(Long docSeq)
{
return null;
}

@Override
public InputStream getAttachmentStream(long docSeq) throws IOException,
Exception
{

return null;
}

@Override
public List<AttachmentEntity> getAttachmentEntity(String moduleType,
String moduleSeq)
{

return null;
}

}

Controller :

    @Autowired
AttachmentService attachmentService;

@RequestMapping("/ItemDetailImageAdd.htm")
public ModelAndView itemDetailImageAdd(@RequestParam("file")
MultipartFile file, @RequestParam(value = "selectedId2", required = false)
String itemSeq) throws Exception
{

InputStream is = file.getInputStream();
String fileName = file.getOriginalFilename();

if (fileName.length() == 0)
{
// gce.add("error.importstudents.file.required");

throw new GroupsCustomeException(
"error.image.required");
}

struts 配置:

 <action path="/ItemDetailsSubmit"
type="com.groups.hms.items.action.ItemDetailsSubmitAction"
name="ItemForm"
scope="session"
validate="true"
input="/pages/items/ItemDetails.jsp">

<exception
key="error.general"
className="com.groups.GroupsExceptionConfig"
type="com.groups.GroupsCustomeException"
handler = "com.groups.GroupsExceptionHandler" />

<forward name="viewDetails" path="/ViewItemDetails.do"/>
</action>

最佳答案

您的<form>应包含 enctype="multipart/form-data"属性。您当前已在输入中设置了该设置:

<input type="file" name="file" id="file" enctype="multipart/form-data"/>

这是不正确的。如需引用,请参阅:

https://www.w3schools.com/tags/att_form_enctype.asp https://www.w3.org/TR/html5/forms.html#attr-fs-formenctype

关于mysql - org.springframework.web.multipart.MultipartException : Current request is not a multipart request,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44858079/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com