Skip to main content

Posts

Showing posts from 2008

[Tutorial] Connecting Apache httpd and Tomcat servers

Apache Tomcat is a Servlet/JSP container and used to deploy dynamic Java contents like JSPs and Servlets. Tomcat has some web server capabilities, however it is not a full blown web server to serve high traffic web sites. In the meantime Apache HTTP server is a full blown web server. So in general Tomcat is configured along with Apache HTTP server to maintain a healthy web site with dynamic content. This article will cover the steps of configuring HTTP server and Tomcat connection, however this will not discuss installation details of Apache or Tomcat.

System RequirementsApache HTTP server installed download from herewe used version 2.2.10 for this articleApache Tomcat installed download from herewe used version 5.5 hereShort Names Followings are the short names used to denote folders used in this article.
%APACHE_HTTP_HOME%denotes Apache HTTP Server installation directory. In our testing machine, it is "D:\ASF\Apache"%CATALINA_HOME%Tomcat installation directory; for example…

Unable to load dynamic library php_curl.dll: Error message in PHP

In Windows, while trying to use "curl" extension with PHP 5.2/Apache 2; you may encounter a blank page. If you open up the error log file in Apache (%APACHE_HOME%\logs\error.log); you may see an error message as follows.
PHP Warning: PHP Startup: Unable to load dynamic library '%PHP_HOME\\ext\\php_curl.dll' - The application has failed to start because its side-by-side configuration is incorrect. Please see the application event log for more detail.
This error message can be caused due to some version conflicts on a set of DLLs that are already available inside %windows%\system32 directory.

First check the %windows%\system32 directory to see whether the following DLL files are already available.
libeay32.dllssleay32.dll If those are available, then you would be able to resolve the issue as follows. (However if they are not available, you would need to find some alternative solution).

Now you must first rename the above two DLL files. We did as follows by adding an…

Manage HTTP headers with Java Servlets: Quick Notes

In Java Servlets API, both HttpServletRequest and HttpServletResponse interfaces (in javax.servlet.http package) provide methods to programatically manipulate HTTP headers. There are a number of standard HTTP headers exchanged between a web server and a client (eg: a browser). "Content-Type" is a commonly used header (which is used to specify MIME type) in Servlets. In this article we are discussing how headers are read/written with Servlet classes.
Reading Headers A servlet can read HTTP headers sent by a client request using HttpServletRequest interface. This interface has two methods for this.
String getHeader(String headerName); int getintHeader(String headerName);
Both these methods are similar except getIntHeader() method is used to return value of headers with int type values. Below code shows how value of "Content-type" header is read from the user request. (HttpServlet.doGet() method is used in the example).
import javax.servlet.http.*; import java.io.*…

Google redirect to incorrect country domain: Fix on Firefox

Google servers identify the country of the googler and redirect to the relevant country domain. They may be using the IP of the request to locate the country before the redirect. However there are situations many googler getting redirected to incorrect country domains. For example, even though our requests are generating from Sri Lanka, most of the time we are redirected to another country (Taiwan) domain. Some misconfigurations at the routers or at the ISP may cause this issue, which makes it harder for a general browser user to get that resolved. This automatic redirect mechanism does not depend on the browser used.

Following is a quick fix to this issue. However this will only work on Firefox browser, sorry friends if you are on another browser.
Install Redirector extension Redirector is a small extension available for Firefox, and it supports most of the versions ranging from 2.0 to 3.0.*. (we are using latest Firefox; 3.0.3). You can freely install it from here.
If you are a …

Gmail Multiple Sessions Alert: This account is open in 1 other location

"This account is open in 1 other location at..." Gmail user interface provides this message when your account is used in multiple locations simultaneously. One of the most important and interesting security feature that any web mail service would wish to provide. I suppose Gmail is the only web mail service that has this type of security feature (let us know if any other does). Users become aware of any misuse of their Gmail accounts.

