Search code examples
servletsportlet

How to Send Post request in java with javax.portlet.ActionResponse.sendRedirect method?


I want to POST to URL but following making it as GET , so How can I POST the

    Object portletResponse = webAppAccess.getHttpServletRequest()
            .getAttribute(Constants.PORTLET_RESPONSE);

   if (portletResponse instanceof javax.portlet.ActionResponse) {
            javax.portlet.ActionResponse actionResponse = (javax.portlet.ActionResponse) portletResponse;

            actionResponse.sendRedirect(URL);
        }

Solution

  • I have done this by using FORM POST method as follows.

     webAppAccess.processPage("importedPage");
    

    Added this imported Page in model :

    <HTML>
    <HEAD>
    <title>New Page</title>
    </HEAD>
    <Body onload="">
    <form id="FormID" method="POST" action="actionURL">
        <input type="hidden" name="id" id="ID" value="<%=webAppAccess.getVariables().getString("ID")%>"/>
        <noscript>
            <p>Your browser does not support JavaScript or it is disabled. 
                Please click the button below to process the request.
        </p>
            <input type="submit" value="Proceed " name ="submit"></input>
        </noscript>
        <script>
        document.getElementById('FormID').submit();
        </script>
    </form>
    

    and then MVC controller mapping as follows:

     @RequestMapping(value = {"/Details"}, method = RequestMethod.POST)
    public String mthDetails(final Model p_model, @RequestParam(value = "id", required = false) final String p_ID){ 
    
        //code for further logic using ID
    }