Your Ad Here

Wednesday, November 25, 2009

What is the purpose of tiles-def.xml file, resourcebundle.properties file, validation.xml file?

1. tiles-def.xml

tiles-def.xml is used as a configuration file for an appliction during tiles development
You can define the layout / header / footer / body content for your View.

Eg:

<tiles-definitions>
<definition name="siteLayoutDef" path="/layout/thbiSiteLayout.jsp">
<put name="title" value="Title of the page" />
<put name="header" value="/include/thbiheader.jsp" />
<put name="footer" value="/include/thbifooter.jsp" />
<put name="content" type="string">
Content goes here
</put>
</definition>
</tiles-definitions>

<tiles-definitions>
<definition name="userlogin" extends="siteLayoutDef">
<put name="content" value="/dir/login.jsp" />
</definition>
</tiles-definitions>

2. validation.xml

The validation.xml file is used to declare sets of validations that should be applied to Form Beans.

Each Form Bean you want to validate has its own definition in this file
Inside that definition, you specify the validations you want to apply to the Form Bean's fields.

Eg:

<form-validation>
<formset>
<form name="logonForm">
<field property="username"
depends="required">
<arg0 key=" prompt.username"/>
</field>
<field property="password"
depends="required">
<arg0 key="prompt.password"/>
</field>
</form>
</formset>
</form-validation>

3. Resourcebundle.properties

Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.

Eg:

In ApplicationResources.properties

errors.registrationForm.name={0} Is an invalid name.

In the registrationForm.jsp

<html:messages id="messages" property="name">
<font color="red">
<bean:write name="messages" />
</html:messages>

Output(in red color) : abc Is an invalid name

Saturday, November 7, 2009

Explain Type Juggling in PHP?

PHP uses Type juggling similar to the way Perl uses. Variable is defined in the context in which it is used. It doesn’t require any explicit definition for a function to perform its duties. For example if a string value is assigned to a variable it is defined as string.

what are triggers?

Triggers are the programs need not to be run explicitly.
The functionality should be embeded in driver program and
as the driver program runs the trigger gets executed
automatically.

what about ob_start and ob_flush?

ob_start

Output buffers are stackable, that is, you may call ob_start() while another ob_start() is active.


ob_flush


This function does not destroy the output buffer

What is the diffrence between Notify URL and Return URL?

Notify URL and Return URL is used in Paypal Payment Gateway integration

What is htaccess?

An .htaccess file is a simple ASCII file similar to that created through text editor such as Notepad or Simple Text. Most people are confused with the naming convention for the file. The term .htaccess is not a file .htaccess or somepage.htaccess because it is the file extension simply named as such. Its widely known use is related to implementing custom error page or password protected directories.

what would be the differences between PHP and Java?

There must be hundreds of differences between these two languages. But I'd say the key differences are:

