Getting Number Format Exception while accessing the value from Jsp -


code servlet

    string id=request.getparameter("id");      userprofiledao dao = new userprofiledao();      list<userprofilepojo> list = dao.userprofile(id);      request.setattribute("profile", list);      requestdispatcher view= request.getrequestdispatcher("profile.jsp");      view.forward(request, response); 

code written in data access object class

public list<userprofilepojo>userprofile(string id) {     string query ="select fname registration id="+id;     list<userprofilepojo> list = new arraylist<userprofilepojo>();     userprofilepojo user = null;     try {            connection = getconnection();         stmt = connection.createstatement();         resultset rs = stmt.executequery(query);         while (rs.next())          {                 user = new userprofilepojo();                 user.setfname(rs.getstring("fname"));                 list.add(profile);         }                                                                                 }                                                                                   

code written in pojo class

public class userprofilepojo {  private string fname;  public string getfname();         {             return fname;         }          public void setfname(string fname)          {             this.fname = fname;          }  } 

access through jsp

       <td>${profile.fname}</td> 

exception stack trace

    message java.lang.numberformatexception: input string: "fname"          description server encountered internal error prevented           fulfilling request.      exception      org.apache.jasper.jasperexception: java.lang.numberformatexception:           input string: "fname"     root cause    java.lang.numberformatexception: input string: "fname"   java.lang.numberformatexception.forinputstring(unknown source) 

the problem when setter method called jsp using ${profile.fname} displays number format exception. after researching on particular exception got know occurs when 1 data type tried convert data type. unable understand happening in particular scenario.

please me in solving problem. regards.

that's because you're trying access element in list without referencing index it's at.

request.setattribute("profile", list); //profile list object 

use instead:

<td>${profile[0].fname}</td> 

Comments

Popular posts from this blog

css - SVG using textPath a symbol not rendering in Firefox -

Java 8 + Maven Javadoc plugin: Error fetching URL -

node.js - How to abort query on demand using Neo4j drivers -