thanks for the reply..
but how do i access the values if the target of the trial.jsp is a servlet?
can i get the java class using request.getAttribute("person")?
Joined: Mar 22, 2005
No, servlets don't work that way - they're called "JSP beans" because they're used with JSPs. Servlets would use getParameter to get at individual form parameters. (As a side note, just about all web frameworks, from Struts to Stripes to Wicket, perform the parameter-to-Java field/object binding automatically.)
Note also that once you make a new request, like with a link, form submission, etc. the *current* request's attributes are lost.
Joined: Feb 22, 2010
Thanks for the reply.
But one more doubt. I read some where, if we set the scope="session" while creating a bean, the bean will be available in the session and I would be able to accccess the object from session as session.getAttribute("beanclass")?
Will this work?
Or java beans are useful only for jsp-jsp communication and not for jsp-servlet communication??
I think the OP is confused about how the input parameters relate to the bean properties.
I would like to offer the following simple example.
In the first JSP page, you include various input fields and a submit button in an HTML <form> element. The Form posts to your servlet.
The servlet uses request.getParameter("parameter-name") to get each of the parameters. You can then assign each of these parameters as you like to your Bean instance. Note that as Ulf said, you can use BeanUtils to locate all the input parameter values and assign them to your bean instance automatically (or use a framework like Struts 2 to do this automatically).
You then assign the bean instance to the session (in request scope perhaps) and forward/redirect to the display JSP page.
In the display JSP page, you can use the <jsp:useBean ...> if you wish, or just use JSTL/EL, which is even easier - to access the bean properties and display them on the page.