本文整理汇总了Java中javax.servlet.http.Part.getSubmittedFileName方法的典型用法代码示例。如果您正苦于以下问题:Java Part.getSubmittedFileName方法的具体用法?Java Part.getSubmittedFileName怎么用?Java Part.getSubmittedFileName使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.servlet.http.Part
的用法示例。
在下文中一共展示了Part.getSubmittedFileName方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: processRequest
import javax.servlet.http.Part; //导入方法依赖的package包/类
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
try (PrintWriter out = response.getWriter()) {
out.println("<!DOCTYPE html>");
out.println("<html>");
out.println("<head>");
out.println("<title>File Upload Servlet</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>File Upload Servlet</h1>");
out.println("Receiving the uploaded file ...<br>");
out.println("Received " + request.getParts().size() + " parts ...<br>");
String fileName = "";
for (Part part : request.getParts()) {
fileName = part.getSubmittedFileName();
out.println("... writing " + fileName + " part<br>");
part.write(fileName);
out.println("... written<br>");
}
out.println("... uploaded to: /tmp/" + fileName);
out.println("</body>");
out.println("</html>");
}
}
开发者ID:PacktPublishing,项目名称:Mastering-Java-EE-Development-with-WildFly,代码行数:26,代码来源:FileUploadServlet.java
示例2: fileBoundaryInfo_nullSubmittedFileName
import javax.servlet.http.Part; //导入方法依赖的package包/类
@Test
public void fileBoundaryInfo_nullSubmittedFileName(@Mocked Part part) {
new Expectations() {
{
part.getSubmittedFileName();
result = null;
part.getContentType();
result = "abc";
}
};
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
Buffer buffer = restClientRequest.fileBoundaryInfo("boundary", "name", part);
Assert.assertEquals("\r\n" +
"--boundary\r\n" +
"Content-Disposition: form-data; name=\"name\"; filename=\"null\"\r\n" +
"Content-Type: abc\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n", buffer.toString());
}
示例3: fileBoundaryInfo_validSubmittedFileName
import javax.servlet.http.Part; //导入方法依赖的package包/类
@Test
public void fileBoundaryInfo_validSubmittedFileName(@Mocked Part part) {
new Expectations() {
{
part.getSubmittedFileName();
result = "a.txt";
part.getContentType();
result = MediaType.TEXT_PLAIN;
}
};
RestClientRequestImpl restClientRequest = new RestClientRequestImpl(request, null, null);
Buffer buffer = restClientRequest.fileBoundaryInfo("boundary", "name", part);
Assert.assertEquals("\r\n" +
"--boundary\r\n" +
"Content-Disposition: form-data; name=\"name\"; filename=\"a.txt\"\r\n" +
"Content-Type: text/plain\r\n" +
"Content-Transfer-Encoding: binary\r\n" +
"\r\n", buffer.toString());
}
示例4: asForm
import javax.servlet.http.Part; //导入方法依赖的package包/类
@Override
public Form asForm() {
final MultivaluedMap<String, String> map = new MultivaluedHashMap<>();
for (final Part part : values.values()) {
if (part.getSubmittedFileName() != null) {
continue;
}
try {
map.add(part.getName(), IOUtils.toString(part.getInputStream(), StandardCharsets.UTF_8));
} catch (final IOException ex) {
LOG.error(ex.getMessage(), ex);
}
}
return new Form(map);
}
示例5: doPost
import javax.servlet.http.Part; //导入方法依赖的package包/类
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// InputStream in = req.getInputStream();
PrintWriter out = resp.getWriter();
String operationStr = null;
req.setCharacterEncoding("UTF-8");
Part part = req.getPart("file");
OperationBean operationBean = new OperationBean();
if (part != null) {
String fileName = part.getSubmittedFileName();
if (fileName.length() > 0) {
part.write(fileName);
File file = new File(System.getProperty("user.dir") + JettyConfig.UPLOAD_TMP_PATH);
if (file.exists()) {
logger.info("上传成功");
operationBean.setCode(200);
operationBean.setMsg(fileName);
} else {
logger.info("上传失败");
operationBean.setCode(400);
operationBean.setMsg("");
}
}else {
SystemWSSender.error("请先浏览到您要安装的app安装包。");
}
}
operationStr = JsonUtil.beanToJson(operationBean);
logger.info(operationStr);
out.println(operationStr);
out.flush();
out.close();
}
示例6: attachFile
import javax.servlet.http.Part; //导入方法依赖的package包/类
private void attachFile(String boundary, Iterator<Entry<String, Part>> uploadsIterator) {
if (!uploadsIterator.hasNext()) {
request.write(boundaryEndInfo(boundary));
request.end();
return;
}
Entry<String, Part> entry = uploadsIterator.next();
// do not use part.getName() to get parameter name
// because pojo consumer not easy to set name to part
String name = entry.getKey();
Part part = entry.getValue();
String filename = part.getSubmittedFileName();
InputStreamToReadStream fileStream = null;
try {
fileStream = new InputStreamToReadStream(vertx, part.getInputStream());
} catch (IOException e) {
asyncResp.consumerFail(e);
return;
}
InputStreamToReadStream finalFileStream = fileStream;
fileStream.exceptionHandler(e -> {
LOGGER.debug("Failed to sending file [{}:{}].", name, filename, e);
IOUtils.closeQuietly(finalFileStream.getInputStream());
asyncResp.consumerFail(e);
});
fileStream.endHandler(V -> {
LOGGER.debug("finish sending file [{}:{}].", name, filename);
IOUtils.closeQuietly(finalFileStream.getInputStream());
attachFile(boundary, uploadsIterator);
});
Buffer fileHeader = fileBoundaryInfo(boundary, name, part);
request.write(fileHeader);
Pump.pump(fileStream, request).start();
}
示例7: getMultipartPart
import javax.servlet.http.Part; //导入方法依赖的package包/类
@POST
@Path("/multipart-part")
@Consumes(MediaType.MULTIPART_FORM_DATA)
public static String getMultipartPart(
@FormParam("content") final Part content)
throws IOException {
return content.getSubmittedFileName();
}