Monday, January 30, 2006

[Struts] Passing data to the jsp

This code was made found at http://www.allapplabs.com/struts/struts_example.htm
It shows how you can pas data from one jsp to another.
This is struts basic and very easy but I didn't knew this.

first jsp contains the code:
<html:text property="name" />

The struts action mapping creates a action class.
This class loads the data from the form with the code:
NameForm nameForm = (NameForm)form;
String name = nameForm.getName();

Second this class sets the attribute for the second jsp:
request.setAttribute("NAME", name);

The second jsp page loads the data with the code:
<%= request.getAttribute("NAME") %>

How easy can it be :-)

No comments: