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 How to get data back on result page from struts Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "How to get data back on result page from struts" Watch "How to get data back on result page from struts" New topic
Author

How to get data back on result page from struts

RP Singh
Greenhorn

Joined: Feb 11, 2006
Posts: 3
Hello ,

How do I get data back in the result jsp page from a action servlet. If I am retrieving data from a database through a model bean how do I get the data onto the output jsp page.

Does it have to go through the formbean and then read the formbean to output the data.

Please add some details.

Thanks

RP
Naseem Khan
Ranch Hand

Joined: Apr 25, 2005
Posts: 809

Originally posted by RP Singh:
How do I get data back in the result jsp page from a action servlet. If I am retrieving data from a database through a model bean how do I get the data onto the output jsp page.



First you asked.. how to getback data in jsp from ActionServlet? Then you asked how to get it in jsp from model.

What exactly is your question? If you are asking data retrieval from model in some jsp then here is the way of doing it.


Code below




Regards

Naseem


Asking Smart Questions FAQ - How To Put Your Code In Code Tags
RP Singh
Greenhorn

Joined: Feb 11, 2006
Posts: 3
Hello Naseem,

The MyTransferObject which will return the data from model bean, you refer it to as a transfer object. Do you mean this MyTransferObject(bean) needs to extend actionForm , I mean is it a formBean.

My question is does the data coming from Model has to come through a FormBean.

Thanks for the help

RP

quote:
--------------------------------------------------------------------------------

Originally posted by RP Singh:
How do I get data back in the result jsp page from a action servlet. If I am retrieving data from a database through a model bean how do I get the data onto the output jsp page.

--------------------------------------------------------------------------------



First you asked.. how to getback data in jsp from ActionServlet? Then you asked how to get it in jsp from model.

What exactly is your question? If you are asking data retrieval from model in some jsp then here is the way of doing it.


Code below


code:
--------------------------------------------------------------------------------

public class TestAction extends Action{ public ActiuonForward execute(ActionMapping mapping, ActionForm form, HttpServletRequest, request, HttpServletResponse response) throws Exception{ /** * Instantiate dao component. Suppose its TestDAO.class which has * meth() method which returns an instance of some TransferObject say * MyTransferObject. */ TestDAO testdao=new TestDAO(); MyTransferObject obj=testdao.meth(); /** * This transfer object actually carries the data from dao * component. Once you got transfer object set it in some scope like * request scope. Forward request, response to Output jsp page. * Finally in Output jsp page retrieve it form request scope. */ request.setAttribute("SomeKey", obj); mapping.findForward("success"); }}

--------------------------------------------------------------------------------




Regards

Naseem
--------------------
HungryJavaGoat
Greenhorn

Joined: Jun 30, 2006
Posts: 23
Hi ,
it is not mandatory that it should come through a FormBean. FormBean is used when data is retrieved from the html form. ActionServlet will instantiate a FormBean and load the form bean with the html form data. This is based on the struts-config.xml.
However while you are trying to retrieve data from db and display it in jsp , we usually have normal java bean object (Transfer Object or Value object) which we will load and keep it in request or session scope based on the need. But you can also use FormBean for that ..But it is good design to use a Transfer Object (its normal java bean .. NOT ActionForm bean). Pls correct if something is wrong.

Regards,
Karthik
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to get data back on result page from struts