Gmail is countering the number of active sessions per account in providing this information; so "open in multiple locations" means that there are multiple active session for this particular account. Gmail also provides more details about each session making it easy to track the misuser. Access Type, IP address and Date/Time are displayed as details.
Effectiveness All these details are visible to all web sessions including misuser's session; so the effectiveness of this feature is in doubt. For example, a misuser can sign out as so…

Sun suspends NetBeans IDE DVD Starter Kit distribution program

Sun has suspended their NetBeans IDE DVD Starter Kit distribution program indefinitely. Yes, you read it correctly; they have done it. So many developers used to get most of Sun (free) products through the distribution program. Students with less bandwidth (in some colleges & universities); specially users without Internet access to home computers are fond of this service as NetBeans DVDs are freely delivered to their hands at no cost.

According to NetBeans.org; Since August 30th, 2005, NetBeans.org has shipped more than 225,000 CDs & DVDs to developers around the world through this initiative! During this period, NetBeans has experienced explosive growth as a download, media kit, and a community. To stay ahead of this encouraging trend we are looking into ways to effectively satisfy increasing demand for NetBeans software worldwide.
For sure this service played a huge role in helping so many Java developers. Also the program is a good marketing option for NetBeans since…

Lazy loading vs. pre-loading beans with Spring Framework

Spring framework can instantiate and bind (called loading) related Java objects (called beans) according to a given configuration. An XML file can easily be used to define these bindings. Spring framework supports two different types of loading methods; lazy loading and pre-loading respectively managed by BeanFactory and ApplicationContext containers. Lazy Loading A bean is loaded only when an instance of that Java class is requested by any other method or a class. org.springframework.beans.factory.BeanFactory (and subclasses) container loads beans lazily. Following code snippet demonstrate lazy loading, concentrate on how "beans.xml" spring configuration file is loaded by BeanFactory container class. BeanFactory factory = new XmlBeanFactory( new InputStreamResource( new FileInputStream("beans.xml")));// 1 Employee emp = (Employee) factory.getBean("employeeBean");// 2 Even though "beans.xml" configuration file is loaded with …

[Eclipse] Access restriction: Class is not accessible due to restriction on required library

"Access restriction: Class is not accessible due to restriction on required library"; error message may be shown while developing Java projects in Eclipse IDE. Error message is self-explanatory, some classes can not be loaded into the project since restriction rules are being imposed on those classes.Solution!This error message can be removed by changing a setting inside Eclipse IDE. Open up the dialog box shown below, using any of the following paths.Windows -> Preferences -> Java -> Compiler -> Errors/Warnings(Project) Properties -> Java Compiler -> Errors/Warnings Locate the "Forbidden reference (access rules)"; option under "Deprecated and restricted API" section in the dialog box. This option decides how to handle access rules defined inside Eclipse. By default it is set to "Error" which causes Eclipse to complain about references to any restricted classes. Choosing any other option (Warning or Ignore) will remove these e…

Chrome or Firefox - which browser to choose?

Chrome is the newest baby in browser family or the next competitor in browser war. What ever it is, Google released their browser named Chrome. But Mozilla Firefox is the most popular browser in the world right now and Google was the major supporter for Firefox. Even while supporting it, they have built their own browser free and open source. Here we are looking at the two browsers and trying to compare them to decide whether to switch to the new one or not leaving our old but fascinating friend Firefox?

Interesting features1. One Process per each tab
Tab is not another thread running inside the browser process; there is a separate process per tab. Even if one tab crashes, the rest of the tabs will be running as nothing happened; which was not available in Firefox. This is one of the most interesting features.

2. New tab is filled with useful links
For a new tab in Firefox, you can load a predefined page, a blank page or a predefined set of page links (using an extension). But you would b…

Use "object" instead of "bean" in Spring Configuration XML

Spring configuration xml is used for defining the wiring between different object. It has the following format.

