Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Passing Atrribute Object From Jsp To Action

 
pamir sonmez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You confused me
Please be some more specific. Show us some code.
 
pamir sonmez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 91
Android Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic