Archive for November, 2007

726Part IVConnectionsSimilar code using (Web server logs) PHP would, by necessity,

Friday, November 30th, 2007

726Part IVConnectionsSimilar code using PHP would, by necessity, be a bit more involved. Create a new PHP filecalled javatest.phpand insert the following: getProperty( java.version ); $os = $system->getProperty( os.name ); ?> Fun with Java and JSP

We are running Java version on the platform, and it s working!

With luck, your browser will output something like the following when you access javatest.php: We are running Java version 1.4.0 on the Linux platform, andit s working! If not, it s time to troubleshoot! Consult the PHP manual or other resources listed in AppendixD for help and suggestions. The Java objectThe Javaobject becomes available with installation of the Java extension, and is used toinstantiate a Java class within PHP. The format is: new Java(class, parameters) where classis the class being invoked and the parameters are arguments to be passed to thatobject s constructor. Parameters are optional, providing a default constructor is available. It s important to note that no Java packages are available to PHP by default. Although, as in the previous example, the java.lang.*package is always available to Java and JSP andtherefore does not need to be referenced implicitly, the complete package and class namemust always be specified from within PHP. The previous example was a simple one, since we provided no arguments to the Systemclass. Systemcannot be instantiated in Java and is referenced through static methods just as getProperty(). Let s take a look at a more involved example. With the deprecation of several Date()constructors, time reporting and formatting grew incomplexity in Java. Here s an example in which we print the current date and time in JSP: <% Calendar cr = new Calendar(); String date_time = yyyy-MM-dd HH:mm:ss ; Note44
Searching for affordable and reliable webhost to host and run your web applications? Go to our java web server services and you will be pleased.

725Chapter 39PHP and JavaJava support is (Best web design) not enabled

Friday, November 30th, 2007

725Chapter 39PHP and JavaJava support is not enabled by default, and you will need to rebuild PHP in order to takeadvantage of its features. During the installation, you must specify the option with- java=(basedirectory)in addition to any other options you may require. (See Chapter 3for more information on building and installing PHP.) Modifications are also required to the php.iniconfiguration file in order to enable the exten- sion. Open your php.inifile in your favorite editor and search for the [Java]subheadingunder Module Settings. Here s where the information you collected earlier will come inhandy. A typical modification on a Linux server might look something like this: [java] java.home = /usr/java/j2sdk1.4.0java.library = /usr/java/j2sdk1.4.0/jre/lib/i386/libjava.sojava.library.path = /usr/lib/php/extensions/no-debug-non-zts- 20020429extension_dir = /usr/lib/php/extensions/no-debug-non-zts- 20020429extension=libphp_java.soWindows users should also add the following line under Windows Extensions: extension=php_java.dllJust to add some confusion for fun, note that the java.libraryvariable pertains to theJava installation, while java.library.pathrefers to the PHP extension directory wherethe optional PHP support files reside. Most problems with getting the Java extension to workseem to revolve around successfully editing php.ini. Remember that these variables must correspond to the settings on your particular server. Windows users must be sure to enclose the path names in quotations. If all goes well, you should be ready to try calling a Java method from within PHP! TestingA simple invocation of java.lang.Systemin a JSP environment would look something like this: <% String version = System.getProperty( java.version ); String os = System.getProperty( os.name ); %> Fun with Java and JSP

We are running Java version <%= version %> on the <%= os %> platform, and it s working!

CautionNote44
From our experience, we can recommend PHP5 Web Hosting services, if you need affordable webhost to host and run your web application.

724Part IVConnectionsbuilding and installing PHP.) In your (Free web hosting music) environment

Thursday, November 29th, 2007