<beans> <bean id=".." class="..."> ... </bean> ... <beans> Classes specified in the configuration file will be instantiated by Spring container. And those objects will be bound with each other accordingly. Any java class specified under attribute named "class" will be instantiated. There is no much limitations on the classes that can be used for this here. It does not need to be a JavaBean. It can be any POJO (plan old java object). The only requirement is that this class must be possible to instantiate.

So why does this tags are named <beans> and <bean>? This seems to be misleading.

In Spring one way of binding objects is using the beaness of java classes. But that is not that only way to bind them together, constructor can be used to bind objects. So if configuration file used tags …

Google Web Toolkit (GWT) & Servlets - Web application tutorial

Google Web Toolkit (GWT) and Java Servlets used in one web application. This tutorial will take you though the steps of developing a simple web application with Google Web Toolkit and J2EE Servlet Technology. The application will have a servlet on server side and one web page.

PrerequisitesBetter to be familiar with developing web applications with J2EE/ServletsKnowledge on deploying a web application into Tomcat web serverSystem RequirementsJDK installedApache Tomcat web server (download, any other web server can be used)GWT (download)In brief, GWT is a framework for developing Ajax based web pages with Java. All the HTML page content will be written as Java classes and converted into a set of Javascript files. For more information on GWT, refer to official site here. http://code.google.com/webtoolkit/
Introduction In this tutorial we will create a simple web application which has one page. When a user clicks a button, web page content will be updated without refreshing or leaving…

Is Partitioning a hard disk into multiple drives bad?

Hard disk partitioning is almost a must, according to what I have heard so far from my colleagues and other professionals (may be same for you). I am used to partition a hard disk at least to three drives; "C" for OS (Operating System), "D" for programs and "E for other files like documents, archives. But I got a chance to read some material on hard drive performance and it completely argued my partitioning practices.

When considering the speed in reading a file from hard drive following are two important points related to partitioning.

1. Files in outer tracks are readable much faster
It is a well known theory in hard disk read/writes that performance is much higher in outer tracks compared to inner tracks.

2. When partitioning a hard disk, the first partition is created in the outer tracks
In creating partitions, the first partition is created in the outer most tracks while each new partition is created in inner tracks than the previous. So the partitions in a ha…

Cellspacing vs cellpadding - Table attributes comparison

In HTML Tables (<table>) there are two attributes named, cellpadding and cellspacing. What is the different between cellpadding and cellspacing? Both these are capable of creating some empty space inside a table.

cellspacing : space between cells
cellpadding : space between the cell border and it's content
As the word "cellspacing" suggests, it denotes the spacing between cells; it is something easy to remember. "cellpadding" keyword can be considered in relation to the "padding" attribute in HTML/CSS; padding is used to denote the space between the content and border of box type elements.

Look at the diagram to clarify this further.
Following is a simple code example to demonstrate the difference.
<table cellspacing="15px" cellpadding="20px" style="background:#8df981;"> <tr> <td bgcolor="#0500fa"> <div style="background…

If Michael Phelps is a country himself alone

What if Michael Phelps is a country himself alone rather than representing United States of America? Michael Phelps has already gathered 8 Gold medals in Beijing Olympics 2008 including 3 relays. Most of the participating countries happened to go back empty hand, so many players are participating knowing they are not up to the level of winning a medal. But consider this man, he's breaking world records in most appearances.

If he is playing himself alone as a separate country named "Phelps" he would still have 5 Gold medals and ranked as 11th country in Beijing Olympic medal table. Around 200 countries will be behind him. Medal table would look as follows.

RankCountryGold1China352USA14 (19-Phelps)3Australia11.....11Phelps5
He is creating new history with a set of world records and we are really proud to see such a person in this planet. We doubt any one living right now in this planet will be able to witness another performance like this in their lifetime. If they could, …

[Cricket] Most wickets in debut Test series - World record by Ajantha Mendis

