{"id":578,"date":"2004-03-15T22:47:07","date_gmt":"2004-03-16T02:47:07","guid":{"rendered":"http:\/\/wordpress.cephas.net\/?p=578"},"modified":"2004-03-15T22:47:07","modified_gmt":"2004-03-16T02:47:07","slug":"scripting-in-asp-with-java","status":"publish","type":"post","link":"https:\/\/cephas.net\/blog\/2004\/03\/15\/scripting-in-asp-with-java\/","title":{"rendered":"Scripting in ASP with Java"},"content":{"rendered":"<p>I&#8217;m working on a project right now that involves a store written in Java using <a href=\"http:\/\/jakarta.apache.org\/struts\/\">Struts<\/a> and a sister site written in <a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/iissdk\/iis\/iis_web_pages.asp?frame=true\">ASP<\/a>. One of the features of the store requires that the sister site use some logic written in Java, which you might think is impossible. Turns out (doesn&#8217;t it always?) that you can quite easily use simple Java methods and objects within ASP from VBScript.  I found two articles (and really only 2) that introduced the use of a simple Java class from ASP (which you can read <a href=\"http:\/\/www.4guysfromrolla.com\/webtech\/080999-1.shtml\">here<\/a> and <a href=\"http:\/\/www.4guysfromrolla.com\/webtech\/081199-2.shtml\">here<\/a>).  Here&#8217;s a Hello World example:<br \/>\n<code><br \/>\npackage org.mycompany;<br \/>\npublic class TestClass {<br \/>\n&nbsp;public String sayHello(String name) {<br \/>\n&nbsp;&nbsp;&nbsp;return \"Hello \" + name;<br \/>\n&nbsp;}<br \/>\n}<br \/>\n<\/code><br \/>\ncompile this and then you save the resulting class file to:<br \/>\n<code>%Win%\/Java\/TrustLib\/%package%\/%classname%.class<\/code><br \/>\nSo the above example would result in a file saved as:<br \/>\n<code>%Win%\/Java\/TrustLib\/org\/mycompany\/TestClass.class<\/code><br \/>\nFrom ASP, you can then use the following syntax:<br \/>\n<code><br \/>\nDim obj<br \/>\nset obj = GetObject(\"java:org.comcompany.TestClass\")<br \/>\nresult = obj.sayHello(\"Aaron Johnson\");<br \/>\nResponse.Write(result)<br \/>\nset obj = nothing<br \/>\n<\/code><br \/>\nCouple of items of note: <\/p>\n<p>a) the use of what Microsoft calls a &#8220;<a href=\"http:\/\/msdn.microsoft.com\/library\/default.asp?url=\/library\/en-us\/iissdk\/iis\/implementingwithvisualj.asp?frame=true\">Java Moniker<\/a>&#8221; allows you to use a Java class without first registering it with the system, which is nice (so you got that going for ya), <\/p>\n<p>b) just like a servlet container, if you make changes to the Java class file while the application is running, you must restart the container, which in this case is IIS, <\/p>\n<p>c) you must (as I mentioned before) make sure to place the compiled class file in the appropriately named subdirectory of %Win%\/Java\/TrustLib\/, where %Win% is usually C:\\windows\\ or C:\\winnt\\, <\/p>\n<p>d) you can&#8217;t use static methods in your Java class if you want to be able to call those methods from VBScript. It appears (from my quick attempts) that the VBScript engine first creates an object using the default constructor and then calls the given method on that instance.  Modifiying the method to be static resulted in a runtime error, and finally<\/p>\n<p>e) your code must work in the Microsoft JVM (I think), which <a href=\"http:\/\/www.microsoft.com\/mscorp\/java\/\">isn&#8217;t being supported past September 2004<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I&#8217;m working on a project right now that involves a store written in Java using Struts and a sister site written in ASP. One of the features of the store requires that the sister site use some logic written in Java, which you might think is impossible. Turns out (doesn&#8217;t it always?) that you can &hellip; <a href=\"https:\/\/cephas.net\/blog\/2004\/03\/15\/scripting-in-asp-with-java\/\" class=\"more-link\">Continue reading <span class=\"screen-reader-text\">Scripting in ASP with Java<\/span> <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":[],"categories":[11,3,2],"tags":[],"_links":{"self":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/578"}],"collection":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/comments?post=578"}],"version-history":[{"count":0,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/posts\/578\/revisions"}],"wp:attachment":[{"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/media?parent=578"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/categories?post=578"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/cephas.net\/blog\/wp-json\/wp\/v2\/tags?post=578"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}