This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Struts and the fly likes can i call DispatchAction from global forward Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "can i call DispatchAction from global forward" Watch "can i call DispatchAction from global forward" New topic
Author

can i call DispatchAction from global forward

sreenivas jeenor
Ranch Hand

Joined: Jan 09, 2005
Posts: 125
Hi Ranchers,


I normal circumstances i uesd to call approriate method in dispatchAction class using hidden attribute in jsp page,but for this case i dont know how to handle.


I have created a DispatchAction class.
my reqiurement is that when i click on getDetails link on the jsp page,the following getPatientDetails() method should be executed in DispatchAction class and a new page must be populated wiith details..


<html:link forward="PatientDetails">get Details</html:link>



here is my strust-config.xml
----------------------------
<global-forwards>

<forward
name="PatientDetails"
path="/PatientDetails.do"/>

</global-forwards>

<action-mappings>
<action
path="/PatientDetails"
type="ssl.phr.patientdemographics.actionservlet.PatientAction"
name="PatientDetailsForm"
scope="request"
validate="true"
parameter="action"
input="/patientregistration.jsp">
<forward name="success" path="/patientregistrationcard.jsp"/>
<forward name="patientdetails" path="/patientdetails.jsp"/>
</action>
</action-mappings>

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


here is my

import ssl.phr.patientdemographics.dto.*;
import ssl.phr.patientdemographics.dao.*;
import java.io.*;import java.util.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.actions.DispatchAction;
import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionServlet;
import javax.servlet.http.HttpSession ;
import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.http.HttpServlet;

public final class PatientAction extends DispatchAction {
public static String SUCCESS = "success";
public static String Patientdetials = "patientdetails";


public ActionForward PRegistration(ActionMapping mapping,
ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException {

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("inside perform method");
PatientDetailsForm pdform =(PatientDetailsForm) form;

PatientDetailsDAO dao= new PatientDetailsDAO();

String pfirstname=request.getParameter("firstName");
pfirstname=pfirstname.replace("'","''");
pdform.setDateOfBirth("");//request.getParameter("dob")

String zip=request.getParameter("zipCode");
int z=Integer.parseInt(zip);
pdform.setZipCode(z);
String emergencyKey=dao.insertPatientRegistrationRecord(pdform);
request.setAttribute("EKey",emergencyKey);
request.setAttribute("PatientDetails",pdform);


return mapping.findForward(SUCCESS);


} // end PatientRegistration

public ActionForward getPatientDetails(ActionMapping mapping,
ActionForm form,HttpServletRequest request,HttpServletResponse response)
throws IOException, ServletException {

HttpSession session = request.getSession();

//int patientID;
String userName=(String)session.getAttribute("userName");
int pid=((Integer)session.getAttribute("patientID")).intValue();

System.out.println("username is.. "+userName);
System.out.println("pid is.. "+pid);

response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("inside perform method");
PatientDetailsForm pdform =(PatientDetailsForm) form;

pdform=(PatientDetailsForm)patdao.retrieveRecord(pid);


return mapping.findForward(Patientdetials);


}
}

help me out

Thanks
Merrill Higginson
Ranch Hand

Joined: Feb 15, 2005
Posts: 4864
My advice is not to use a forward in this case, but just append the parameter used by DispatchAction to the action path URL. Example:


Merrill
Consultant, Sima Solutions
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: can i call DispatchAction from global forward
 
Similar Threads
how to populate values in jsp page
How to hide url: in struts
DispatchAction:seems fine, but doesn't work
How to get the field details from one jsp page in struts dispatchaction action class
how to get value of hmtl:link in action class?