Sunday, August 12, 2007

what's new in servlet 2.5

servlet 2.5

1. Servlet name wildcardingFirst, when writing a <filter-mapping>, you can now use an asterisk in a <servlet-name> entry to represent all servlets (and thus all JSP pages as well). Previously, you could only bind one servlet at a time to a filter, like this:
<filter-mapping>
<filter-name>Image Filter</filter-name>
<servlet-name>ImageServlet</servlet-name>
</filter-mapping>

Now you can bind all servlets at once:
<filter-mapping>
<filter-name>Image Filter</filter-name>
<servlet-name>*</servlet-name> <!-- New -->
</filter-mapping>

2. Multiple patterns in mappings
Second, when writing a <servlet-mapping> or <filter-mapping>, you can now provide multiple match criteria in the same entry. A <servlet-mapping> previously supported just one <url-pattern> element. Now it supports more than one.
For example:
<servlet-mapping>
<servlet-name>color</servlet-name>
<url-pattern>/color/*</url-pattern>
<url-pattern>/colour/*</url-pattern>
</servlet-mapping>

3. Likewise, a <filter-mapping> previously allowed just one <url-pattern> or one <servlet-name>. Now it supports any number of each:
<filter-mapping>
<filter-name>Multipe Mappings Filter</filter-name>
<url-pattern>/foo/*</url-pattern>
<servlet-name>Servlet1</servlet-name>
<servlet-name>Servlet2</servlet-name>
<url-pattern>/bar/*</url-pattern>
</filter-mapping>

4. A new dependency on J2SE 5.0

5. Support for annotations and Annotation performanceWhether or not you use annotations—and especially if you don't—it's important to understand the performance impact they can have on a server at startup. In order for the server to discover annotations on classes, it must load the classes, which means that at startup, a server will look through all the classes in WEB-INF/classes and WEB-INF/lib, looking for annotations. (Per the specification, servers don't have to look outside these two places.) You can avoid this search when you know you don't have any annotations by specifying a metadata-complete attribute on the <web-app> root like this:

<web-app xmlns="http://java.sun.com/xml/ns/javaee"
version="2.5" metadata-complete="true">
</web-app>

When you're not using annotations, this reenables lazy class loading.
Annotations:
JSR 250: Common Annotations for the Java Platform
JSR 220: Enterprise JavaBeans 3.0
JSR 224: Java API for XML-Based Web Services (JAX-WS) 2.0
JSR 181: Web Services Metadata for the Java Platform

6. A handful of removed restrictions
Servlet 2.5 eased a few restrictions around error handling and session tracking. With error handling, Servlet 2.5 removed a rule dictating that error-handling pages configured with <error-page> could not call setStatus() to alter the error code that triggered them. The rule followed the argument that the job of an error page is to report each error but not alter it. However, practical use has made clear that sometimes an error-handling page may be able to do something more graceful than show an error, perhaps choosing instead to show an online help chat window to help the user resolve the problem. The specification no longer prevents an error-page handler from producing a nonerror response.

Regarding session tracking, Servlet 2.5 eased a rule dictating that a servlet called by RequestDispatcher include() couldn't set response headers. This rule's purpose was to keep included servlets constrained within their own space on the page, unable to affect the page outside that area. The rule has eased now to allow request.getSession() calls within the included servlet, which might implicitly create a session-tracking cookie header. Logic dictates an included resource should be constrained, but logic also dictates those constraints shouldn't eliminate the ability to initiate a session. This change proves especially important for the Portlet Specification. Note that if the response was already committed, the getSession() call will throw an IllegalStateException. Previously, it would have been a no-op.

7. Some edge case clarifications
Lastly, the new specification clarifies several edge cases to make servlets more portable and guaranteed to work as desired.
Response closureThe first clarification is trivial and esoteric, but interesting as an example of the unintended side effects you sometimes see in a specification. The Servlet 2.4 specification dictates that the response should be committed (that is, have the response started with the status code and headers sent to the client) in several situations including when "The amount of content specified in the setContentLength method of the response and has been written to the response." This appears all well and good until you write code like this to do a redirect:

response.setHeader("Host", "localhost");
response.setHeader("Pragma", "no-cache");
response.setHeader("Content-Length", "0");
response.setHeader("Location", "http://www.apache.org");

Thursday, August 9, 2007

PHP4 installation on apache2 (require root permission)

Download the php binary distribution from php site and execute the following commands in the same order

$gzip -d php-4.4.4.tar.gz
$tar -xvf php-4.4.4.tar
$cd php-4.4.4
$./configure --with-apxs2=/portal/apache0/bin/apxs --with-config-file-path=/portal/apache0/conf
$make
$make install
$cp php.ini-dist /portal/apache0/conf/php.ini

edit httpd.conf and add below lines
LoadModule php4_module modules/libphp4.so
AddType application/x-httpd-php .php .phtml
AddType application/x-httpd-php-source .phps

restart apache

How to set date in Linux OS

$ date -s "07/24/2007 15:24:00"

some useful unix commands

Free Memory check
$ free -m

Free Memory and Total Memory check
$ free -m -t

Process wise memory usage
$ vmstat
$ top (hit q to stop)

To get to know the environment
$ env

Oracle double byte characters sets

If your operating system is enabled for a single-byte character set, it does not automatically accept double-byte character sets. You must enable your database to store monitoring information that comes in double-byte character strings.
So while creating a database includes the CHARACTER SET UTF8 string. This string enables storage of double-byte character sets.

Enabling the database for double bytes character set is just setting the character set to UTF-8.

To make sure the database is UTF-8 enabled execute the below query.
select value from NLS_DATABASE_PARAMETERS where parameter = 'NLS_CHARACTERSET';

result 1: WE8ISO8859P1
result 2: AL32UTF8

If you get UTF8 then it is UTF-8 enabled

UnsupportedClassVersionError

Java version incompatible error

Caused by: java.lang.UnsupportedClassVersionError: com/mycomp/struts/GetNameForm (Unsupported major.minor version 49.0)

If you compile this java file using jdk1.5 and try to run it on jdk1.4.2 (lower version) u'll get this error !!

UNIX command to run script as a backend process

example 1: nohup java Reminder &

example 2: nohup ./start.sh &