* Java is principly an object orientated programming language, where as PHP is principly a imperative scripting language (but does now support object orientation.)
* Java is portable and only requires the system intended to run an applictation has the Java Platform running on it - making it arcitecture neutral. PHP can be deployed on many systems, but does not use a VM environment like Java and is therefore less portable.
* PHPs intended purpose is to be a general-scripting langauge for web development (this is what you'll find almost all PHP applications doing). Java is a general purpose higher level programming language intended for many different purposes, something that you'll notice in the variety of packages that Java provides.

On the matter of security, read this about PHP. Since Java was originally designed with security in mind, there is little point in defending PHPs position. It is less secure. That's not to say that it's not worth considering PHP for your project, I personally have deployed numerous PHP projects with no security melt-downs (yet!)

What is the use of header() function in php?

PHP's header function allows you to change the headers on your returned content so that (examples)

• The browser receives not HTML but plain text, a .jpg image or a file to save locally
example: header ('Content-type: Application/Octet-stream');

• You can change a "404" missing reponse code into a "200" - good.
example: header("HTTP/1.1 200 OK");

• You can send out cache instructions
example: header("cache-control: no-store");

• you can sent out a save file name if you're saving the file.
example: header ('Content-Disposition: attachment; filename="hello.txt"');

What is the difference between session_register and $_session?

Following are differences between session_register and $_SESSION

The very first main and simple difference is that session_register function returns boolean value and $_SESSION returns string value. The second will be session_register function doesn't work if register_global is disabled. But whereas $_SESSION works in both case whether register_global is disabled or enabled. So using $_SESSION for session variable manipulation is more appropriate.

$_SESSION (uppercase !)is a superglobal. You treat it like an associative array, and you can store your session variables in it. session_register() is used for register one or more global variables with the current session. session_register is old php-style for php < 4.4.x and may never used in conjunction with $_SESSION. While $_SESSION[] array is used for storing one or more variables with in the current session array. session_register() depends upon register_global is enable or disable, If it disable it will not work.
Reply With Quote

I read in some blog that using $_SESSION[var]=value is better than using session_register. It is because session_register() only works if register_globals is set ON in your php.ini file. Use $_SESSION , and don't forget to start the session since the strict beginning of the script (before session_start(), only include the classes definition if an instance is stored as a session variable.

How we know browser properties using php

get_browser() attempts to determine the capabilities of the user's browser. This is done by looking up the browser's information in the browscap.ini file.

echo $_SERVER['HTTP_USER_AGENT'];
$browser = get_browser();

foreach ($browser as $name => $value) {
echo "$name $value
\n";
}

Difference between mysql_connect and mysql_pconnect

mysql_connect open a new connection to the database

but mysql_pconnect open a persistant connection to the database

Mysql_connect()->we can colse the datedase
Mysql_pconnect()->we can't close the datadase

Mysql_conect()->opens the database every time page is load
Mysql_pconnect()->Need not to the every time page load

mysql_connect everytime open a new connection to the database


while using mysql_pconnect , the function would first try to
find a (persistent) link that's already open with the same
host, username and password. If one is found, an identifier
for it will be returned instead of opening a new connection...
the connection to the SQL server will not be closed when the
execution of the script ends. Instead, the link will remain
open for future use.

What are the different tables present in MySQL, which type of table is generated when we are creating a table in the following syntax:

create table employee (eno int(2),ename varchar(10))
Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM

What function can you use to open a file for reading and writing?

1. fget();
2. file_open();
3. fopen();
4. open_file();

What function would you use to redirect the browser to a new page?

1. redir()
2. header()
3. location()
4. redirect()

What is the difference between Split and Explode?

split() can work using regular expressions while explode() cannot.

How do you capture audio/video in PHP?

FFmpeg is a complete solution to record, convert and stream audio and video. It includes libavcodec, the leading audio/video codec library. FFmpeg is developed under Linux, but it can compiled under most operating systems, including Windows.

How i can get ip address ?

PHP makes REMOTE_ADDR and REMOTE_HOST available for our use, they live
within the SERVER arrays.
REMOTE_ADDR - the IP address of the client
REMOTE_HOST - the host address of the client, if available

How can we encrypt and decrypt a data presented in a table using MySQL?

You can use functions: AES_ENCRYPT() and AES_DECRYPT()
like:
AES_ENCRYPT(str, key_str)
AES_DECRYPT(crypt_str, key_str)

Who is the father of PHP and explain the changes in PHP versions?

Rasmus Ledorf is the father of PHP.
PHP 3: Functionalities added.
PHP 4: Zend Engine added for code optimisation
PHP 5: Object oriented Programming concepts added.

What type of inheritance that php supports?

In PHP an extended class is always dependent on a single base class, that is, multiple inheritance is not supported. Classes are extended using the keyword 'extends'.

How to reset/destroy a cookie in PHP?

Reset a cookie by specifying expire time in the past:
Example: setcookie('Test',$i,time()-3600); // already expired time
Reset a cookie by specifying its name only
Example: setcookie('Test');

How to set cookies in PHP?

setcookie('variable','value','time');
variable - name of the cookie variable
value - value of the cookie variable
time - expiry time

Example: setcookie('Test',$i,time()+3600);
Test - cookie variable name
$i - value of the variable 'Test'
time()+3600 - denotes that the cookie will expire after an one hour

What are encryption functions in PHP?

CRYPT()
MD5()

What is the difference between PHP4 and PHP5?

PHP4 cannot support oops concepts and Zend engine 1 is used.
PHP5 supports oops concepts and Zend engine 2 is used.
Error supporting is increased in PHP5.
XML and SQLLite will is increased in PHP5.

What is meant by MIME?

MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However browsers also uses MIME standard to transmit files. MIME has a header which is added to a beginning of the data. When browser sees such header it shows the data as it would be a file
for example image
Some examples of MIME types:
audio/x-ms-wmp
image/png
aplication/x-shockwave-flash

echo, print and printf. Explain the differences?

echo just outputs the contents following the construct to the screen.
print() is a function that will return either 0 or 1 based on failure or success. print does not take multiple parameters.
printf is similar but is used for printing formatted output.

What are the current versions of Apache, PHP, and MySQL?

Apache HTTP Server 2.0.63
PHP 5.3.0
MySQL 5.1
MySQL 5.4 is the current development release series.

What is meant by nl2br()?

nl2br() inserts a HTML tag
<br>
before all new line characters \n in a string.
echo nl2br("god bless \n you");
output:
god bless

Would you initialize your strings with single quotes or double quotes?

Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.

WHAT ARE THE DIFFERENT TYPES OF ERRORS IN PHP?

Here are three basic types of runtime errors in PHP:
1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script - for example, accessing a variable that has not yet been defined. By default, such errors are not displayed to the user at all - although you can change this default behavior.
2. Warnings: These are more serious errors - for example, attempting to include() a file which does not exist. By default, these errors are displayed to the user, but they do not result in script termination.
3. Fatal errors: These are critical errors - for example, instantiating an object of a non-existent class, or calling a non-existent function. These errors cause the immediate termination of the script, and PHP's default behavior is to display them to the user when they take place.
Internally, these variations are represented by twelve different error types

How do I find out the number of parameters passed into function?

func_num_args() function returns the number of parameters passed in.

What is the difference between ereg_replace() and eregi_replace()?

ereg_replace( string $pattern , string $replacement , string $string )
eregi_replace( string $pattern , string $replacement , string $string )
This both function scans string for matches to pattern , then replaces the matched text with replacement .
eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.

What is the functionality of the function strstr and stristr?

strstr() returns part of a given string from the first occurrence of a given substring to the end of the string.
For example: strstr("user@example.com","@") will return "@example.com".
stristr() is idential to strstr() except that it is case insensitive.

What’s the difference between md5(), crc32() and sha1() crypto on PHP?

The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.

How can we know the count/number of elements of an array?

a) sizeof($array) – This function is an alias of count()
b) count($urarray) – This function returns the number of elements in an array.

What are the different functions in sorting an array?

Sorting functions in PHP:
asort()— Sort an array in alphabatical order and maintain index association.
arsort()— Sort an array in reverse order and maintain index association.
ksort()- Sort an array by key
krsort()- Sort an array by key in reverse order
usort()- Sort an array by values using a user-defined comparison function
uksort()- Sort an array by key using a user-defined comparison function
uasort() — Sort an array with a user-defined comparison function and maintain index association
sort() — Sort an array
natsort() — Sort an array using a "natural order" algorithm
rsort() — Sort an array in reverse order

how can we unset the variable of a session?

session_unregister() – Unregister a global variable from the current session.
session_unset() – Free all session variables.

What’s the difference between htmlentities() and htmlspecialchars()?

The htmlspecialchars() function converts some predefined characters to HTML entities.
The predefined characters are:
* & (ampersand) becomes &
* " (double quote) becomes "
* ' (single quote) becomes '
* < (less than) becomes &lt;
* > (greater than) becomes &gt;

htmlentities — Convert all applicable characters to HTML entities.

How can we register the variables into a session?

session_register($session_var);
$_SESSION['var'] = ‘value’;

What is the difference between the functions unlink and unset?

unlink() is a function for file system handling. It will simply delete the file in context.
unset() is a function for variable management. It will make a variable undefined.

