0
我想让我的JSF网站上传图片到服务器,但我有一个时间。我发现了4种方法,但我想使用h:InputFile,因为它似乎是最直接的。上传JSF文件(需要正确的文件路径)
看来我只是需要正确提供上传路径。
添加@MultipartConfig后,我不再收到异常,但无法验证文件是否已上传或看到任何错误。
public void AddPicture()
{
ConnInfo HitIt = new ConnInfo();
try
{
HitIt.save(fileCelebrityToAdd);
}
catch(Exception ex)
{
//?
}
}
@MultipartConfig(location="C:\\local\\pathway\\Netbeans\\project\\web\\Pictures\\items\\")
public class ConnInfo
{
private String uploadLocation;
public ConnInfo()
{
//uploadLocation = ".\\Pictures\\items\\";
uploadLocation = "C:\\local\\pathway\\Netbeans\\project\\web\\Pictures\\items\\";
}
public boolean TryOut(Part file) throws IOException
{
String monkey = uploadLocation+getFilename(file);
try
{
file.write(monkey);
}
catch(Exception ex)
{
return false;
}
return true;
}
}
希望我已经正确地复制了必要的信息。
请仔细阅读本主题:http://stackoverflow.com/questions/27677397/how-to-upload-file-using-jsf-2-2-hinputfile-where-is-the-saved-file –
谢谢谭,这是其中之一我发现的很多文章。事实证明,我嵌套的表单问题是干扰这一点,我会相应地更新问题,但现在(看起来)它只是提供一个正确的文件路径的问题。 – Kamurai
不客气:) –