WT Lab Programs
WT Lab Programs
Output:
2. Write html page to take a number from text field in the range 0 to 999
and display in other text field in words. If number is out of range display
alert with “out of range” & display “Not a number” if it is not a number.
<html>
<script language="javascript">
function numinwrd()
{
var numbr=document.getElementById('num').value;
var str=new String(numbr)
var splt=str.split("");
var rev=splt.reverse();
var once=['Zero', ' One', 'Two', 'Three', 'Four','Five', 'Six', 'Seven', 'Eight', 'Nine'];
var twos=['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', '
Seventeen', ' Eighteen',' Nineteen'];
var tens=[ '', 'Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', '
Eighty', ' Ninety' ];
numlen=rev.length;
var word=new Array();
var j=0;
for(i=0;i<numlen;i++)
{
switch(i)
{
case 0:
if((rev[i]==0) || (rev[i+1]==1))
{
word[j]='';
}
else
{
word[j]=once[rev[i]];
}
word[j]=word[j] ;
break;
case 1:
abovetens();
break;
case 2:
if(rev[i]==0)
{
word[j]='';
}
else if((rev[i-1]==0) || (rev[i-2]==0) )
{
word[j]=once[rev[i]]+"Hundred ";
}
else
{
word[j]=once[rev[i]]+"Hundred and";
}
break;
case 3:
if(rev[i]==0 || rev[i+1]==1)
{
word[j]='';
}
else
{
word[j]=once[rev[i]];
}
default:break;
}
j++;
}
function abovetens()
{
if(rev[i]==0)
{
word[j]='';
}
else if(rev[i]==1)
{
word[j]=twos[rev[i-1]];
}
else
{
word[j]=tens[rev[i]];
}
}
word.reverse();
var finalw='';
for(i=0;i<numlen;i++)
{
finalw= finalw+word[i];
}
document.niw.word.value=finalw;
}
</script>
<form name="niw">
Number:
<input type="text" name="num" id="num" maxlength="9">
<input type="button" name="sr1" value="Click Here" onClick="numinwrd()">
Number in Words:
<input type="text" name="word" id="word" size="30">
</form>
</html>
Output:
3. Write an HTML page that has one input, which can take multi-line text
and a submit button. Once the user clicks the submit button, it should
show the number of characters, words and lines in the text entered using
an alert message. Words are separated with white space and lines are
separated with new line character.
<html>
<script language="javascript">
function countWCL()
{
var textarea=document.getElementById("tarea");
var text = textarea.value;
value = "Words: " + (text.split(/\b\S+\b/).length - 1) + " Characters: " +
text.replace(/\s/g, "").length + "/ " + text.replace(/\n/g, "").length + "lines:" +
text.split("\n").length;
alert(value);
}
</script>
<form name="cwl">
Enter Multi Line Text <br>
<textarea name="string" id="tarea" rows=4 cols=30></textarea>
<input type="button" name="sub" value="count" onClick="countWCL()">
</form>
</html>
Output:
4. Write an HTML page that contains a selection box with a list of 5
countries. When the user selects a country, its capital should be printed
next to the list. Add CSS to customize the properties of the font of the
capital (color, bold and font size).
<html>
<title>
country name as capital
</title>
<head>
<style>
div.capstr{
color: red; font-style: bold; font-size:12pt;
}
</style>
</head>
<body>
<select id="country" onchange="getcap();">
<option value="NEW DELHI">india </option>
<option value="LONDON">uk </option>
<option value="Beijing">china </option>
<option value="COLOMBO">srilanka </option>
<option value="Washington">USA</option>
</select>
<div class="capstr" id="capcountry"> </div>
<script type="text/javascript">
function getcap()
{
document.getElementById("capcountry").innerHTML=
document.getElementById("country").value;
}
</script>
</div >
</body>
</html>
Output:
5.Write a java program to create an xml document using DOM parser.
import javax.xml.parsers.*;
import org.w3c.dom.*;
import java.io.*;
import javax.xml.transform.*;
import javax.xml.transform.dom.*;
import javax.xml.transform.stream.*;
public class Dom
{
public static void main(String rags[]) throws Exception
{
DocumentBuilderFactory f=DocumentBuilderFactory.newInstance();
DocumentBuilder b=f.newDocumentBuilder();
Document doc=b.newDocument();
Element rootEle=doc.createElement("students");
Element studentEle=doc.createElement("student");
Element nameEle=doc.createElement("name");
Element emailEle=doc.createElement("email");
Element mobileEle=doc.createElement("mobile");
Element addressEle=doc.createElement("address");
Text t1=doc.createTextNode("VAAGESWARI");
Text t2=doc.createTextNode("[email protected]");
Text t3=doc.createTextNode("9849750204");
Text t4=doc.createTextNode("KARIMNAGAR");
nameEle.appendChild(t1);
emailEle.appendChild(t2);
mobileEle.appendChild(t3);
addressEle.appendChild(t4);
studentEle.appendChild(nameEle);
studentEle.appendChild(emailEle);
studentEle.appendChild(mobileEle);
studentEle.appendChild(addressEle);
rootEle.appendChild(studentEle);
doc.appendChild(rootEle);
Transformer t=TransformerFactory.newInstance().newTransformer();
t.transform(new DOMSource(doc), new StreamResult(new
FileOutputStream("students.xml")));
}
}
Output:
C:\>javac Dom.java
C:\>java Dom
students.xml
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<students>
<student>
<name>VAAGESWARI</name>
<email>[email protected]</email>
<mobile>9849750204</mobile>
<address>KARIMNAGAR</address>
</student>
</students>
6. Write a java program to read the XML file contents and print as it is
using SAX parser.
import org.xml.sax.*;
import org.xml.sax.helpers.*;
import javax.xml.parsers.*;
import java.io.*;
public class SAXReader extends DefaultHandler
{
public static void main(String rags[]) throws Exception
{
SAXParser p=SAXParserFactory.newInstance().newSAXParser();
p.parse(new FileInputStream("students.xml"), new SAXReader());
}
public void startDocument()
{
System.out.println("Document begins here");
}
public void startElement(String uri, String localName, String qName, Attributes
attrs)
{
System.out.println(" <"+qName+" >");
}
public void characters(char ch[], int start, int len)
{
System.out.println(new String(ch, start, len));
}
Output:
C:\>javac SAXReader.java
C:\>java SAXReader
calc.html
<html>
<head>
<title>calculator</title>
</head>
<body>
<form name="f1" method="post" action="success.php">
<table cellpadding="5" cellspacing="5" border="0">
<tr>
<td>Enter First Number</td>
<td colspan="1"><input name="fvalue" id="fvalue" type="text"/></td>
</tr>
<tr>
<td>Select Operator</td>
<td><select name="operator">
<option selected value=""> choose operator</option>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
<option value="%">%</option>
</select></td>
</tr>
<tr>
<td>Enter second Number</td>
<td><input name="lvalue" type="text" id="lvalue"/></td>
</tr>
<tr>
<td></td>
<td><input type="submit" name="calculate" value="Calculate" /></td>
</tr>
</table>
</form>
</body>
</html>
success.php
<?php
if( isset( $_REQUEST['calculate']))
{
$operator = $_REQUEST['operator'];
$a = $_REQUEST['fvalue'];
$b = $_REQUEST['lvalue'];
if($operator == "+")
{
$res = $a + $b;
$result = 'SUM';
}
if($operator == "-")
{
$res = $a - $b;
$result = 'DIFFERENCE';
}
if($operator == "*")
{
$res = $a * $b;
$result = 'PRODUCT';
}
if($operator == "/")
{
$res= $a / $b;
$result = 'DIVISION';
}
if($operator == "%")
{
$res= $a % $b;
$result = 'REMAINDER';
}
}
echo "The".$result." Of ".$a." And".$b." Is ". $res;
?>
<br/><br/><a href="calc.html">click Here</a> To Go Back To Calculator
Output:
8. A web application that takes name and age from an HTML page. If the
age is less than 18, it should send a page with “Hello <name>, you are not
authorized to visit this site” message, where <name> should be replaced
with the entered name. Otherwise it should send “Welcome <name> to
this site” message.
user.html
<html>
<head>
<title> Authorization of user</title>
<body>
<form action="authenticate.php" method="POST">
Name <input type="text" name="name" value=""/><br>
Age <input type="text" name="age" value=""/><br>
<input type="submit" value="submit"/>
</form>
</body>
</html>
authenticate.php
<?php
if($_POST['age']<18)
{
echo "Hello ".$_POST['name']." You are not authorized to visit this site";
}
else
{
echo "Welcome ".$_POST['name']." to this site";
}
?>
Output:
9. A web application that lists all cookies stored in the browser on clicking
“List Cookies” button. Add cookies if necessary.
DESCRIPTION:
Set the JAVA_HOME Variable
You must set the JAVA_ HOME environment variable to tell Tomcat where to find
Java. Failing to properly set this variable prevents Tomcat from handling JSP
pages. This variable should list the base JDK installation directory, not the bin
subdirectory. On Windows XP, you could also go to the Start menu, select Control
Panel, choose System, click on the Advanced tab, press the Environment Variables
button at the bottom, and enter the JAVA_HOME variable and value directly as:
Name: JAVA_HOME
Value: C:\jdk
Set the CLASSPATH
Since servlets and JSP are not part of the Java 2 platform, standard edition, you
have to identify the servlet classes to the compiler. The server already knows about
the servlet classes, but the compiler (i.e., javac) you use for development probably
doesn't. So, if you don't set your CLASSPATH, attempts to compile servlets, tag
libraries, or other classes that use the servlet and JSP APIs will fail with error
messages about unknown classes.
Name: JAVA_HOME
Value: install_dir/common/lib/servlet-api.jar
Turn on Servlet Reloading
The next step is to tell Tomcat to check the modification dates of the class files of
requested servlets and reload ones that have changed since they were loaded into
the server's memory. This slightly degrades performance in deployment situations,
so is turned off by default. However, if you fail to turn it on for your development
server, you'll have to restart the server every time you recompile a servlet that has
already been loaded into the server's memory.
To enable the invoker servlet, uncomment the following servlet and servlet-
mapping elements in install_dir/conf/web.xml. Finally, remember to make a backup
copy of the original version of this file before you make the changes.
<servlet>
<servlet-name>invoker</servlet-name>
<servlet-class>
org.apache.catalina.servlets.InvokerServlet
</servlet-class>
...
</servlet>
...
<servlet-mapping>
<servlet-name>invoker</servlet-name>
<url-pattern>/servlet/*</url-pattern>
</servlet-mapping>
OUTPUT:
Output:
RESULT: These pages are accessed using the TOMCAT web server successfully.
PROGRAM-1.3 Install MySQL
Aim: Step-by-Step guide for Installing MySQL on Windows
You can download the MySQL database from the MySQL website
http://www.mysql.com by clicking on the downloads tab. Scroll down to the
MySQL database server & standard clients section and select the latest production
release of MySQL, 5.1.35 at the time of writing.
If you are getting an error message after clicking the Next button, then please
enable port 3306 in the Windows XP Firewall Settings
Done!!!
But if you are installing MySQL on a Windows XP workstation, or any other
computer that has a firewall enabled, and the wizard fails with an error message
similar to the one shown below (Can't connect to MySQL server on 'localhost'),
then you will have to exclude the MySQL daemon from your firewall configuration
On Windows XP, you can exclude MySQL from the firewall by following the steps
below:
1. Navigate to Start -> Settings -> Control Panel -> Windows Firewall
After clicking OK twice, return to the MySQL error message and select Retry.
MySQL should now be able to create the instance correctly.
Installation of WampServer2:
To start the installation process, you need to open the folder where you saved the
file, and double-click the installer file. A security warning window will open,
asking if you are sure you want to run this file. Click Run to start the installation
process.
Next you will see the Welcome To The WampServer Setup Wizard screen. Click
Next to continue the installation.
The next screen you are presented with is the License Ageement. Read the
agreement, check the radio button next to I accept the agreement, then click
Next to continue the installation.
Next you will see the Select Destination Location screen. Unless you would like to
install WampServer on another drive, you should not need to change anything.
Click Next to continue.
The next screen you are presented with is the Select Additional Tasks screen. You
will be able to select whether you would like a Quick Launch icon added to the
taskbar or a Desktop icon created once installation is complete. Make your
selections, then click Next to continue.
Next you will see the Ready To Install screen. You can review your setup choices,
and change any of them by clicking Back to the appropriate screen, if you choose
to. Once you have reviewed your choices, click Install to continue.
Once the files are extracted, you will be asked to select your default browser.
WampServer defaults to Internet Explorer upon opening the local file browser
window. If your default
browser isn’t IE, then look in the following locations for the corresponding .exe file:
Opera: C:\Program Files (x86)\Opera\opera.exe
Firefox: C:\Program Files (x86)\Mozille Firefox\firefox.exe
Safari: C:\Program Files (x86)\Safari\safari.exe
Chrome:
C:\Users\xxxxx\AppData\Local\Google\Chrome\Application\chrome.exe
Select your default browser’s .exe file, then click Open to continue. The Setup
screen will appear next, showing you the status of the installation process.
Once the progress bar is completely green, the PHP Mail Parameters screen will
appear. Leave the SMTP server as localhost, and change the email address to
one of your choosing. Click Next to continue.
The Installation Complete screen will now appear. Check the Launch
WampServer Now box, then click Finish to complete the installation.
Testing WampServer:
Once you have completed the installation process, test that your installation is
working properly by going to http://localhost/ in your browser. You should see the
WampServer homepage displayed.