• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to create common successful page

 
cb poo
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I would like to have one successful.jsp that can call by more that one action. This successful.jsp will show different bean for different actions.

For example of userAction, successful.jsp should show
--------
The record successfully save:-
user = myUserName
password = myUserPassword
--------

For example of AccountAction, successful.jsp should show
--------
The record successfully save:-
account id = 001
account name = myAccount
account type = saving
--------

Guys, any idea how to archieve this using struts? I don't want to create each different success.jsp for different action.
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create a global forward named success that points to the success.jsp. Any action can forward to a global forward.
 
cb poo
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No. I talking about how to create the content of the success.jsp, where it can be shareable across all my action. And the jsp should display bean that successfully save into database for every individual action.
In this case, how do I code the jsp page. I will never know the bean name to display in jsp?
 
Eugene Lucash
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It's possible.
first create global forward.
and then in your jsp use some reflection, java.beans.*;
For example Introspector tool (class) to get all of Bean's properties
take a look at api documentation

import java.beans.*;
import java.lang.reflect.*;

Object bean = .....

BeanInfo i = Introspector.getBeanInfo(bean.getClass());
PropertyDescriptor[] p = i.getPropertyDescriptors();
for (PropertyDescriptor prop : p) {
Class clazz = prop.getPropertyType();
String name = prop.getName();
Method m = prop.getReadMethod();
Object value = m.invoke(bean,null);
//do something for each property
//now you have prop's name, type and value, all you need
}

if you can use DynaActionForms it is even simplier

DynaActionForm form = (DynaActionForm )f;
DynaClass dc = form.getDynaClass();
DynaProperty dn[] = dc.getDynaProperties();

for (DynaProperty d : dn){
String propertyName = d.getName();
Class clz = d.getType();
Object value = form.get(propertyName);
// do somethig for each property
}
[ February 23, 2005: Message edited by: Eugene Lucash ]
 
cb poo
Ranch Hand
Posts: 67
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The solution above need to have scriplet in my jsp, right? Is there any others way to archive that?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic