unable to get file name in struts2 file upload -


i new struts2. unable file name , path. kindly one.

import java.io.file; import java.util.resourcebundle;  import org.apache.commons.io.fileutils;  import nre.dao.dbconnection;  import com.mysql.jdbc.connection; import com.opensymphony.xwork2.actionsupport;   public class addproperty extends actionsupport {  private string propertyid; private string propertyname; private string country; private string state; private string city; private string description; private file uploadphoto; private string photofiletype; private string photoname;  public string getpropertyid() {     return propertyid; } public void setpropertyid(string propertyid) {     this.propertyid = propertyid; } public string getpropertyname() {     return propertyname; } public void setpropertyname(string propertyname) {     this.propertyname = propertyname; } public string getcountry() {     return country; } public void setcountry(string country) {     this.country = country; } public string getstate() {     return state; } public void setstate(string state) {     this.state = state; } public string getcity() {     return city; } public void setcity(string city) {     this.city = city; } public string getdescription() {     return description; } public void setdescription(string description) {     this.description = description; } public file getuploadphoto() {     return uploadphoto; } public void setuploadphoto(file uploadphoto) {     this.uploadphoto = uploadphoto; }  public string getphotofiletype() {     return photofiletype; }  public void setphotofiletype(string photofiletype) {     this.photofiletype = photofiletype; }  public string getphotoname() {     return photoname; }  public void setphotoname(string photoname) {     this.photoname = photoname; }  public string execute(){      dbconnection connection=new dbconnection();     connection.getconnection();      try{          string filepath=connection.filepath;          system.out.println("filepath : : "+filepath);         system.out.println("photoname : : "+photoname);          if(filepath!=null && photoname!=null){             file filetocreate=new file(filepath,photoname);             fileutils.copyfile(uploadphoto, filetocreate);           }      }catch(exception e){         e.printstacktrace();         addactionerror(e.getmessage());          return input;     }      string query ="insert addproperty(propertyid,propertyname,propertycity,propertystate,propertycountry,addedby,addeddate,removeddate) values ('"+propertyid+"','"+propertyname+"','"+city+"','"+state+"','"+country+"','parthi',now(),null)";     connection.executeupdate(query);      system.out.println("completed inserting");      return success;      //system.out.println("class completed"); } } 

action class should have following 3 properties.
• [inputname]file
• [inputname]filename
• [inputname]contenttype

[inputname] name of file tag(s) on jsp. example, if file tag's name uploadphoto, properties follows:
• file uploadphotofile
• string uploadphotofilename
• string uploadphotocontenttype

string filepath = servletrequest.getrealpath("/"); file filetocreate = new file(filepath, this.uploadphotofilename); fileutils.copyfile(this.uploadphotofile, filetocreate); 

Comments

Popular posts from this blog

php - Wordpress website dashboard page or post editor content is not showing but front end data is showing properly -

javascript - Get parameter of GET request -

javascript - Twitter Bootstrap - how to add some more margin between tooltip popup and element -