File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Struts and the fly likes Passing Atrribute Object From Jsp To Action Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Passing Atrribute Object From Jsp To Action" Watch "Passing Atrribute Object From Jsp To Action" New topic
Author

Passing Atrribute Object From Jsp To Action

pamir sonmez
Ranch Hand

Joined: May 31, 2010
Posts: 47
Hello everyone,

I have a situation like that;

In a page, lets say product.jsp, I fill the textBoxes and I submitted the form and I am redirected to the action mapping of this jsp
In this actionMethod I get the ,lets say productForm, and then I called the function "request.setAttribute("productForm",productForm);
Then I am redirected to the "consumer.jsp". In consumer.jsp page, I can reach the attribute of productForm.

In the consumer.jsp, when I clicked a button I will be forwarded to the another action mapping, namely another actionMethod.

And I want to reach the productForm in this actionMethod.
How can I submit this form bean from jsp to method?

Thanks
Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 88

You confused me
Please be some more specific. Show us some code.
pamir sonmez
Ranch Hand

Joined: May 31, 2010
Posts: 47
first jsp:

<html:form action="product">
<html:hidden property="method" value="add" />
<html:submit>Add</html:submit>
/>

From this jsp, when I clicked submit I am forwarded to the action method;

public ActionForward add(...) {
.....
productForm = (ProductForm) actionForm;
request.setAttribute("productForm",productForm);
return mapping.findforward(..);
}

Then I am directed to another jsp;
In this jsp I can reach the object like
<%
ProductForm = request.getAttribute("productForm");
%>

And In this page I hava a submit button again;
<html:form action="product">
<html:hidden property="method" value="check" />
<html:submit>Add</html:submit>
/>

So when I clicked the button I am forwarded to the action method;
public ActionForward check(...) {

/*
In this method I want to reach product object like
productForm = request.getAttribute("productForm");
*/
}
Karthik Jayachandran
Ranch Hand

Joined: Feb 18, 2009
Posts: 88

In a page, lets say product.jsp, I fill the textBoxes and I submitted the form and I am redirected to the action mapping of this jsp .....

Then I am redirected to the "consumer.jsp". In consumer.jsp page, I can reach the attribute of productForm.


Not sure whether you are 'redirecting' to customer.jsp. If you have set redirect="true" in the action mapping, then this will clear any object in request scope and creates new request. So, instead you can have that form object in session scope.

/*
In this method I want to reach product object like
productForm = request.getAttribute("productForm");
*/


Also do a casting of your ActionForm object. After customer.jsp submit, in the action get the object as

 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Passing Atrribute Object From Jsp To Action