Link to home
Start Free TrialLog in
Avatar of chaitu chaitu
chaitu chaituFlag for India

asked on

How to pass the object from one context to another context in struts-websphere combination


How to pass the object in this action class(do we need to set it here in request,session or application scope)  from one context to another context and how to access this object in in different context action class.

am using websphere application server.

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>


index.jsp
<HEAD>

<BODY>
<form action="/employee/EmployeAction">
<input type='text' name='empname' value='1'>
<input type='submit' name='submit' value='submit'>
</BODY>
</HTML>

Open in new window

EmployeAction.java
public class EmployeAction extends Action {
	public ActionForward execute(ActionMapping mapping, ActionForm form,
			HttpServletRequest request, HttpServletResponse httpservletresponse)
			throws Exception {

		if (form == null) {
			return mapping.findForward("success");
		}
		
			
		String empname =request.getParameter("empname");
		Employee emp = new Employee();
		emp.setName(empname);

	//  how to store or pass this object here in this action class(do we need to set it here session or application scope) and	how to access this object in in different context action //class.
	//am using websphere application server.

		/dept/DeptAction
			
		
		return mapping.findForward("success");
	}
}

Open in new window

Avatar of Mick Barry
Mick Barry
Flag of Australia image

you cannot pass an object to a different context, they are independant applications
Avatar of Suraj_Mathew
Suraj_Mathew

try setting the required objects in Session variable , and access them from your desired class/jsp
But it will only be available in that particular HTTP session.

request.getSession().setAttribute("attribute name",object);
Avatar of chaitu chaitu

ASKER

suraj,

if you are passing object from one context to another context session scope will not work.

objects,

this employee object is having multiple variables and need to pass this object in diff contexts.how to overcome this problem??
session is only available in the same context so won't help for sending to a different context
if you're just forwarding within the same context then you should pass it as a request attribute
to pass to a different context then you'll need to do a redirect and include the details need as request parameters
thanks chaituu and objects for correcting me....
objects,
i didnt get you.can you write some pseudo code?
/dept/DeptAction?empName=bill&empAbc=xyz
this is old technique.i need to send some 30 to 40 parameters.if i send like this it will be performance overhead..apart from that i have one xml blob object that i cannot send like this..
ASKER CERTIFIED SOLUTION
Avatar of Mick Barry
Mick Barry
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial