将图像上传到数据库

时间:2014-05-22 06:47:22

标签: spring jsf-2 primefaces oracle10g

我正在尝试将图像上传到数据库表中。我得到这个nullpointer异常。 javax.faces.component._MethodExpressionToMethodBinding.invoke(_MethodExpressionToMethodBindin g.java:96)

my profile.xhtml

<h:form enctype="multipart/form-data" >
 <p:panelGrid columns="1">
  <p:outputLabel for="firstname" value="first"> 
    <p:inputText id="firstname" value="#{profile.firstName}"></p:inputText>
  </p:outputLabel>

 <p:outputLabel for="lastname" value="last">
      <p:inputText id="lastname" value="#{profile.lastName}"></p:inputText>
 </p:outputLabel>

 <p:outputLabel for="ContactNumber" value="ContactNumber">
   <p:inputText id="ContactNumber" value="#{profile.contactNumber}"></p:inputText>
 </p:outputLabel>

 <p:outputLabel for="photo" value="ProfilePhoto">
    <p:fileUpload id="photo" value="#{profile.photo1}" mode="simple" 
        dragDropSupport="false"
         sizeLimit="100000" allowTypes="/(\.|\/)(gif|jpe?g|png)$/">
    </p:fileUpload>
 </p:outputLabel> 

 <p:outputLabel for="mailId" value="Email">
        <p:inputText id="mailId" value="#{profile.email}"></p:inputText> 
 </p:outputLabel> 

 <p:outputLabel for="SelfDesc" value="AboutMe??" >
         <p:inputTextarea id="SelfDesc" value="#{profile.description}">  
            </p:inputTextarea>
 </p:outputLabel> 


 </p:panelGrid>
 <p:panelGrid columns="1">

<p:commandButton value="submit" action="#{profile.insertProfile}">
    </p:commandButton>
 </p:panelGrid>
 </h:form>

my profile.java

@ManagedBean(name="profile",eager=true)
@SessionScoped
public class Profile {

 @ManagedProperty("#{jdbcTemplate}")
    public JdbcTemplate jdbcTemplate;
            private String firstName,lastName,email,description;
            private UploadedFile photo1;
            private String insertQry;
            private int contactNumber;
     public JdbcTemplate getJdbcTemplate() {
    return jdbcTemplate;
     }

     public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
    this.jdbcTemplate = jdbcTemplate;
     }
         public UploadedFile getPhoto1() {
        return photo1;
         }

         public void setPhoto1(UploadedFile photo1) {
            this.photo1 = photo1;
         }

         public String getEmail() {
        return email;
         }

         public void setEmail(String email) {
         this.email = email;
         }

         public String getDescription() {
         return description;
         }

         public void setDescription(String description) {
         this.description = description;
         }

         public String getFirstName() {
         return firstName;
        } 

         public void setFirstName(String firstName) {
         this.firstName = firstName;
        }

        public String getLastName() {
         return lastName;
        }

       public void setLastName(String lastName) {
         this.lastName = lastName;
       }

       public int getContactNumber() {
         return contactNumber;
       }

       public void setContactNumber(int contactNumber) {
        this.contactNumber = contactNumber;
       }

       public void insertProfile() throws Exception{

       InputStream is=photo1.getInputstream();
       System.out.println(is);
       insertQry="insert into profile 
           values('"+getFirstName()+"','"+getLastName()+"','"+getContactNumber()+"',
            '"+getEmail()+"','"+getDescription()+"','"+is+"')";

           System.out.println(insertQry);



      int num=jdbcTemplate.update(insertQry);
      System.out.println(num);




   }

我正在使用jdbctemplate spring3.0和commons-fileupload一个commons-io也在类路径中 我的lib列在这里

com.springsource.org.apache.commons.logging-1.1.1.jar
com.springsource.org.apache.log4j-1.2.15.jar
commons-beanutils-1.8.3.jar 
commons-codec-1.3.jar
commons-collections-3.2.jar
commons-digester-1.8.jar
commons-fileupload-1.3.1.jar
commons-io-2.4.jar
commons-lang3-3.1.jar
commons-logging-1.1.1.jar
javaee.jar
jstl-1.2.jar
myfaces-api-2.1.0.jar
myfaces-impl-2.1.0.jar
ojdbc7.jar
org.springframework.asm-3.0.1.RELEASE-A.jar
org.springframework.beans-3.0.1.RELEASE-A.jar 
org.springframework.context-3.0.1.RELEASE-A.jar
org.springframework.core-3.0.1.RELEASE-A.jar
org.springframework.expression-3.0.1.RELEASE-A.jar
org.springframework.transaction-3.0.0.RELEASE.jar
primefaces-3.4-sources.jar
primefaces-3.4.jar
spring-2.5.jar
spring-jdbc.jar
spring-webmvc-3.0.0.RELEASE.jar

我正在使用primefaces3.4,jsf2.1,spring3.0。任何人都可以帮助我摆脱它。真诚地感谢你的回应。

0 个答案:

没有答案