What are "GET" and "POST"?

GET and POST are methods used to send data to the server: With the GET method, the browser appends the data onto the URL. With the Post method, the data is sent as "standard input."
When you want to send short or small data, not containing ASCII characters, then you can use GET Method. But for long data sending, say more then 100 character you can use POST method.

What are the differences between DROP a table and TRUNCATE a table?

DROP TABLE table_name – This will delete the table and its data.
TRUNCATE TABLE table_name – This will delete the data of the table, but not the table

How do you pass a variable by value?

Just like in C++, put an ampersand in front of it, like $a = &$b

I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what is the problem?

PHP Interpreter treats numbers beginning with 0 as octal.

What is the difference between mysql_fetch_object and mysql_fetch_array?

mysql_fetch_object — Fetch a result row as an object
mysql_fetch_array — Fetch a result row as an array

What is meant by urlencode and urldecode?

urlencode() returns the URL encoded version of the given string.
URL coding converts special characters into % signs followed by two hex digits.
For example: urlencode("10.00%") will return "10%2E00%25". URL encoded strings are safe to be used as part of URLs.
urldecode() returns the URL decoded version of the given string.

What are the differences between require and include,include_once,require_once?

require_once() and include_once() are both the functions to include and evaluate the specified file only once.
If the file is not present, require(), calls a fatal error, while in include() does not.

How do you define a constant in PHP?

Via define() directive, like define ("MYCONSTANT", 100);

What Is a Persistent Cookie?

A persistent cookie is a cookie which is stored in a cookie file permanently on the browser’s computer. By default, cookies are created as temporary cookies which stored only in the browser’s memory. When the browser is closed, temporary cookies will be erased. You should decide when to use temporary cookies and when to use persistent cookies based on their differences:
*Temporary cookies can not be used for tracking long-term information.
*Persistent cookies can be used for tracking long-term information.
*Temporary cookies are safer because no programs other than the browser can access them.
*Persistent cookies are less secure because users can open cookie files see the cookie values.

What is the difference between $message and $$message?

$message is a simple variable whereas $$message is a reference variable.
Example:
$user = 'bob'
is equivalent to
$holder = 'user';
$$holder = 'bob';

What is meant by PEAR in php?

PEAR("PHP Extension and Application Repository") is the next revolution in PHP. This repository is bringing higher level programming to PHP. PEAR is a framework and distribution system for reusable PHP components. It eases installation by bringing an automated wizard, and packing the strength and experience of PHP users into a nicely organised OOP library. PEAR also provides a command-line interface that can be used to automatically install "packages"

What Is a PHP Session?

A session is a logical object created by the PHP engine to allow you to preserve data across subsequent HTTP requests.Sessions are commonly used to store temporary data to allow multiple PHP pages to offer a complete functional transaction for the same visitor.

How To Check Your PHP Installation?

PHP provides two execution interfaces: Command Line Interface (CLI) and Common Gateway Interface (CGI).
* Run "phpphp -v" command to check the Command Line Interface (CLI).
* Run "phpphp-cgi -v" command to check the Common Gateway Interface (CGI).

PHP Supported Database

It supports all major database servers, including: MySQL, MS SQL Server, Oracle, mSQL, Sybase, etc.

Wednesday, November 4, 2009

Can we load CSS stylesheets dynamically at runtime

We cann't load the CSS stylesheets dynamically, instead of that we can make the css style sheets to swf and we can load the swf dynamically using Loader in the runtime. This is because if we using the css stylesheet means, on the compile time only the sheet will be loaded.

Tuesday, November 3, 2009

Not standard declaration for Strings in java

We should not declare many variables at a time like

String a,b,c;

This is not a standard format

What's PHP ?

The PHP Hypertext Preprocessor is a programming language that allows web developers to create dynamic content that interacts with databases. PHP is basically used for developing web based software applications.
Your Ad Here