你好,我正在制作员工目录。在那种形式中,我想上传员工的照片,当我尝试存储图像时, 如果我删除图像上传的逻辑,然后我的其他数据成功存储在数据库中,则会出现类似Portlet 暂时不可用的错误。请帮助我如何将图像路径存储在数据库中。我在/webapps创建了图像 文件夹。我想将我的所有图像存储在这个文件夹中,并将我的图像路径存储到数据库中。请告诉我如何存储图像路径以及存储图像路径后如何在其他页面中显示图像。
在这里,我给你我的 java 代码,我在其中编写了我的逻辑。包 com.dir;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import javax.portlet.ActionRequest;
import javax.portlet.ActionResponse;
import javax.portlet.PortletException;
import com.liferay.portal.kernel.exception.SystemException;
import com.dir.model.directory;
import com.dir.model.impl.directoryImpl;
import com.dir.service.directoryLocalServiceUtil;
import com.liferay.counter.service.CounterLocalServiceUtil;
import com.liferay.portal.kernel.upload.UploadPortletRequest;
import com.liferay.portal.kernel.util.FileUtil;
import com.liferay.portal.kernel.util.ParamUtil;
import com.liferay.portal.util.PortalUtil;
import com.liferay.util.bridges.mvc.MVCPortlet;
public class Directory extends MVCPortlet {
public void updatedir(ActionRequest actionRequest,ActionResponse
actionResponse)throws IOException, PortletException
{
String empname =ParamUtil.getString(actionRequest,"empname");
String designation =ParamUtil.getString(actionRequest,"designation");
String qualification =ParamUtil.getString(actionRequest,"qualification");
String email =ParamUtil.getString(actionRequest,"email");
String photo=ParamUtil.getString(actionRequest,"photo");
String company =ParamUtil.getString(actionRequest,"company");
int experiance=ParamUtil.getInteger(actionRequest,"experiance");
directory d1 = new directoryImpl();
// set primary key
long directoryId=0L;
try
{
directoryId=CounterLocalServiceUtil.increment(this.getClass().getName());
}
catch (SystemException ex)
{
ex.printStackTrace();
}
d1.setDirectoryId(directoryId);
// set UI fields
d1.setEmpname(empname);
d1.setDesignation(designation);
d1.setQualification(qualification);
d1.setEmail(email);
d1.setPhoto(photo);
d1.setCompany(company);
d1.setExperiance(experiance);
File file;
UploadPortletRequestupreq=PortalUtil.getUploadPortletRequest(actionRequest);
file=upreq.getFile(photo);
Stringpath=actionRequest.getPortletSession().getPortletContext().getRealPath(photo)
+ "//" + ("/images");
File fileone= new File(path);
FileUtil.copyDirectory(file,fileone);
// set audit field(s)
d1.setDateAdded(new Date());
// insert the book using persistence api
try {
directoryLocalServiceUtil.adddirectory(d1);
} catch (SystemException e) {
e.printStackTrace();
}
}
}
在这里,我从我上传照片的地方给你我的 Jsp 文件。
<aui:form name="fm" method="POST" action="<%= updatedirURL.toString() %>"
enctype="multipart/form-data">
<aui:input name="empname" label="Name"/>
<aui:input name="designation" label="Designation"/>
<aui:input name="qualification" label="Qualification"/>
<aui:input name="email" label="Email"/>
<aui:input type="file" label="Photo" name="photo"/>
<aui:input name="company" label="Company"/>
<aui:input name="experiance" label="Experiance"/>
<aui:button type="submit" value="Save"/>
</aui:form>
请帮助我哪里错了,哪些东西缺少它的要求。并告诉我如何显示该文件夹中的数据。