[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 594
  • Last Modified:

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

0
chaitu chaitu
Asked:
chaitu chaitu
  • 5
  • 3
  • 2
1 Solution
 
objectsCommented:
you cannot pass an object to a different context, they are independant applications
0
 
Suraj_MathewCommented:
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);
0
 
chaitu chaituAuthor Commented:
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??
0
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
objectsCommented:
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
0
 
objectsCommented:
to pass to a different context then you'll need to do a redirect and include the details need as request parameters
0
 
Suraj_MathewCommented:
thanks chaituu and objects for correcting me....
0
 
chaitu chaituAuthor Commented:
objects,
i didnt get you.can you write some pseudo code?
0
 
objectsCommented:
/dept/DeptAction?empName=bill&empAbc=xyz
0
 
chaitu chaituAuthor Commented:
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..
0
 
objectsCommented:
the only way to pass data between context is via the request
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

  • 5
  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now