You seem to misunderstand the work and purpose of jsp:useBean .
First of all, you indicated that the bean is in the session area, and you fill it with all the parameters of the current request.
<jsp:useBean id="user" class="com.hermes.data.RateCode_" scope="session"> <jsp:setProperty name="user" property="*"/> </jsp:useBean>
This bean is thus saved as a session attribute named user . You need to get it in the servlet as a session attribute, not as a request attribute.
RateCode_ user = (RateCode_) request.getSession().getAttribute("user");
( user is a terrible and confusing attribute name, by the way, I would rename it rateCode or something without this odd _ at the end)
However, it will not contain anything. getCode() and getDescription() will return null . <jsp:setProperty> did not fill it with all request parameters, but at that moment you are trying to access it in the servlet. This will only be done when you forward the request containing the parameters back to the JSP page. However, this happens outside the servletβs business logic.
You need to collect them as query parameters yourself. First, get rid of the whole <jsp:useBean> thing in JSP and do doPost() in the servlet doPost() as follows:
RateCode_ user = new RateCode_(); user.setCode(request.getParameter("code")); user.setDescription(request.getParameter("description")); // ... request.setAttribute("user", user); // Do NOT store in session unless really necessary.
and then you can access it in the JSP, as shown below:
<input type="text" name="code" value="${user.code}" /> <input type="text" name="description" value="${user.description}" />
(this is only sensitive to XSS attacks , you want to install JSTL and use fn:escapeXml )
No, you do not need <jsp:useBean> in JSP. Hold it, it doesn't really matter when you use the MVC approach (level 2) with real servlets. <jsp:useBean> is only useful for MV design (MVC level 1). To save the template code for the collection request parameters, consider using the MVC or Apache Commons BeanUtils structure. See Also links for tips.
See also: