cancel
Showing results for 
Search instead for 
Did you mean: 

HTTP form post from Web Dynpro Java Application without opening new window

Former Member
0 Kudos

Hi Experts,

We are trying to submit form data to an external URL from Web Dynpro Java application. We are achieving this with the following piece of code.

  try

  {

   strPrintContent="<html>"+

     "<head>"+

     "<script type=\"text/javascript\">"+   

     "function myfunc () "+

     "{"+

     "var frm = document.getElementById(\"paymentForm\");"+

     "frm.submit();"+

     "}"+

     "</script>"+

     "</head>"+

     "<body onLoad=myfunc()>"+

     "<form id=paymentForm  method=post action=\""+merchantURLPart+"\">"+

     "<INPUT type=hidden name=username value="+userName+">"+

     "<INPUT type=hidden name=pass value="+passWord+">"+

     "<INPUT type=hidden name=senderid value="+senderID+">"+    

     "<INPUT type=hidden name=dest_mobileno value="+mobile+">"+

     "<INPUT type=hidden name=message value='"+msg+"'>"+

     "<INPUT type=hidden name=response value="+response+">"+

     "</form>"+

     "</body>"+

     "</html>";    

  

  IWDWebResource webResource = WDWebResource.getWebResource(strPrintContent.getBytes(),WDWebResourceType.HTML);

  IWDWindow window = wdComponentAPI.getWindowManager().createNonModalExternalWindow(webResource.getAbsoluteURL(),"WBSEDCL");

  window.show();

         

  }

  catch(Exception e)

  {

 

 

  wdComponentAPI.getMessageManager().reportException("Error : "+e.toString(),false);

  }

But it opens another window. We dont need that. We have to stay on the same window.  Please suggest what can be done.

Accepted Solutions (1)

Accepted Solutions (1)

Former Member
0 Kudos

Answers (5)

Answers (5)

former_member186852
Contributor
0 Kudos

Dear Suvankar,

U got any solution ???

If have any solution please let me know

Thanks & Regards,

Meghal Shah

Former Member
0 Kudos

Hi,

You can create a HTML file with the request post parameters and the external URL something like this:

public java.lang.String GetRedirecturl( )

{

// External URL

String html = "<html><head></head><body onload=\"load()\"> " +

"<form id=\"form1\" action=\"https://www.abc.com/xyz.jsp\" method=\"POST\">" +

// Post Parameters

"<INPUT TYPE=\"HIDDEN\" NAME=\"Param1\"VALUE=\""+Param1Value+"\">"+

"<input name=\"sap-wd-resumeurl\" type=\"hidden\"/>" +

"</form> " +

"" +

"<script>" +

"function load(){" +

"var loc = window.location.search.substring(1);" +

"var queryString = loc.split(\"sap-wd-resumeurl=\");" +

"if(queryString.length > 0)" +

"{" +

"var resumeURL = queryString[1].split(\"&\");" +

"if(resumeURL.length >= 0)" +

"{" +

" document.forms['form1'].elements['sap-wd-resumeurl'].value= unescape(resumeURL[0])" +

"}" +

"}" +

"document.getElementById('form1').submit();" +

"}" +

"</script>" +

"</body> </html>";

String redirectUrl = "";

byte[] byteArrayHtmlData = null;

try {

  byteArrayHtmlData = html.getBytes("UTF-8");

} catch (UnsupportedEncodingException e) {

  wdComponentAPI.getMessageManager().reportException("Internal error occurred. Please try after some time",true);

}

IWDResource htmlResource = WDResourceFactory.createCachedResource(new ByteArrayInputStream(byteArrayHtmlData), "Redirect.html", WDWebResourceType.HTML, true);

redirectUrl = htmlResource.getUrl(WDFileDownloadBehaviour.AUTO.ordinal());

return redirectUrl;

}

Hope this will be helpful.

Regards,

Anurag

Former Member
0 Kudos

If you are in NW7.3 version try using WebWidget UI for this requirement.

Mahesh

Former Member
0 Kudos

Dear Suvankar,

Please check if this thread is helpful.

Thanks,

Patralekha

former_member182374
Active Contributor
0 Kudos

Hi,

Use Java, something like this: http://kspace.in/blog/2008/05/30/submit-html-form-using-java/

Regards,

Omri

former_member191044
Active Contributor
0 Kudos

Hi Suvankar,

you could try to add a "window.hide()" right after the "window.show". But i don't know what happens since it would be a show and a hinde in one roundtrip.

Also you coud create a html file which accepts your params via url and then does a post on load. Then you could call that html via IFrame and set the frame to 0 px so it would be invisible.

Or maybe add a message "Data send successfully" (or something equal) and a button "ok" to your generated HTML which closes the new external window and gives feedback to enduser.

Regards,

Tobi