724Part IVConnectionsbuilding and installing PHP.) In your environment variables, make sure that servlet.jarisincluded in your CLASSPATHand add the PHP directory containing the libphp4.sofile toLD_LIBRARY_PATH. Windows users will need to build and copy the php_java.dllfile into their extension_dirdirectory and enable the extension in the php.inifile. Also be sure that servlet.jarisincluded in your CLASSPATHand add the PHP directory containing the PHP DLL files to PATH. Building the module will also create a JAR file called phpsrvlt.jar, which must also beincluded in your CLASSPATH. Additional setup specific to your servlet engine will probably berequired. Check the PHP Web site and mailing lists for comments from other users who havesuccessfully configured your Java servlet engine for use with this module. Further informationOnce you have the module up and running, you should be able to view php files as normal. Point to an existing PHP page, or create a test by printing phpinfo()to see if you have succeeded. Usage of this module is still considered experimental, and there isn t a lot of documentation. You probably won t build or use this module unless you already have a specific need for it. Asthe module is under constant revision, additional useful notes may be found in the READMEfile and other sources located in your PHP directory under /sapi/servlet. Users also some- times add comments to the User Contributed Notes in the online manual, so it s probably agood idea to check there every so often. Official notes on Java/PHP integration can be foundon the PHP Web site at www.php.net/manual/en/ref.java.php. The Java extensionIf you re feeling particularly adventurous, you can build Java support directly into PHP usingthe experimental Java extension. Once enabled, the extension allows you to create and callJava objects and methods from within PHP. The advantages are obvious for the Java-familiar, but use of this extension is not without some pain upfront and some serious care on your part. The Java extension for PHP is subject to continuing revision as it is fine-tuned for future ver- sions. Committing to use of this feature in your application implies added diligence to avoidfuture code breakage. It s not labeled EXPERIMENTAL in the PHP manual for nothing! Installation and setupUse of the Java extension will require some modifications to your PHP installation and envi- ronment. Before rebuilding PHP, it s a good idea to make sure you have access to pertinentinformation on your Java Development Kit (JDK) environment. Make sure that you know thefollowing information: .The base directory of your JDK installation (typically /usr/java/j2sdk in Linux) .The JAVA_HOMEand CLASSPATHenvironment variables (JAVA_HOMEshould be set tothe above directory) .Location of the Java library (typically in JAVA_HOME/jre/lib/i386on Linux) Caution44
You want to have a cheap webhost for your apache application, then check apache web hosting services.

723Chapter 39PHP and JavaChapterChapter TitleVerdict?Notes7Passing Information Somewhat familiarSpecific (Web hosting compare)

Wednesday, November 28th, 2007

