File: JSPLikeInNetRexx.java

package info (click to toggle)
libbsf-java 1%3A2.3.0%2Bcvs20050308-2
  • links: PTS
  • area: contrib
  • in suites: sarge
  • size: 1,444 kB
  • ctags: 1,264
  • sloc: java: 7,643; cpp: 2,514; xml: 1,786; jsp: 463; ansic: 182; makefile: 59; python: 45; sh: 29
file content (75 lines) | stat: -rw-r--r-- 3,192 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
// program to illustrate use of BSF in a JSP-generated servlet
// like scenario. The model is there's a series of Java code pieces
// intermixed with a series of NetRexx code pieces.

import org.apache.bsf.*;

public class JSPLikeInNetRexx {
  BSFManager mgr = new BSFManager ();
  { mgr.setTempDir ("/tmp"); } // test the tmp dir stuff
//{ mgr.setDebug (true); }
  BSFEngine rexx;

  /* assume that the JSP page is compiled into the constructor:
     intermix java and javascript code now. The .jsp could've looked
     like the following (I'm accepting Sanjiva's guesses about syntax here.).
     I'm assuming that language was set to NetRexx somewhere before.

     Unlike Javascript, standard NetRexx doesn't have the concept of a
     default persistant execution environment. Any data to be stored
     between NetRexx invocations has to be explicitly placed in a
     Property if it's local (which, given the way the NetRexx binding
     has been done in this prototype, means working with minor
     classes) or stashed in the BSF environment's registry if it's
     global. Neither is needed for this simple example; obtaining a
     new Date is painless (we'd need to provide the classname for the
     variable anyway) and "response" is already in the registry.

       <html>
       <head><title>JSPLike</title></head>
       <body>
       <h1>Welcome at <%= return java.util.Date().toString %></h1>
       stuff
       Response bean's length is: <%= 
           return (java.lang.String bsf.lookupBean('response')).length %>
       Response bean's uppercase value is: <%=
           return (java.lang.String bsf.lookupBean('response')).toUpperCase () %>
       <h5>Page generation done at <%= return java.util.Date().toString() %></h5>
       </body>
       </html> */
  public JSPLikeInNetRexx () throws BSFException {
    rexx = mgr.loadScriptingEngine ("netrexx");

    System.out.println("<!- Using "+rexx.eval ("", 0, 0,"Version")+" ->");
    
    // first register the response bean into the runtime 
    mgr.registerBean ("response", new String ("howdy-doody"));

    Object result;

    System.out.println ("<html>");
    System.out.println ("<head><title>JSPLike</title></head>");
    System.out.println ("<body>");
    
    System.out.print ("<h1>Welcome at ");
    result = rexx.eval ("", 0, 0,"java.util.Date().toString()");
    System.out.println (result + "</h1>");
    System.out.println ("stuff");
    System.out.print ("Response bean's length is: ");
    result = rexx.eval ("", 0, 0,"java.lang.Integer((java.lang.String " +
                                 "bsf.lookupBean('response')).length)");
    System.out.println (result);
    System.out.print ("Response bean's uppercase value is: ");
    result = rexx.eval ("", 0, 0,"(java.lang.String bsf.lookupBean('response')).toUpperCase()");
    System.out.println (result);
    System.out.print ("<h5>Page generation done at ");
    result = rexx.eval ("", 0, 0,"java.util.Date().toString()");
    System.out.println (result + "</h5>");
    System.out.println ("</body>");
    System.out.println ("</html>");
  }
  
  public static void main (String[] args) throws Exception {
    new JSPLikeInNetRexx ();
  }
}