java - useBean in jsp and getAttribute in jsp but NULL
- by ravi parekh
user is null in servlet.
Pls let me if doing mistake.
i m trying to get all html element in bean
rateCode.jsp
**<%@page import="com.hermes.data.RateCode_" %>**
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title>Rate Code</title>
</head>
<body>
**<jsp:useBean id="user" class="com.hermes.data.RateCode_" scope="session" >
<jsp:setProperty name="user" property="*"/></jsp:useBean>**
<form id="f_rateCode" action="/ratePromoCodes" method="post" >
<table align="center" border="1" cellspacing="0">
<tr>
<td colspan="2" align="center" class="header">Rate Code Administrations</td>
</tr>
<tr>
<td align="right" style="border-style: solid;">Rate Code:</td>
<td align="left" style="border-style: solid;">
<input type="text" id="code" name="code" value="${user.code}" size="10" maxlength="32" style="width: 100px"/>
</td>
</tr>
<tr>
<td align="right" style="border-style: solid;">Rate Description:</td>
<td align="left" style="border-style: solid;">
<input type="text" id="description" name="description" value="<%=user.getDescription()%>" maxlength="128" size="40"></td>
</tr>
<tr><td><input type="submit" value="ok" /></td> </tr>
</table>
</form>
Servlet - ratePromoCodes
protected void doPost(HttpServletRequest req, HttpServletResponse resp) {
RateCode rc = (RateCode) req.getAttribute("user");
Enumeration an = req.getAttributeNames();
Enumeration pn = req.getParameterNames();
Object o = null;
while (an.hasMoreElements()) {
o = an.nextElement();
System.out.println(o);
}
while (pn.hasMoreElements()) {
o = pn.nextElement();
System.out.println(o);
}
}
RateCode.java (javaBean)
public class RateCode_ {
private String code ;
private String description;
public String getCode() {
return code;
}
public void setCode(String code) {
this.code = code;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}