Most wickets by a player in his debut 3-match Test series; a 60+ years old world record has been broken. By whom? By Sri Lankan newly found precious mystery spinner Ajantha Mendis. He produced this new world record yesterday, 2008-08-10 with the wicket of Sachin Tendulkar, another master of cricket. Up to now, he has got 25 wickets in this series, and he has passed the 24 wickets record held by English bawler named Alec Bedser.

Ajantha Mendis has so many variations, and so difficult to read from the hand. Most of the Indian batsmen are still struggling to play against him while he is improving with his variations and accuracy.

In the current India-Sri Lanka Test series he played in all 3 matches (and 6 innings) and performed fabulously. Still he is bawling in the 2nd inning of the last Test match and 5 more wickets are left in Indian team. So we wish Mendis to get some more wickets out of those and improve his record into an untouchable one in history.

Well done Menda.

Update:
Ajantha add…

Verify calling JavaScript function available to avoid runtime errors

Do you want to verify whether a JavaScript function exists before calling it to avoid runtime errors? With JavaScript we used to call JavaScript functions. But sometimes our JavaScript code tend to throw runtime errors and showing then on the browser. For this there can be several reasons including; incorrect function names or invalid .js file names causing some functions not loaded into your web page.

JavaScript has the ability to check the existence of a function. For that we can use the typeof keyword, and check whether that is of 'function' type or not.

Generally we will be calling a JavaScript function without checking whether it exists. Following code shows how we would call a function.
function callClient(){ myTestFunction(); }
If the function named myTestFunction() is not available, the browser will show an error message at runtime. But we can check whether this method is available even before calling it, avoiding the errors. Following code snippet checks t…

Write Java with JDK 1.5 features and run on JRE 1.4

Have you being writing your Java code on Java 1.5 (JDK 1.5) with new features like auto boxing, generics and enums? And suddenly realized that your customer's servers are still using Java 1.4 (JRE 1.4)? This is not a surprise since most of the customers are not in a position to take a risk and try the newer versions as they are running live/online businesses. But as professionals in the software development field, we have to move with the latest/stable versions available in the market. That's where the conflict occurs.

Now you must deploy your Java 1.5 codes into a 1.4 Java runtime environment (even may be 1.3 or 1.2). Even if the Java code has not used any of the new features of Java 1.5, you still can not run your code in 1.4 JRE as the runtime throws an error saying "java.lang.UnsupportedClassVersionError".
Compile 1.5 codes for 1.4 JVM Java compiler provides an option to specify the target JVM of the generated classes like 1.5, 1.4, and 1.3 as follows.
public c…

Java: Numbers only String by removing non numeric characters

With Java, deleting non numeric characters (letters, symbols etc) from a string to produce a numbers-only String is a common requirement in web applications, as application users are used to insert numeric values with non-numeric characters.

For example a phone number will be entered with (-) characters like;
650-212-5710.
A price value may be entered with (,) characters like;
12,500.00

In Java, java.lang.Character class has a method; isDigit() which can be used to identify whether a character is a digit or not. Following method can be used for extracting a numbers-only string, by removing all non-digits.
public static String getOnlyNumerics(String str) { if (str == null) { return null; } StringBuffer strBuff = new StringBuffer(); char c; for (int i = 0; i < str.length() ; i++) { c = str.charAt(i); if (Character.isDigit(c)) { strBuff.append(c); } } return strBuff.toString(); } Calling…

How to open a .war (web archive) or .jar (java archive) files

With Java we generate .JAR files to bundle a set of resources. For J2EE web applications, we generate .WAR (Web Archive) files for deployments. Both of these are ways of archiving a set of files.

Both these .jar or .war archives are in zip format. So there are plenty of ways to open those files to read the content. One way would be to use any tool that you use to open/extract a .zip file. Next will be to use the Jar command itself.

JAR Command JAR (command) utility in Java can be used to open/extract these files as follows. Run following command from the folder where you need the content to be extracted by providing the path to the archive.
jar xf <path-to-file> options: x - extract the files f - file to extract
Let's extract myWebApp.war and myProject.jar files. jar xf myWebApp.war jar xf myProject.jar

