Getting data from the Java bean to be displayed on a JSP page [duplicate]

左心房为你撑大大i 提交于 2019-12-06 04:42:27

First of all, your class RegisterDetails is not a bean because it does not implement the java.io.Serializable interface.

Secondly, you really need to implement some kind of input sanitization for the data coming from the request (to prevent SQL/HTML/Cross-site scripting injections), and if you are going to use beans I guess you should put that inside the bean class.

Third, you could also dispense with the bean concept (meaning you won't need jsp:useBean) and just save the instance of the class RegisterDetails as a regular class object into the session, and then you can pull it from the session on any page as follows:

In the servlet:

 session.setAttribute("details", details); //saving your object to the session

In any other page:

RegisterDetails details = (RegisterDetails)session.getAttribute("details");

developerwjk - good catch on the bean not being serializeable, but that shouldnt cause the problem.

user3258979 - your servlet looks ok to me. And I can see your form doing the proper POST. Have you tried doing a trace on the servlet? Can you put a break point on this line to confirm the request values are coming through:

details.setName(request.getParameter("FullName"));

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!