我必须将文件及其属性发送到 GWT 服务器。
为了发送文件,我使用了表单面板。
public class BrowseFile extends DialogBox {
// more code
// ..
private FormPanel getFormPanel() {
if (formPanel == null) {
formPanel = new FormPanel();
formPanel.setMethod(FormPanel.METHOD_POST);
formPanel.setEncoding(FormPanel.ENCODING_MULTIPART);
formPanel.setAction(GWT.getHostPageBaseURL() +"UploadFileServlet");
formPanel.addSubmitHandler(new FormPanel.SubmitHandler(){
public void onSubmit(SubmitEvent event) {
// TODO Auto-generated method stub
setFilename(fileUpload.getFilename());
}
});
}
return formPanel;
}
}
该文件的所有属性都在 Hashmap 中
有2个对话框Propertybox extends DialogBox
和
BrowseFile extends DialogBox
在 PropertyBox 的构造函数里面有 BrowseFile
当 PropertyBox 构造函数
setSize("600px", "670px");
setHTML("Add Document");
setWidget(getVerticalPanel());
browseFile = new BrowseFile();
PropertyBox里面的自定义Property依赖于选择的类(Class是tree Widget)
在服务器端
public class FileUpload extends HttpServlet implements Servlet{
private static final long serialVersionUID = 1L;
private static final Logger log = Logger.getLogger(FileUpload.class
.getName());
protected void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException, IOException {
byte[] buffer = new byte[115200];//
String fileName = null;
String mimetype = null;
String majorVersion = null;
InputStream stream = null;
try {
ServletFileUpload upload = new ServletFileUpload();
FileItemIterator iterator = upload.getItemIterator(request);
while (iterator.hasNext()) {
FileItemStream item = iterator.next();
stream = item.openStream();
if (item.isFormField()) {
//
} else {
fileName = item.getName();
mimetype = item.getContentType();
//
}
}
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
ByteArrayOutputStream output = new ByteArrayOutputStream();
int len;
while ((len = stream.read(buffer, 0, buffer.length)) != -1) {
output.write(buffer, 0, len);
}
ByteArrayInputStream input = new ByteArrayInputStream(output.toByteArray());
Session session =RootFolder.getSession();
ContentStream contentStream = session.getObjectFactory()
.createContentStream(fileName, output.size(), mimetype, input);
}
为了在外部存储库中创建文档,我需要 hasmap 中的文档属性
folder.createDocument(文档属性,contentStream,VersioningState.MAJOR);
Document 属性应在Document 属性 Class 的onClick
事件中发送到此类Button ADD
*****如何在 FileUpload 类中将此文档属性发送到服务器 *****