在 XPages 的 Java bean 中接收文件
Receive files in Java bean in XPages
我正在创建可以接收文件并将其附加到文档的服务。
我已经创建了 HTML 用于提交文件的表单(示例如下)。
测试表格
<html>
<body>
<h1>Test-form to upload files (v.1.0.0) </h1>
<form action="/file.xsp/upload" method="post" enctype="multipart/form-data">
<p>
Select a file : <input type="file" name="file" size="50" />
</p>
<input type="submit" value="Upload It" />
</form>
</body>
</html>
表单提交后 Java bean 被触发,下面是示例。
JAVA豆子
public class TestFile extends CustomServiceBean {
@Override
public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {
print ("START: Uploading of file...");
HttpServletResponse res = engine.getHttpResponse();
HttpServletRequest req = engine.getHttpRequest();
...
但是我不知道如何将 InputStream 初始化为提交给服务的文件。任何人都可以建议(或示例)如何做到这一点吗?
谢谢!
我不确定它是否适用于将文件提交给 bean,但我使用了类似于以下代码的内容来验证上传的文件属性,如大小。
在我的例子中,POST 是由 XPage 制作的,这可能不是你的情况,所以它可能不适用。
HttpServletRequest request= engine.getHttpRequest();
@SuppressWarnings("unchecked")
Map<String,Object> params=request.getParameterMap();
for (Entry<String, Object> tmpEntry : params.entrySet()) {
if (tmpEntry.getValue() instanceof UploadedFile) {
UploadedFile myFile=(UploadedFile)tmpEntry.getValue();
//Do something with the file
}
}
我正在创建可以接收文件并将其附加到文档的服务。
我已经创建了 HTML 用于提交文件的表单(示例如下)。
测试表格
<html>
<body>
<h1>Test-form to upload files (v.1.0.0) </h1>
<form action="/file.xsp/upload" method="post" enctype="multipart/form-data">
<p>
Select a file : <input type="file" name="file" size="50" />
</p>
<input type="submit" value="Upload It" />
</form>
</body>
</html>
表单提交后 Java bean 被触发,下面是示例。
JAVA豆子
public class TestFile extends CustomServiceBean {
@Override
public void renderService(CustomService service, RestServiceEngine engine) throws ServiceException {
print ("START: Uploading of file...");
HttpServletResponse res = engine.getHttpResponse();
HttpServletRequest req = engine.getHttpRequest();
...
但是我不知道如何将 InputStream 初始化为提交给服务的文件。任何人都可以建议(或示例)如何做到这一点吗?
谢谢!
我不确定它是否适用于将文件提交给 bean,但我使用了类似于以下代码的内容来验证上传的文件属性,如大小。
在我的例子中,POST 是由 XPage 制作的,这可能不是你的情况,所以它可能不适用。
HttpServletRequest request= engine.getHttpRequest();
@SuppressWarnings("unchecked")
Map<String,Object> params=request.getParameterMap();
for (Entry<String, Object> tmpEntry : params.entrySet()) {
if (tmpEntry.getValue() instanceof UploadedFile) {
UploadedFile myFile=(UploadedFile)tmpEntry.getValue();
//Do something with the file
}
}