java - NullPointerException exception on file uploading in struts2 -


i working on struts2 application have upload file , save database. each time showing nullpointerexception code here

stack trace is-

java.lang.nullpointerexception     dao.clientdao.registration(clientdao.java:31)     action.client.clientaction.execute(clientaction.java:18)     sun.reflect.nativemethodaccessorimpl.invoke0(native method)     sun.reflect.nativemethodaccessorimpl.invoke(unknown source)     sun.reflect.delegatingmethodaccessorimpl.invoke(unknown source)     java.lang.reflect.method.invoke(unknown source)     com.opensymphony.xwork2.defaultactioninvocation.invokeaction(defaultactioninvocation.java:452)     com.opensymphony.xwork2.defaultactioninvocation.invokeactiononly(defaultactioninvocation.java:291)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:254)     com.opensymphony.xwork2.interceptor.defaultworkflowinterceptor.dointercept(defaultworkflowinterceptor.java:176)     com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:248)     com.opensymphony.xwork2.validator.validationinterceptor.dointercept(validationinterceptor.java:263)     org.apache.struts2.interceptor.validation.annotationvalidationinterceptor.dointercept(annotationvalidationinterceptor.java:68)     com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:248)     com.opensymphony.xwork2.interceptor.parametersinterceptor.dointercept(parametersinterceptor.java:207)     com.opensymphony.xwork2.interceptor.methodfilterinterceptor.intercept(methodfilterinterceptor.java:98)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:248)     org.apache.struts2.interceptor.fileuploadinterceptor.intercept(fileuploadinterceptor.java:314)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:248)     com.opensymphony.xwork2.interceptor.i18ninterceptor.intercept(i18ninterceptor.java:176)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:248)     com.opensymphony.xwork2.interceptor.exceptionmappinginterceptor.intercept(exceptionmappinginterceptor.java:187)     com.opensymphony.xwork2.defaultactioninvocation.invoke(defaultactioninvocation.java:248)     org.apache.struts2.impl.strutsactionproxy.execute(strutsactionproxy.java:52)     org.apache.struts2.dispatcher.dispatcher.serviceaction(dispatcher.java:485)     org.apache.struts2.dispatcher.ng.executeoperations.executeaction(executeoperations.java:77)     org.apache.struts2.dispatcher.ng.filter.strutsprepareandexecutefilter.dofilter(strutsprepareandexecutefilter.java:91) 

model class is

import java.io.file; public class clientmodel { private string aggrement; private string  date; private string rate; private string maturitydate; private string detail; private string taxno; private file imagefile; public file getimagefile() {     return imagefile; }  public void setimagefile(file imagefile) {     this.imagefile = imagefile; }  public string getrate() {     return rate; }  public void setrate(string rate) {     this.rate = rate; }  public string getdetail() {     return detail; }  public void setdetail(string detail) {     this.detail = detail; }  public string gettaxno() {     return taxno; }  public void settaxno(string taxno) {     this.taxno = taxno; }  public string getaggrement() {     return aggrement; }  public void setaggrement(string aggrement) {     aggrement = aggrement; }    public string getmaturitydate() {     return maturitydate; }  public void setmaturitydate(string maturitydate) {     this.maturitydate = maturitydate; }  public string getdate() {     return date; }  public void setdate(string date) {     this.date = date; }  } 

struts.xml

  <?xml version="1.0" encoding="utf-8" ?> <!doctype struts public     "-//apache software foundation//dtd struts configuration 2.3//en"     "http://struts.apache.org/dtds/struts-2.3.dtd"> <struts>        <constant name="struts.enable.dynamicmethodinvocation" value="true"/>              <constant name="struts.devmode" value="true"/>              <package name="loginmodel" extends ="struts-default">          <action name="clientlogin"  class="action.client.clientaction" >            <interceptor-ref name="exception"/>             <interceptor-ref name="i18n"/>             <interceptor-ref name="fileupload">             <param name="allowedtypes">text/plain</param>             <param name="maximumsize">10240</param>         </interceptor-ref>              <interceptor-ref name="params">                 <param name="excludeparams">dojo\..*,^struts\..*</param>             </interceptor-ref>             <interceptor-ref name="validation">                 <param name="excludemethods">input,back,cancel,browse</param>             </interceptor-ref>             <interceptor-ref name="workflow">                 <param name="excludemethods">input,back,cancel,browse</param>             </interceptor-ref>              <result name="input">/registration/clientregistration.jsp </result>            <result name ="success">/registration/success.jsp  </result>            </action>           </package> </struts> 

clientregistration.jsp

<%@ page language ="java" contenttype ="text/html; charset=iso-8859-1" pageencoding ="iso-8859-1"%> <%@ taglib uri ="/struts-tags" prefix="s"%> <%@ taglib uri ="/struts-dojo-tags" prefix="sx" %> <%@ taglib prefix="sj" uri="/struts-jquery-tags"%> <html> <head> <sj:head jqueryui="true" jquerytheme="redmond" /> <style>    div.ui-datepicker {       font-size: 82.5%;        } </style> <meta http-equiv="content-type" content="text/html; charset=iso-8859-1"> <title>client</title> <link rel="stylesheet" type="text/css" href="css/emp.css"> </head> <body >  <div id ="did" align="center"> <h1 style="color: red">  client registration form</h1>   <s:form action ="clientlogin" method="post" enctype="multipart/form-data">  <s:select  name="aggrement" label ="type of aggrement" list ="{'oral', 'written'}  "/> <sj:datepicker  name="date" label="aggrement date" changemonth="true" changeyear="true"/>   <s:select name ="rate" list="{'1','2','3'}" label ="aggrement rate"/> <s:textarea  name ="detail" label ="aggrement detail"></s:textarea>  <s:textfield name ="taxno" label="tax no "></s:textfield>  <s:file name ="imagefile" label ="upload document"  /> <tr><td>&nbsp;</td></tr>         <tr>     <td>&nbsp;</td>   <s:submit align="center"></s:submit> </s:form>    </div>   </body> </html> 

client dao is

package dao;  import java.sql.blob; import java.sql.sqlexception; import model.clientmodel; import com.mysql.jdbc.preparedstatement; import com.mysql.jdbc.resultset;  public class clientdao {  java.sql.connection connection =null;    preparedstatement pst = null;    resultset rs =null;  private java.sql.connection getconnection() throws sqlexception{     java.sql.connection conn; conn = connectionfactory.getinstance().getconntection();     return conn;  }  public int registration(clientmodel model){      int i= 0;    try{       string str  = "insert " + "clientdata(aggrement,aggrementdate,rate,maturitydate,detail,taxno,image)"+                      "values(?,?,?,?,?,?)";         connection =getconnection();        pst =(preparedstatement) connection.preparestatement(str);      pst.setstring(1, model.getaggrement());      pst.setstring(2, model.getdate());      pst.setstring(3, model.getrate());      pst.setstring(4, model.getmaturitydate());      pst.setstring(5, model.getdetail());      pst.setstring(6, model.gettaxno());      pst.setblob(7,(blob) model.getimagefile());           = pst.executeupdate();      system.out.println("result " +i);    }   catch (sqlexception se){     se.printstacktrace();      }    return i;  } } 

implement modeldriven interface , return object of overridden method model class in action class .


Comments

Popular posts from this blog

Why does Ruby on Rails generate add a blank line to the end of a file? -

keyboard - Smiles and long press feature in Android -

node.js - Bad Request - node js ajax post -