# application getserverurl and webclient

**URL:** <https://forum.servoy.com/t/application-getserverurl-and-webclient/9495>\
**Category:** Classic Servoy\
**Created:** [August 25, 2008, 12:45pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495 "2008-08-25T12:45:16Z")\
**Posts on this page:** 11\
**Page:** 1

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [August 25, 2008, 12:45pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/1 "2008-08-25T12:45:16Z")

</div>

When i’m using the function application.getServerUrl in a web client, servoy gives me localhost:8099 (my servoyport) and not the real name of my server.

Is it a bug or must i change something in my configuration?

Servoy 357

---

<div class="post-metadata">

**Author:** ![Joas](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/joas/32/5095_2.png) [@Joas](https://forum.servoy.com/u/Joas)\
**Post date:** [August 25, 2008, 3:08pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/2 "2008-08-25T15:08:35Z")

</div>

A web client is running ON the server, so that’s why it returns localhost. To get the actual ip of the server, you can do something like this:```  
plugins.http.getPageData(“[IP Address API](http://www.whatismyip.com/automation/n09230945.asp)”);

```auto

```

---

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [August 25, 2008, 4:20pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/3 "2008-08-25T16:20:51Z")

</div>

I generate temp pdf file report with jasper in the servoyroot/web-client/tempdirectory and then i do a showurl of the temppddfile.

I think so that i must put the server url in a global var of my application.

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [August 25, 2008, 6:32pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/4 "2008-08-25T18:32:03Z")

</div>

With the latest version of the JasperReports plugin, you can just use the “view” option in the WC and a PDF will be automatically generated and pushed to the WC.

Paul

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [August 25, 2008, 6:34pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/5 "2008-08-25T18:34:30Z")

</div>

Paul, can you tell which ireport version is still 100% compatible with the jasper report plugin?

---

<div class="post-metadata">

**Author:** ![pbakker](https://avatars.discourse-cdn.com/v4/letter/p/a4c791/32.png) [@pbakker](https://forum.servoy.com/u/pbakker)\
**Post date:** [August 26, 2008, 6:58am UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/6 "2008-08-26T06:58:01Z")

</div>

The JasperReports plugin is compatible with all versions of JasperReports.

You just have to make sure that the JasperReports libraries that the JasperReports plugin uses are the same or a higher version than the ones iReports uses.

The latest version of the plugin (2.1.1) can be downloaded as a complete package with all the libraries of JasperReports version 3.0, which iReports 3.0 also uses.

Paul

---

<div class="post-metadata">

**Author:** ![Harjo](https://yyz2.discourse-cdn.com/flex010/user_avatar/forum.servoy.com/harjo/32/4873_2.png) [@Harjo](https://forum.servoy.com/u/Harjo)\
**Post date:** [August 26, 2008, 11:15am UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/7 "2008-08-26T11:15:53Z")

</div>

oke thanks!

---

<div class="post-metadata">

**Author:** ![erdione](https://avatars.discourse-cdn.com/v4/letter/e/e9a140/32.png) [@erdione](https://forum.servoy.com/u/erdione)\
**Post date:** [August 26, 2008, 11:18am UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/8 "2008-08-26T11:18:04Z")

</div>

Thanks Paul for this feature  
It Works like a charme in the webclient.

---

<div class="post-metadata">

**Author:** ![amcgilly](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@amcgilly](https://forum.servoy.com/u/amcgilly)\
**Post date:** [April 17, 2009, 7:58am UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/9 "2009-04-17T07:58:54Z")

</div>

Servoy 4.1.1, FireFox, WinXP

I have a related question.

My solution generates pdfs and stores them in the database. In the smart client, when I want to display the pdf I am saving it to a temp file (tempFile) and then using this code I found in one of Bob Cusick’s demos to display the PDF in Acrobat Reader:

```auto
if(utils.stringMiddle(application.getOSName(),1,7) == "Windows") 
{ 
   application.executeProgram('rundll32', 'url.dll,FileProtocolHandler',tempFile) 
}
else if(utils.stringMiddle(application.getOSName(),1,7) == "FreeBSD"||utils.stringMiddle(application.getOSName(),1,5) == "Linux") 
{ 
   application.executeProgram('mozilla', tempFile) 
}
else if(utils.stringMiddle(application.getOSName(),1,6) == "Mac OS") 
{ 
   application.executeProgram('open', tempFile) 
}

```

But this isn’t working in the web client. In the Web Client, this causes the PDF to open on the server!

What’s the correct procedure to display a db-stored pdf file in the web client? I don’t care whether it’s in the browser or in its own Acrobat window.

I’ve tried this, thinking at least this would work in Developer, if not on the server, but it doesn’t work.

```auto
function btnShowPDF()
{

var tempFile = plugins.file.createTempFile('SmartTrash','.pdf') //creates empty temporary file
application.writeFile(tempFile,hauls_to_haul_po_pdfs.pdf) // writes the media field to file
	
tempFile = utils.stringReplace(tempFile,'\\','\/')  
application.showURL('file:///'+tempFile,'_blank')
}
}

