0

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.

Enrico Morelli
  • 185
  • 3
  • 16
  • 2
    Yes, it is. Have you tried something? – Luiggi Mendoza Nov 19 '13 at 14:37
  • @LuiggiMendoza I tried a lot of thing but no one works. Can you give an idea how to do that? – Enrico Morelli Nov 19 '13 at 14:41
  • 1
    possible duplicate of [JSF - how to hit a bean method and redirect based on a get variable?](http://stackoverflow.com/questions/7488211/jsf-how-to-hit-a-bean-method-and-redirect-based-on-a-get-variable) – BalusC Nov 19 '13 at 15:24
  • @BalusC the main problem is that the remote host check for the presence of a redirect instruction in the response page. In the post you link, it's the bean that redirect the user. – Enrico Morelli Nov 19 '13 at 15:42
  • If JSP really is deprecated, then Java is finally dead. I guess we should all switch to .NET now. – developerwjk Nov 19 '13 at 22:03

1 Answers1

0

you can use metadata in your xhtml i.e:

<f:metadata>
        <f:viewParam name="result" value="#{yourBean.result}"/>
        <f:viewParam name="auth" value="#{yourBean.auth}"/>
        <f:viewParam name="ref" value="#{yourBean.ref}"/>
        <f:viewParam name="transid" value="#{yourBean.tranid}"/>
        <f:viewParam name="trackid" value="#{yourBean.trackid}"/>
</f:metadata>