本文整理匯總了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();
}