```

I’ve also read Westy’s advice here: [http://www.servoy.com/forum/viewtopic.p … 8&start=15](http://www.servoy.com/forum/viewtopic.php?f=3&t=12028&start=15) but that seems to be for a deployed solution - what about just getting it to work in Developer for starters?

Please help! Thank you.

---

<div class="post-metadata">

**Author:** ![bobcusick](https://avatars.discourse-cdn.com/v4/letter/b/ba9def/32.png) [@bobcusick](https://forum.servoy.com/u/bobcusick)\
**Post date:** [April 18, 2009, 1:06pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/10 "2009-04-18T13:06:20Z")

</div>

Dean’s answer [http://www.servoy.com/forum/viewtopic.p … 8&start=15](http://www.servoy.com/forum/viewtopic.php?f=3&t=12028&start=15) IS the way you do it. Even in developer. Remember, when you’re in developer, you ARE deployed and the Tomcat web server is running (that’s how you get a web client in the first place).

Use Dean’s method and it should work just fine.

---

<div class="post-metadata">

**Author:** ![amcgilly](https://avatars.discourse-cdn.com/v4/letter/a/e0b2c6/32.png) [@amcgilly](https://forum.servoy.com/u/amcgilly)\
**Post date:** [April 20, 2009, 10:55pm UTC](https://forum.servoy.com/t/application-getserverurl-and-webclient/9495/11 "2009-04-20T22:55:59Z")

</div>

> [Dean’s answer](http://www.servoy.com/forum/viewtopic.php?f=3&t=12028&start=15) IS the way you do it. Even in developer. Remember, when you’re in developer, you ARE deployed and the Tomcat web server is running (that’s how you get a web client in the first place).

OK I figured it out. Dean’s method does not work in developer, and that’s because when he does this:

```auto
var installdir = java.lang.System.getProperty("user.dir")

```

under developer this returns ‘C:\Servoy\developer’. In order to work, it needs to return ‘C:\Servoy\application\_server’

So in order to have a single method that works in both server and developer I guess I could test if the word ‘developer’ appears in installdir and if so replace it with ‘application\_server’ … not very elegant but it works … got any other ideas?

Here’s what Dean’s method looks like now:

```auto
if (application.getApplicationType() == 5) // web client
{
   var installdir = java.lang.System.getProperty("user.dir")

// to make it work in Developer we need to redirect this path to the application_server folder
   installdir = utils.stringReplace(installdir,'developer','application_server')

   installdir = utils.stringReplace(installdir,'\\','\/');//original code edited to include this line
   var uuid =application.getNewUUID();
   var filename = uuid+'.pdf';
   var filepath = installdir+'/server/webapps/ROOT/'+filename;
   var success = plugins.file.writeFile(filepath,hauls_to_haul_po_pdfs.pdf);
   application.output('filepath=' + filepath +' filename='+filename)
   if (success)
   {
      application.showURL('/'+filename,'_blank')
   }
}

```
