画像ファイルをPartで受け取ってそれをbyte[]に変換してデータベースに格納したいと考えています。しかし下記のコードではgoToConfirm()を実行した時にNullPointerExceptionが出てしまいます。どうすれば良いでしょうか。回答の方よろしくお願いいたします。
Java
1 2 3 private Part file; 4 5private byte[] image; 6 7 8 public static byte[] toByteArray(Part file) throws IOException { 9 final ByteArrayOutputStream output = new ByteArrayOutputStream(); 10 copy((InputStream) file, output); 11 return output.toByteArray(); 12 13 } 14 15 public void imageToByte() throws IOException { 16 image = toByteArray(file); 17 18 } 19 public String goToConfirm() throws IOException { 20 toByteArray(this.file); 21 return "/confirm.xhtml?faces-redirect=true"; 22 23 24//getter and setter
xhtml
1<h:form enctype="multipart/form-data"> 2 <div align="center"><h:inputFile id="file" value="#{bb.file}" label="写真を選択"/></div><br /> 3</h:form>
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2016/12/13 06:12
2016/12/13 06:26
2016/12/13 07:56
2016/12/13 08:07
2016/12/13 08:11
2016/12/13 11:09