Forum Stats

  • 3,855,036 Users
  • 2,264,452 Discussions
  • 7,905,869 Comments

Discussions

Executing web url in java

1004526
1004526 Member Posts: 197
edited Dec 27, 2013 5:32PM in JDeveloper and ADF

    I use a custom component and develop below piece of code

    <img id="01" src="http://localhost:80/cs/idcplg?IdcService=CREATE_STATIC_RENDITION&dDocName=ABC000001&Rendition=Web">

Above line is part of html displayed on web browser

    however, I want to execute this line inside my java code

    Something like Execute --> http://localhost:80/cs/idcplg?IdcService=CREATE_STATIC_RENDITION&dDocName=ABC000001&Rendition=Web

Answers

  • BrianV
    BrianV Member Posts: 86 Blue Ribbon

    You probably should consider servlets....


    However brutal way....


    <span class="kwd" style="color: #00008b;">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">net</span><span class="pun">.*;</span><span class="pln"><br/></span><span class="kwd" style="color: #00008b;">import</span><span class="pln"> java</span><span class="pun">.</span><span class="pln">io</span><span class="pun">.*;</span><span class="pln"><br/><br/></span><span class="kwd" style="color: #00008b;">public</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">class</span><span class="pln"> </span><span class="typ" style="color: #2b91af;">URLConnectionReader</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>  </span><span class="kwd" style="color: #00008b;">public</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">static</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">void</span><span class="pln"> funk</span><span class="pun">(</span><span class="typ" style="color: #2b91af;">String</span><span class="pun">[]</span><span class="pln"> args</span><span class="pun">)</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">throws</span><span class="pln"> </span><span class="typ" style="color: #2b91af;">Exception</span><span class="pln"> </span><span class="pun">{</span><span class="pln"><br/>  URL myUrl </span><span class="pun">=</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">new</span><span class="pln"> URL</span><span class="pun">(</span><span class="str" style="color: #800000;">"<a class="jive-link-external-small" href="http://localhost/cs/idcplg?IdcService=CREATE_STATIC_RENDITION&dDocName=ABC000001&Rendition=Web" style="font-family: 'Helvetica Neue', Helvetica, Arial, 'Lucida Grande', sans-serif; color: #1f4f82;">http://localhost:80/cs/idcplg?IdcService=CREATE_STATIC_RENDITION&dDocName=ABC000001&Rendition=Web</a>"</span><span class="pun">);</span><span class="pln"><br/>   </span><span class="typ" style="color: #2b91af;">URLConnection</span><span class="pln"> yc </span><span class="pun">=</span><span class="pln"> <span style="font-family: Consolas, Menlo, Monaco, 'Lucida Console', 'Liberation Mono', 'DejaVu Sans Mono', 'Bitstream Vera Sans Mono', 'Courier New', monospace, serif;">myUrl</span></span><span class="pun">.</span><span class="pln">openConnection</span><span class="pun">();</span><span class="pln"><br/>   </span><span class="typ" style="color: #2b91af;">BufferedReader</span><span class="pln"> in </span><span class="pun">=</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">new</span><span class="pln"> </span><span class="typ" style="color: #2b91af;">BufferedReader</span><span class="pun">(</span><span class="pln"><br/>   </span><span class="kwd" style="color: #00008b;">new</span><span class="pln"> </span><span class="typ" style="color: #2b91af;">InputStreamReader</span><span class="pun">(</span><span class="pln"><br/>  yc</span><span class="pun">.</span><span class="pln">getInputStream</span><span class="pun">()));</span><span class="pln"><br/>   </span><span class="typ" style="color: #2b91af;">String</span><span class="pln"> inputLine</span><span class="pun">;</span><span class="pln"><br/><br/>   </span><span class="kwd" style="color: #00008b;">while</span><span class="pln"> </span><span class="pun">((</span><span class="pln">inputLine </span><span class="pun">=</span><span class="pln"> in</span><span class="pun">.</span><span class="pln">readLine</span><span class="pun">())</span><span class="pln"> </span><span class="pun">!=</span><span class="pln"> </span><span class="kwd" style="color: #00008b;">null</span><span class="pun">)</span><span class="pln"> <br/>   </span><span class="typ" style="color: #2b91af;">System</span><span class="pun">.</span><span class="pln">out</span><span class="pun">.</span><span class="pln">println</span><span class="pun">(</span><span class="pln">inputLine</span><span class="pun">);</span><span class="pln"><br/>  in</span><span class="pun">.</span><span class="pln">close</span><span class="pun">();</span><span class="pln"><br/>  </span><span class="pun">}</span><span class="pln"><br/></span><span class="pun">}</span>

    BrianV
  • Balu LEO
    Balu LEO Member Posts: 105
    edited Dec 27, 2013 5:33PM

    Another approach implementing this using JavaScript and Java Code in BackingBean.

    You need to have a commandLink or commandButton and point target to the external link.

    Let the link or button be hidden and fire/trigger the action using java code.

    Action Flow:

    Invoke JavaScript Method from Java Code --> JavaScript will invoke Hidden Button/Link Action

    function triggerAction(compID)
                          {                                              
                              var comp_id= AdfPage.PAGE.findComponentByAbsoluteId(compID);
                              var actionEvent = new AdfActionEvent(comp_id);
                              actionEvent.forceFullSubmit();
                              actionEvent.noResponseExpected();
                              actionEvent.queue();
                          }
    
    
    Balu LEO
This discussion has been closed.