java - How to get data fron beanclass in springMVC? -
how data beanclass in springmvc? trying got error.
in spring mvc didnt data bean class
this bean class
public class emailbean { private long id; private string from; private string to; private string subject; private string content; private string status; //getter , setter }
this email sender
public class emailsender extends thread { private emailbean eb; public emailbean geteb() { return eb; } public void seteb(emailbean eb) { this.eb = eb; } public void run() { sendsingleemail(eb); } public static void sendsingleemail(emailbean eb) { system.out.println(eb.getto()); system.out.println(eb.getsubject()); system.out.println(eb.getcontent()); } }
this main class
public class testmail { public static void main(string[] args) { try { emailbean eb=new emailbean(); eb.setfrom("xxx@gmail.com"); eb.setto("yyyyy@gmail.com"); eb.setsubject("testing email subject"); eb.setcontent("testing email content"); eb.setid(1l); eb.setstatus("100"); emailsender es=new emailsender(); es.start(); } catch (exception e) { e.printstacktrace(); } } }
when run testmail wont work why? git error
exception in thread "thread-0" java.lang.nullpointerexception @ com.candidjava.springmvc.service.emailsender.sendsingleemail(emailsender.java:36) @ com.candidjava.springmvc.service.emailsender.run(emailsender.java:30)
just simple mistake made in main method, before starting thread call setter method set emailbean information, find below correct code
public class testmail { public static void main(string[] args) { try { emailbean eb=new emailbean(); eb.setfrom("xxx@gmail.com"); eb.setto("yyyyy@gmail.com"); eb.setsubject("testing email subject"); eb.setcontent("testing email content"); **eb.setid(1l);** eb.setstatus("100"); emailsender es=new emailsender(); es.seteb(eb); es.start(); } catch (exception e) { e.printstacktrace(); } } }
if new spring mvc try simple spring hello world example understand basic
Comments
Post a Comment