Signup · Login
Stardeveloper.com  
Home · Tutorials · Forums · Web Hosting Plans · Faisal Khan's Blog · Contact
Search Stardeveloper.com
Stardeveloper RSS Feed
Newsletter
Enter your email address below to be informed every time a new article is posted at Stardeveloper.com:

You can follow Faisal Khan on Twitter
Article Categories
.NET  .NET
  ASP (16)
  ASP.NET (41)
  ADO (16)
  ADO.NET (10)
  COM (6)
  Web Services (4)
  C# (1)
  VB.NET (3)
  IIS (2)

J2EE  J2EE
  JSP (15)
  Servlets (9)
  Web Services (1)
  EJB (4)
  JDBC (4)
  E-Commerce (1)
  J2ME (1)
  Products (1)
  Applets (1)
  Patterns (1)
Log In
UserName Or Email:

Password:

Auto-Login:

Miscellaneous Links
  Submit Article

Hosted by Securewebs.com
 
Home : J2EE : JSP : Google on your WAP phone using Java Server Pages
 

Google on your WAP phone using Java Server Pages

by Ivan Idris.

Introduction
Without doubt Google is the best search engine of this millenium. The Google people are constantly improving and adding services. They have created a Java API at http://www.google.com/apis/, which lets you access their search results and the good news is that it is totally free! It is essentially a Web Service, but you only need to know Java to use the API. You can search the Internet, get cached pages or use the Google spellchecker. This tutorial focuses on the search functionality.

I asked myself, whether it will be possible to use Google with a mobile phone. There are of course a few obstacles here. First there is the bandwidth limitation and also not all websites are suited for mobile browsers. One of the protocols that allow mobile browsing is WAP. The webpages will have to be written in WML. More about WML later in this tutorial. If you have a website, you will probably want to know how your website ranks on Google for certain keywords. Now you can use an application, that I have built and which I will use as an example in this tutorial.

WML
WML is based on XML and optimized for requirements of mobile phones. One of the optimization strategies is to split requested data and display it with cards. So one long page becomes a card deck of which you see the top card on your mobile. It is up to the developer to provide navigation showing one card at a time. Here is a WML page in JSP style:

<%@ page language="java"
	contentType="text/vnd.wap.wml" %>

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
	"http://www.wapforum.org/DTD/wml_1.1.xml"> 

<wml>
	<card id="searchrank">
		<do type="accept">
			<go href="showrankWML.jsp" method="post">
			  <postfield name="url" value="$(url)" />
			  <postfield name="keywords" value="$(keywords)" />
			</go>
		</do>

		<p>URL:
			<input type="text" name="url"
				maxlength="20" format="*m" />
		</p>

		<p>Keywords:
			<input type="text" name="keywords"
				maxlength="20" format="*m" />
		</p>

	</card>
</wml>

Explanation
The first line tells the server that the content type of the page is WML.

<%@ page language="java"
	contentType="text/vnd.wap.wml" %>

Next line declares it XML.

<?xml version="1.0"?>

Next line defines the DTD.

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
	"http://www.wapforum.org/DTD/wml_1.1.xml"> 

The root element is wml then you see one card tag. You can have several cards here. There are few tags that you will be familiar with - p and input. The input tag however has an attribute 'format'. The format indicates what kind of characters can be entered in the fields. In this case all characters are accepted. This page displays a form, which is posted to another jsp. There are two parameters - the URL of a website we want to rank and keywords. The do tag defines an action for a pressed key and the go and postfields indicate which values to send. In this case, when the user presses OK after filling in all the parameters – the form data is posted to showrankWML.jsp just like with a normal HTML form.

Introduction
Without doubt Google is the best search engine of this millenium. The Google people are constantly improving and adding services. They have created a Java API at http://www.google.com/apis/, which lets you access their search results and the good news is that it is totally free! It is essentially a Web Service, but you only need to know Java to use the API. You can search the Internet, get cached pages or use the Google spellchecker. This tutorial focuses on the search functionality.

I asked myself, whether it will be possible to use Google with a mobile phone. There are of course a few obstacles here. First there is the bandwidth limitation and also not all websites are suited for mobile browsers. One of the protocols that allow mobile browsing is WAP. The webpages will have to be written in WML. More about WML later in this tutorial. If you have a website, you will probably want to know how your website ranks on Google for certain keywords. Now you can use an application, that I have built and which I will use as an example in this tutorial.

WML
WML is based on XML and optimized for requirements of mobile phones. One of the optimization strategies is to split requested data and display it with cards. So one long page becomes a card deck of which you see the top card on your mobile. It is up to the developer to provide navigation showing one card at a time. Here is a WML page in JSP style:

<%@ page language="java"
	contentType="text/vnd.wap.wml" %>

<?xml version="1.0"?>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
	"http://www.wapforum.org/DTD/wml_1.1.xml"> 

<wml>
	<card id="searchrank">
		<do type="accept">
			<go href="showrankWML.jsp" method="post">
			  <postfield name="url" value="$(url)" />
			  <postfield name="keywords" value="$(keywords)" />
			</go>
		</do>

		<p>URL:
			<input type="text" name="url"
				maxlength="20" format="*m" />
		</p>

		<p>Keywords:
			<input type="text" name="keywords"
				maxlength="20" format="*m" />
		</p>

	</card>
</wml>

Explanation
The first line tells the server that the content type of the page is WML.

<%@ page language="java"
	contentType="text/vnd.wap.wml" %>

Next line declares it XML.

<?xml version="1.0"?>

Next line defines the DTD.

<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" 
	"http://www.wapforum.org/DTD/wml_1.1.xml"> 

The root element is wml then you see one card tag. You can have several cards here. There are few tags that you will be familiar with - p and input. The input tag however has an attribute 'format'. The format indicates what kind of characters can be entered in the fields. In this case all characters are accepted. This page displays a form, which is posted to another jsp. There are two parameters - the URL of a website we want to rank and keywords. The do tag defines an action for a pressed key and the go and postfields indicate which values to send. In this case, when the user presses OK after filling in all the parameters – the form data is posted to showrankWML.jsp just like with a normal HTML form.


 ( 1 Remaining ) Next

See all comments and questions (post-ad) posted for this tutorial.


Comments/Questions ( Threads: 1, Comments: 1 )
    Contains 1 or more replies by the Author of this Article.
    Contains 1 or more replies by Faisal Khan.

  1. please do this help for me please

Post Comments/Questions

In order to post questions/comments, you must be logged-in. If you are not a member yet, then signup, otherwise login. Once you login then come back to this page and you'll see a form right here which will allow you to post comments/questions.

Please note, one of the benefits of signing up is to be notified immediately by email everytime you receive a reply to the thread you have subscribed to.

 
© 1999 - 2009 Stardeveloper.com, All Rights Reserved.