我正在使用JSP将blob文件从HTML表单上传到数据库.我需要将文件名插入DB.我知道文件名存储在Content-Disposition标题中,我怎么能得到它?
我正在使用JSF <h:inputFile>
将图像上传到服务器.
<h:form enctype="multipart/form-data">
<h:inputFile value="#{fileHandlerBean.file}"/>
<h:commandButton action="#{fileHandlerBean.uploadImage()}"/>
</h:form>
Run Code Online (Sandbox Code Playgroud)
我创建了一个虚拟主机/projectname/webapp/images
.我可以成功地将文件创建到该文件夹中.
private Part file;
public String uploadImage(){
InputStream is = null;
try {
String extension = FilenameUtils.getExtension(file.getSubmittedFileName());
File tempFile = File.createTempFile("picture-", "."+extension, new File("/projectname/webapp/images"));
Logger.getLogger("FILE SIZE").warning(String.valueOf(file.getSize()));
Logger.getLogger("FILE EXTENSION").warning(extension);
is = file.getInputStream();
Logger.getLogger("STREAM AVAILABLE SIZE").warning(String.valueOf(is.available()));
Files.copy(is, tempFile.toPath());
} catch (IOException ex) {
Logger.getLogger(FileHandlerBean.class.getName()).log(Level.SEVERE, null, ex);
} finally {
if( is!= null){
try {
is.close();
} catch (IOException ex) {
Logger.getLogger(FileHandlerBean.class.getName()).log(Level.SEVERE, null, ex);
}
}
}
return "success";
}
Run Code Online (Sandbox Code Playgroud)
但是所有这些都是空的,我 …
所以我做了一些用于发送消息的输入块,它在Chrome和Safari中工作正常,但Firefox用灰色边框显示它.在IE中也存在一个问题,因为它会让它们变大,直到你激活它,然后它会回到正常大小.
<form action="" method="post">
<label for="name">
<input class="input1" type="text" placeholder="Your name" name="name" id="name"/>
</label>
<label for="E-mail">
<input class="input1" type="text" placeholder="Your e-mail" id="email"/>
</label>
<label for="Subject">
<input class="input1" type="text" placeholder="Subject" id="subject" />
</label>
<label for="Message">
<textarea class="input2" name="message" rows="20" cols="20" id="message" placeholder="Message"></textarea>
</label>
<label>
</form>
Run Code Online (Sandbox Code Playgroud)
CSS:
input {
-moz-border-color: #0d1025;
-moz-border-width:medium;
border-color: #0d1025;
border-width:medium;
margin-top: 15px;
}
.input1 {
width:300px;
height:30px;
display:block;
}
.input2 {
width:650px;
height:270px;
margin-left:320px;
margin-top:-143px;
border-color: #0d1025;
border-width:medium;
}
::-webkit-input-placeholder {
color: #0d1025;
font-style:italic;
padding-left:15px;
font-weight:bold;
} …
Run Code Online (Sandbox Code Playgroud)