使用Struts2和EJB将映像存储到数据库中

时间:2016-04-18 02:32:50

标签: database image struts2 ejb

我必须使用EJB通过Struts2将我的图像存储到数据库Oracle中。它会保留数据,但是当我将输入文件添加到JSP时,我在这一行上有NullPointerException:

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;
}
}

2 个答案:

答案 0 :(得分: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>

答案 1 :(得分:0)

我的Xml

cat_id