2016-04-18 36 views
-1

我不得不通過Struts2的使用EJB到我的圖像存儲到數據庫的Oracle。它堅持的數據,但是當我添加輸入文件JSP我的NullPointerException在這條線:專賣店形象到數據庫中使用的Struts2和EJB

byte[] buffer=new byte[(int)this.telethoraxImg.length()]; 

下面是我的一些代碼部分:

PictureAction.java

public class PictureAction extends ActionSupport implements SessionAware{ 
private static final long serialVersionUID = 1L; 
private static final Logger log = Logger.getLogger(MorphoRECAction.class); 
private Map session ; 
private ExamMorpho exMoR; 
private Patient pat; 
private HttpServletRequest request; 

public void setServletRequest(HttpServletRequest request) { 
    this.request=request; 
} 
public ExamMorpho getExam(){ 
    return exMoR; 
} 
public void setExam(ExamMorpho exMoR){ 
    this.exMoR = exMoR; 
} 

public Patient getPat(){ 
    return pat; 
} 
public void setPat(Patient pat){ 
    this.pat = pat; 
} 


private Date dateExMorpho; 
private String echoAbdo; 
private String echoCard; 
private String exGyneco; 
private String exOphtalmo; 
private String mamo; 
private String telethoraxTxt; 
private File telethoraxImg; 


public String execute(){ 
    log.info("Entrée dans la méthode execute() "); 

    System.out.println("creation examen"); 
    ExamMorpho ex = new ExamMorpho(); 

    System.out.println("fin création"); 


    try{ 
     Patient pt = (Patient)session.get("lepat"); 
     InitialContext initialContext = new InitialContext(); 
     ExMorphoRemote facade = (ExMorphoRemote) initialContext.lookup("PatProjet/ExMorphoBean/remote"); 
     System.out.println("ID Patient RECUPERE /" + pt.getIdPat()); 

     System.out.println("Debut conversion image"); 
      byte[] buffer=new byte[(int)this.telethoraxImg.length()]; 
      /*exMoR = new ExamMorpho(buffer, dateExMorpho, echoAbdo, echoCard, exGyneco, exOphtalmo, mamo, telethoraxTxt); */ 
      System.out.println("Fin conversion image"); 

     FileInputStream in=new FileInputStream(this.telethoraxImg); 
     in.read(buffer); 

     ex.setTelethoraxImg(buffer); 
     ex.setDateExMorpho(dateExMorpho); 
     ex.setEchoAbdo(echoAbdo); 
     ex.setEchoCard(echoCard); 
     ex.setExGyneco(exGyneco); 
     ex.setExOphtalmo(exOphtalmo); 
     ex.setMamo(mamo); 
     ex.setTelethoraxTxt(telethoraxTxt); 


     System.out.println("FIN AJOUT IMAAAGE"); 
      exMoR = facade.AddExMorphoR(ex, pt); 
      System.out.println("FIN AJOUT MORPHOOS"); 
    } catch(Exception e) { 
     e.printStackTrace(); 
    } 


    return SUCCESS; 
} 

/*private byte[] telethoraxImg = null; 
public byte[] getTelethoraxImg() { 
    return this.telethoraxImg; 
} 
public void setTelethoraxImg(byte[] telethoraxImg) { 
    System.out.println("ENTREE ADD IMAGE"); 
    this.telethoraxImg = telethoraxImg; 
    System.out.println("SORTIE ADD IMAGE"); 
}*/ 

/*private Date dateExMorpho = null; 
public Date getDateExMorpho() { 
    return this.dateExMorpho; 
} 
public void setDateExMorpho(Date dateExMorpho) { 
    this.dateExMorpho = dateExMorpho; 
} 

private String echoAbdo = null; 
public String getEchoAbdo() { 
    return this.echoAbdo; 
} 
public void setEchoAbdo(String echoAbdo) { 
    this.echoAbdo = echoAbdo; 
} 

private String echoCard = null; 
public String getEchoCard() { 
    return this.echoCard; 
} 
public void setEchoCard(String echoCard) { 
    this.echoCard = echoCard; 
} 

private String exGyneco = null; 
public String getExGyneco() { 
    return this.exGyneco; 
} 
public void setExGyneco(String exGyneco) { 
    this.exGyneco = exGyneco; 
} 

private String exOphtalmo = null; 
public String getExOphtalmo() { 
    return this.exOphtalmo; 
} 
public void setExOphtalmo(String exOphtalmo) { 
    this.exOphtalmo = exOphtalmo; 
} 

private String mamo = null; 
public String getMamo() { 
    return this.mamo; 
} 
public void setMamo(String mamo) { 
    this.mamo = mamo; 
} 

private String telethoraxTxt = null; 
public String getTelethoraxTxt() { 
    return this.telethoraxTxt; 
} 
public void setTelethoraxTxt(String telethoraxTxt) { 
    this.telethoraxTxt = telethoraxTxt; 
} 
*/ 

public void setSession(Map session) { 
    this.session = session; 
} 

public Map getSession() { 
    return session; 
} 
} 
+0

向我們展示了JSP代碼... – goodyzain

+0

註釋掉的getter/setter方法'telethoraxImg'。 –

+0

我會嘗試感謝你希望它會工作 – Sissi

回答

0

JSP代碼

<form action="fileUpload" method="POST" enctype ="multipart/form-data"><table> 
<thead> 
    <tr> 
     <th colspan="2"></th> 
     <th colspan="2" rowspan="3"><center><input type="text" name="dateExMorpho" id="dn"/></a></center></th> 

    </tr> 
</thead> 
<tbody> 

    <tr> 

    </tr>  
     <tr><td colspan="2">Echographie Abdominale</td><td><textarea name="echoAbdo" rows=4 COLS=40></textarea></td></tr> 
     <tr><td colspan="2">Ecographie Cardiaque</td><td><textarea name="echoCard" rows=4 COLS=40></textarea></td></tr> 
     <tr><td colspan="2">Examen Gynécologique</td><td><textarea name="exGyneco" rows=4 COLS=40></textarea></td></tr> 
     <tr><td colspan="2">Examen Ophtalmoloique</td><td><textarea name="exOphtalmo" rows=4 COLS=40></textarea></td></tr> 
     <tr><td colspan="2">Mamographie</td><td><textarea name="mamo" rows=4 COLS=40></textarea></td></tr> 
     <tr> 
     <td ROWSPAN="2">T&eacute;l&eacute;thorax</td> 
     <td >Image</td> 
     <td><s:file name="telethoraxImg" ContentEditable="false" style="float:left;"/></td> 
     </tr> 

     <tr> 
     <td>Remarques</td> 
     <td><textarea name="telethoraxTxt" rows=4 COLS=40></textarea></td> 
     </tr> 
</tbody> 

0

我的XML

<action name="fileUpload" class="clientStruts2.PictureAction"> 
    <interceptor-ref name="fileUpload"> 
     <param name="allowedTypes"> 
     image/pjpeg,image/png,image/gif,image/jpeg,image/jpg,image/pjpeg</param> 
     <param name="maximumSize">2097152</param></interceptor-ref> 
    <interceptor-ref name="basicStack"/> 
    <result name="input">/login/dossierRec.jsp</result> 
    <result name="error">/login/dossierRec.jsp</result> 
    <result name="success">/login/dossierRec.jsp</result> 
</action> 
+0

Pleaaase傢伙,我只是看到療法是沒有更多的錯誤,但場均在DB空 – Sissi