RSS구독하기:SUBSCRIBE TO RSS FEED
즐겨찾기추가:ADD FAVORITE
글쓰기:POST
관리자:ADMINISTRATOR

JSP & PHP with EASE

by Ahmad Baitalmal
published on: 07/05/2006


Inter-mingling JSP and PHP code inside EASE is extremely simple. You can use JSP/PHP code inside your EASE script to leverage any existing code you might already have or extent the platform with third party libraries and capabilities.

The Etelos Application Server platform allows you to drop in and out of PHP/JSP code seamlessly. Below is an example of how you can access any EAS binder variable.

< #[SYSTEM.DATE_TIME]#> <
br>
<?php
print eas_get_value( "system.date_time" ) ."<br>";
?>

<?jsp

<%= eas_get_value("system.date_time") "<br/>"%>

?>



The three lines in the code above will produce identical output. You have full un-crippled access to PHP & JSP. You can interact with EAS data in real-time and see your changes on the fly. The following code creates a new binder tag in PHP  and prints it out in EASE.

<?php
print eas_set_value( "my.data", "right here" );
?>

My data is <b></b><br>

As expected, the output is:

My data is right here

Or in JSP:
<?jsp
<% eas_set_value( "my.data", "right here" )%>
?>

My data is <b>< #[MY.DATA]#></b><br>

EASE skips much of the grunt work usually required in web development. With the PHP/JSP interfaces, you can still do all the fine-grained coding that you may need. For example, you may need to update a few binder instances real quick without user interaction. While eas_set_value and eas_get_value give you access to the EAS tag data in real-time, after the page execution is done, your changes aren't saved to the database. Here is how you modify the actual data in contacts and instances in PHP:

<?php
eas_set_instance_value( "products.6", "color", "Tomato");
eas_set_contact_value( eas_get_value("contact.id"), "age", "33");
?>

< # apply instance products.6 and reference as "product". # >
The product color is < #[product.color]# >
<br>

The instance's color variable is changed in the database to "Tomato" and the < # [contact.id] # >'s age variable is changed to "33". In the opposite direction, you can load an instance or contact from the database like this:

<?php
print_r( eas_get_instance( "products.6" ) );
print_r( eas_get_contact( eas_get_value("contact.id") ) );
?>


This code will print two arrays. The first array is an associative array of variable=>value for instance id 6 from the products binder. The next array is also an associative array of variable=>value for the < # [contact.id] # >.

The following code goes a little bit further. eas_query enables you to write your own SQL queries to the database.
<?php
$result = eas_query( "select * from binder_12 where lower( color ) != 'red';" );
if( $result->ok )
{
    print "<u>". $result->count ."</u> products were found\n";    
    print "<u>". $result->updated ."</u> products were updated\n";    
    while( $product = pg_fetch_assoc($result->recordset) )
    {
        print "<b>". $product['instance_id'] . " - " . $product['name'] . "</b>\n";
        print $product['color'] ."\n";
        print $product['description'] ."\n\n";
    }
}
?>


In this example, a query is issued to return all products (binder_12) where the color is not red. The result object that is returned provides a few useful properties.

$result->ok is true when the query is executed successfully, otherwise it's false. $result->count has the number of rows returned, and $result->updated has the number of rows that were updated if the query was an UPDATE.



Here is the same code in JSP:
<?jsp

<%
   try
   {
       ResultSet rs = eas_query( "select * from binder_12;" );
       Statement st = rs.getStatement();
             rs.last();
       int count = rs.getRow();
       rs.beforeFirst();
             int updateCount = st.getUpdateCount();
%>
       <%="<u>" count "</u> products were found<br/>"%>
       <%="<u>" updateCount "</u> products were updated<br/>"%>
<%
       while( rs.next() )
       {
%>
           <%="<b>" rs.getString( "instance_id" ) "-" rs.getString( "name" )
               "</b><br/>"%>
           <%=rs.getString( "color" ) "<br/>"%>
           <%=rs.getString( "description" ) "<br/><br/>"%>
<%
       }          st.close();
   }
   catch( Exception e ) {}
%>

?>


You can easily imagine doing some more advanced queries that would be hard or inefficient to do in the standard list engine like unions or intersects. Having the full power and flexibility of PHP and JSP is also a big plus, you have the speed of rapid web application development with EASE and the flexibility and extensibility of PHP and JSP all in a single page.




//  This following example is not featured int he magazine because of space in the printed edition.  Here is an extra example of setting contact values in JSP.

<?jsp
<%@ page import="java.util.*" %>

<%=eas_set_contact_value( "2330c69b9fab0cfe170fad0a95e8f7f8", "last_name", "Changed!" )%>

<%
   Map m = eas_get_contact( "2330c69b9fab0cfe170fad0a95e8f7f8" );
   Iterator i = m.keySet().iterator();
   String result = "";
   while( i.hasNext() )
   {
       Object key = i.next();
       Object val  = m.get( key );
             result = key.toString() ":" val.toString() "<br/>";
   }
%>

<%="<br/><br/>result:<br/>" result%>

?>


Relevent Tags: EASE tips   PHP Dev   JSP Dev   

2009/11/10 11:51 2009/11/10 11:51
이 글에는 트랙백을 보낼 수 없습니다
웅쓰:웅자의 상상플러스
웅자의 상상플러스
전체 (379)
게임 (5)
영화 (2)
기타 (23)
맛집 (5)
영어 (2)
대수학 (3)
형태소 (5)
Hacking (9)
Linux (112)
HTML (48)
Application_developing (48)
Web_developing (102)
Window (11)
«   2024/12   »
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        
  1. 2016/01 (1)
  2. 2015/12 (3)
  3. 2015/10 (3)
  4. 2015/03 (2)
  5. 2015/01 (4)