Web Services with Apache Axis 1.4 Tutorial: server and client sides

Web services are a handy method of integrating independent systems. Apache Axis is one of the best free tools available for implementing and deploying web services, and also for implementing the web service clients. In this article we will create a simple, but complete web service and a client for this service step-by-step. Article will be explanatory as much as possible to succeed you in implementing it yourself alone after completing this tutorial.PrerequisitesMust be familiar with JavaFamiliar with basics on a web server like TomcatSome knowledge in configuring Axis will be an added advantageSystem Configuration Requirements We will be discussing the configuration in brief as our scope is mainly on web services. (If Axis already configured, jump to implementation). If you find any issues on the configuration part, you can refer to Apache Axis site for troubleshooting. (But if you can not solve it yourself do not worry, post the issue under the comments section in this article, and …

Java2WDSL & WSDL2Java - java.util.Date not handled consistently

Java2WSDL and WSDL2Java tools in Axis (1.4) are pretty handy tools. Those help you to generate a WSDL from a java class as well as generating stubs/skeletons from a WSDL. But if you are dealing with java.util.Date fields in your code, you must pay some attention. Java2WSDL Consider the following java interface which uses java.util.Date as a return type as well as a method parameter. public interface MyService { public java.util.Date getNextDate(); public void updateLastRun(java.util.Date date); } When the Java2WDSL tool generates a WSDL for a class with a Date field, it will represent java.util.Date fields as dateTime fields in WSDL. The generated WSDL file would look as follows. <?xml version="1.0" encoding="UTF-8" ?> <wsdl:definitions targetNamespace="http://service" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="http://service" xmlns:intf="http://service" xmlns…

Java Sorting: Comparator vs Comparable Tutorial

Java Comparators and Comparables? What are they? How do we use them? This is a question we received from one of our readers. This article will discuss the java.util.Comparator and java.lang.Comparable in details with a set of sample codes for further clarifications.

Create/Restore Internet Explorer desktop shortcut

Internet Explorer (IE) shortcut on Windows desktop is missing! May be it was deleted accidentally or missing due to some unexpected reason. So what would be the way to recreate it? You can create a shortcut just by right clicking on Windows Desktop. But you must give the application path to Internet Explorer installation. How would you find it?


You would do a search on Windows for iexplore.exe on your C drive (Windows drive); and you'll end up seeing a number of iexplore.exe files on your machine. Are these the ones you have to use? which one out of these?

Not exactly. The expected executable will not be shown by a Windows search. The correct file is a "protected operating system file", also it's hidden. By default Windows Explorer hides those files, but still you can view such files by changing the folder options as shown in the image.
Tools->Folder Options->View


The iexplore.exe executable will be available under;
C:\Program Files\Internet Explorer\iexplore.exe

S…

Change Apache Tomcat port 8080 to 80 or another port number

Change Apache Tomcat port 8080 to 80 or another port number. Whether it is Apache Tomcat 5 or Tomcat 6, by default Apache Tomcat runs on port 8080. But there can be situations where there are some other servers running on this same port forcing you to change the port of one of the servers. This article explains how to change this port 8080 on Tomcat (we tested this against Apache Tomcat 5.5 and 6.0 versions).

Here we’ll be using label <CATALINA_HOME> to denote the folder where Tomcat is installed. In our systems, tomcat is installed in the following path.
<CATALINA_HOME>=C:\Java\Tomcat_x.x

We need to edit the file named server.xml inside <CATALINA_HOME>\conf folder.

In the server.xml file; locate the following segment.
<!-- Define a non-SSL HTTP/1.1 Connector on port 8080 --> <Connector port="8080" … /> By changing this 8080 value of port attribute, server would start listening on new port number. <Connector port="8081" … />…
Creative Commons License Digizol by Kamal Mettananda is licensed under a Creative Commons Attribution-Noncommercial-No Derivative Works 3.0 License .
URL of this page must be supplied in attribution
© 2004-2017