servlets - Accessing bean from Jsp -
i searched on forum haven't got appropriate solution. , if mistake 1 duplicate sorry.
coming problem... i'm setting values 1 of html using servlet code index.html
<form method="post" action="user"> what's name? <input type="text" name="username" size=20>`
code servlet
package test; ...... userbean ub = new userbean(); string name = request.getparameter("username"); ub.setfirstname(name); request.setattribute("user",ub); requestdispatcher rd=request.getrequestdispatcher("/getjsp.jsp"); rd.forward(request,response);
both servlet , bean placed in package called test.
code userbean:
private string firstname; public string getfirstname() { return firstname; } public void setfirstname(string firstname) { this.firstname = firstname; system.out.println(firstname); }
from bean i'm able print proper value name on server console. after setting values servlet i'm trying acceess bean values jsp called getjsp.jsp
getjsp.jsp
<table> <jsp:usebean id="user" type="test.userbean" class="test.userbean" scope="request" > <tr> <td> id : </td> <td> <jsp:getproperty name="user" property="firstname"/></td> </tr> </jsp:usebean> </table>
when accessing bean properties jsp i'm getting following error:
org.apache.jasper.jasperexception: /getjsp.jsp (line: 10, column: 1) value usebean class attribute userbean invalid.
i'm not able understand problem in code error. me out please.
thank you.
given error message, seems actual code of jsp uses class="userbean"
, not class="test.userbean"
.
but more importantly, reason why found nothing when searching answer you're implementing jsp if nothing had changed in jsp area more 10 years. jsp:usebean
, other jsp:xxx
tags obsolete. learn how use jsp el , jstl, , replace code of jsp by
<table> <tr> <td> id : </td> <td><c:out value="${user.firstname}"/></td> </tr> </table>
this have additional advantage of escaping html special characters in user name.
Comments
Post a Comment