I've to create a platform for a congress registration and payment. For the payment my application redirect the user on the back platform. At the end of the payment the bank platform redirect the user on my application sending some data. To grab these data (following the bank documentation) I'm using JSP like the following:
<%@page import="EJB.getResponse"%>
<%
long paymentID = Long.parseLong(request.getParameter("paymentid"));
String result = request.getParameter("result");
String auth = request.getParameter("auth");
long ref = Long.parseLong(request.getParameter("ref"));
long tranid = Long.parseLong(request.getParameter("tranid"));
String trackid = request.getParameter("trackid");
out.println("redirect=" + "http://mymachine/congress/result.jsp?paymentID=" + paymentID + "&responsecode=" + responsecode);
%>
If there isn't the redirect instruction in the page, the remote server doesn't send any data. I'm reading that JSP is deprecated, so is there a way to do the same thing using JSF end Beans?
After your suggestions I tried to use JSF and Beans like these:
<f:metadata>
<f:viewParam name="result" value="#{getResponse.result}"/>
<f:viewParam name="auth" value="#{getResponse.auth}"/>
<f:viewParam name="ref" value="#{getResponse.ref}"/>
<f:viewParam name="transid" value="#{getResponse.tranid}"/>
<f:viewParam name="trackid" value="#{getResponse.trackid}"/>
<f:event type="preRenderView" listener="#{getResponse.redirect}" />
</f:metadata>
public void redirect() throws IOException {
// FacesContext facesContext = FacesContext.getCurrentInstance();
// NavigationHandler navigationHandler = facesContext.getApplication().getNavigationHandler();
//// ExternalContext extContext = facesContext.getExternalContext();
//// extContext.redirect("result.jsp?paymentid=" + paymentId + "&responsecode=" + responsecode + "faces-redirect=true");
// navigationHandler.handleNavigation(facesContext, null, "result.jsp?paymentid=" + paymentId + "&responsecode=" + responsecode + "faces- redirect=true");
ExternalContext ec = FacesContext.getCurrentInstance().getExternalContext();
ec.redirect(ec.getRequestContextPath() + "/result.jsp?paymentid=" + paymentId + "&responsecode=" + responsecode + "faces-redirect=true");
}
I tried also servlet:
@WebServlet("/getresponse")
public class getResponse2 extends HttpServlet {
private Long paymentId;
private String result;
private String auth;
private String ref;
private String traind;
private String trackid;
private String udf1;
private String responsecode;
private String host;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
paymentId = Long.parseLong(request.getParameter("paymentid"));
responsecode = "9999";
System.out.println("paymentID: " + paymentId);
// Etc... Put your original JSP code here and alter accordingly.
request.getRequestDispatcher("notify2.jsp").forward(request, response);
//response.sendRedirect("result.jsp?paymentID=" + paymentId + "&responsecode=" + responsecode);
}
But for the bank platform no one is correct. The response page MUST to contains redirect= string.