723Chapter 39PHP and JavaChapterChapter TitleVerdict?Notes7Passing Information Somewhat familiarSpecific to Web-scripting. Will be between Pagesfamiliar if you have used JSP. 8StringsMostly familiarMany behavior differences andtyping concerns. 9ArraysSomewhat familiarPHP arrays share some similarities, but with different behavior. 10NumbersFamiliarPHP s two numerical types, corresponding to the long anddouble types. 11Basic PHP GotchasNovelAlmost no correlation with compiletime and runtime error checking in Java. Integrating PHP and JavaIn the course of your development work, you may run across a situation in which you will be required to use PHP and Java together, or this combination may prove advantageous forsome reason. You basically have two options to accomplish this tricky undertaking, both ofwhich are outlined below. Java environments are inherently complicated and vary accordingto servlet engine and server. Since these issues are well beyond the scope of this book, in allfurther discussions we will assume that you already have a working Web server that supportsservlets, an installed Java virtual machine (JVM), and a working familiarity with Java. The Java SAPIThe most stable solution is to integrate PHP into a Java Servlet environment using the JavaService Access Point Identifier (SAPI). This allows the PHP processor to run as a servlet andbuilds upon the PHP Java extension (described following). The servlet will run from within aJava servlet engine, such as Apache Tomcat. Though the Java servlet SAPI module will theoretically run on any of a number of availableservlet engines, the PHP team has only tested the code using Apache s Jakarta Tomcatservlet engine. Your mileage may vary if you have implemented another engine such asCaucho s Resin or IBM s WebSphere. Any environmental differences may require adjust- ments, and you are essential on your own. The PHP team encourages brave souls who tri- umph over other servlet engines to submit bugs and found fixes to the PHP DevelopmentMailing List. (See Appendix D for more information on PHP mailing lists.) Installation and setupAs with the Java extension, SAPI module support is not built into PHP by default. You willneed to rebuild PHP with the necessary options (–with-servlet-withjava) as well asany other options you may require for other uses. (See Chapter 3 for more information onNote44
Please visit our professional web hosting services to find out about cheap and reliable webhost service that will surely answer all your demands.

Abyss web server - 722Part IVConnections Pages can freely alternate between HTML

Wednesday, November 28th, 2007

722Part IVConnections

Pages can freely alternate between HTML and JSP, just as in using HTML and PHP. Choose your scripting languagePHP can actually be used with Java in lieu of JSP, though support is much less robust andsubject to change in future releases. Many of the shortcutsavailable to JSP are not availablethrough PHP. For example, many of the standard Java class packages are automatically avail- able as in Java Server Pages, but must be implicitly referenced using PHP Java support. Don t let new syntax and structure similarities lull you into believing that PHP is truly likeJava. The forgiving nature of PHP and the loose treatment of variable typing mean that codemust be treated very differently. Those errors that Java demanded you to fix before it wouldcompile may not show up in PHP until they are in an end user s browser! Guide to this bookAs with the similar sections for C Programmers (Appendix A) and Perl hackers (Appendix B), Table 39-1 labels the chapters of Part I according to how familiar they are likely to be to Javaprogrammers. Table 39-1: Guide to Part I for Java ProgrammersChapterChapter TitleVerdict?Notes1Why PHP and MySQL?NovelThe chapter you need to justify PHPto your boss. 2Server-side Web ScriptingSomewhat familiarImportant if you have not seen Web-scripting languages before. PHP bears many similarities to JavaServer Pages (JSP). 3Getting Started with PHPNovelInstallation, hosting, and so on. 4Adding PHP to HTMLNovel but easy Hello world for PHP. 5Syntax and VariablesSomewhat familiarSome syntactic similarities exist. Some will be unfamiliar, especiallythe way in which variables aretreated. 6Control and FunctionsSomewhat familiarMany of the PHP control structures(if, while, for) work similarly to Java, with important differences, such as functions and variablescoping. Caution44
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

Business web hosting - 721Chapter 39PHP and Javaor: String preamble = We,

Tuesday, November 27th, 2007

721Chapter 39PHP and Javaor: String preamble = We, the people… ; the corresponding PHP code would be simply: $preamble = We, the people… ; PHP utilizes dynamic typing; the variable has no intrinsic type and can change with each newstatement. While the following code is perfectly legal in PHP: $type = 11; $type = 11 ; you would need to use separate variables in Java, or attempt to recast the variable as aString, with potential problems and resultant performance hit. Though type hinting has been introduced in PHP5, it does not yet apply to data types. Variables can be declared and typed as in Java, but this is not required in PHP. Java Server Pages and PHPPHP can fulfill many functions similarly to Java Server Pages (JSP). The JSP servlet engineserves as a scripting language for use with Java, and, just as PHP, is often used in front endapplications. Embedded HTMLPHP is more similar to JSP than Java itself in that you are allowed to write HTML directlyrather than using endless printstatements. Unlike Java, but like JSP, variables can also bereferenced from within a block of HTML. A simple HTML page using JSP script might look like this: <% String greeting = Hello, world ; %> Fun with JSP

<%= greeting %>

Similarly, using PHP, you can write: Fun with PHP
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

720Part IVConnectionsOperatorsThe assignment operators (=, +=, *=, and (Web design tools)

Monday, November 26th, 2007

720Part IVConnectionsOperatorsThe assignment operators (=, +=, *=, and so on), the Boolean operators (&&,||, !), and thebasic arithmetic operators (+, -, *, /, %) all behave as they do in Java. Other operators aresimilar, with some syntax differences. The string concatenation operator, for example, in PHPis a period (.) rather than a plus sign (+) as in Java. Object modelThe Java programmers coming to PHP with version 5 can rejoice! You no longer need tounlearn your approach to OOP in order to deal with the often crude OOP support in PHP4and earlier versions. With recent changes, the object model in PHP has moved closer toJava s. PHP5 now supports interfaces, and sports a limited version of object overloading. Theaddition of keywords (such as private, protected, and public) for dealing with membervariables should also prove familiar to Java coders. New error handling methods, includingthe built-in Exceptionclass, also seem to borrow a page from Java. See Chapter 20 for much more detailed information about PHP5 s new object model. Memory managementUnder normal circumstances, PHP s garbage-collected environment ensures that you do notneed to explicitly free allocated memory. If you re used to Java s mostly automated garbage- collected heap, you ll be right at home here. Packages and librariesMany Web-specific libraries are built into PHP and are available by default or with minorchanges. This works similarly to the standard Java packages that are available through JARfiles and CLASSPATHreferences. DifferencesThough many of the new features of PHP5 have a Java-like feel, there are plenty of notableexceptions to the way Java and PHP operate. As a general rule, never assume that a Java feature or concept will carry over completely into PHP. Compiled versus scriptingUnlike Java, PHP is a scriptinglanguage. The development cycle is edit-executerather thanedit-compile-execute, as in Java. PHP code is automatically compiled at execution time anddoes not produce native standalone executables. As a result, the developer is not subjectedto rigorous compile time error checking as in Java; many of the errors that you are used toseeing at compile time will not rear their ugly heads until the code is executed in PHP. Variable declaration and loose typingGet used to that leading $. Unlike in Java, all variables in PHP must begin with a $. Variablesneed not be declared before use, nor cast to a different type as in Java. Rather than the Java code: String preamble = new String(); Preamble = We, the people… ; Cross- Reference44
In case you need quality webspace to host and run your web applications, try our personal web hosting services.

My web server - PHP and JavaThe relationship between PHP and Java

Sunday, November 25th, 2007

PHP and JavaThe relationship between PHP and Java has changed significantlywith each new release. Unsurprisingly, given the source code, PHPinitially had much more in common with C. PHP4 supported integra- tion of PHP and Java using a Java Servlet environment or, more exper- imentally, directly into PHP. Finally, with the overhaul of the objectmodel in PHP5, there s a distinctly Java feel to the PHP approach toobject oriented programming. Java users will find much of PHP5 snew object model very familiar, though with important differences. Given these changes, as PHP takes on a more Java-like cast, there aretwo possibilities for which a discussion of PHP and Java might bepertinent. You might need to work on a project that requires PHP andJava or Java Server Pages (JSP) to work in tandem. Or you may beapproaching PHP from a Java background and want to know aboutthe similarities and differences in order to learn PHP faster. We willdeal with both needs in this chapter. If you don t have a need to use Java, or aren t already familiar withthe language, this chapter won t do much for you. PHP for Java programmersMost projects won t require integration of Java and PHP, unless thereis some specific need due to pre-existing architecture. The Java pro- grammer approaching PHP for the first time may still want to knowmore about how PHP compares to Java for the purposes of learningPHP scripting. SimilaritiesIn this section, we discuss some ways in which PHP and Java are similar. SyntaxThough PHP syntax is much closer to C, many conventions used inJava apply to PHP as well. Code is whitespace insensitive, statementsare terminated with semicolons, function calls have a similar struc- ture (my_function(expression1,expression2)), and curly braces({and }) make statements into blocks. PHP supports C and C++-stylecomments (/* */as well as //), which are also used in Java. 3939CHAPTER …In This ChapterPHP for JavaprogrammersJava Server Pages (JSP) and PHPIntegrating Java and PHPThe Java extensionThe Java object in PHPError handling andreporting …
Please visit Domain Name Hosting services for high quality webhost to host and run your jsp applications.

Web site hosting - 717Chapter 38PHP and JavaScript Cheese Bread This form

Saturday, November 24th, 2007

717Chapter 38PHP and JavaScript



Cheese





Bread

This form admittedly doesn t actually do very much yet but the point is that it would obvi- ate one or two trips from client to server and back. It also demonstrates another of the inter- esting effects PHP developers can get by experimenting with JavaScript. SummaryJavaScript is a client-side scripting language that is highly efficient at many tasks that do notrequire server-side processing. Not everyone will want to use JavaScript, which has long- standing usability and security issues, but for those who do, the combination of client-sideand server-side programming languages can offer an attractive combination of functionalities. PHP and JavaScript have different object notations. JavaScript uses the so-called dotnotation, whereas PHP uses the arrowor C++ style notation. JavaScript is thoroughly object-oriented, whereas PHP treats objects as an optional feature. The good news is that you ll never confusea JavaScript object for a PHP object, or vice versa. The bad news is that you cannot accessthe same object from both languages. It s often possible to implement a feature in both a client-side and a server-side way. Users withJavaScript-enabled browsers can enjoy greater speed and convenience, whereas those withoutcan still get the functionality. This makes it possible to consider using JavaScript without itsgreatest drawback, which is unpredictability leading to alienation of segments of the userbase. Perhaps the greatest service PHP can perform for JavaScript is to enable database connectivity resulting in what we might call Dynamic JavaScript. JavaScript, being purely a client-side technology, cannot query a server-side database for variable data with which to dynamically generate content. Without a server-side helper like PHP, JavaScripts must beupdated by hand whenever variable data is changed. PHP s capability to pass in up-to-datevariables from a data store can make it considerably less labor intensive to maintainJavaScript-enabled forms and functions. …
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

716Part IVConnectionsListing 38-6(continued) Bread White Wheat Rye Kaiser (Cpanel web hosting)

Saturday, November 24th, 2007

716Part IVConnectionsListing 38-6(continued)



Bread



Listing 38-7:Results listing (results.php)

Da Results

n ); } } else { echo($filling); } } ?>
From our experience, we are can tell you that you can find a reliable and cheap webhost service at Java Web Hosting services.