Vous êtes sur la page 1sur 20

AIM: /* Validating a registration form using java script */

<html> <head> <script type="text/javascript"> function val() { var ckname=/^[A-Za-z]{6,20}$/; var ckpass=/^[A-Za-z0-9!@#$%^&*()_]{6,20}$/; var uname=document.getElementById("name").value; var ps=document.getElementById("pass").value; var flag=1; if(!ckname.test(uname)) { alert("Improper username.Should have only characters\n\ and length should be > 6"); flag=0; } if(!ckpass.test(ps)) { alert("Improper password.Should have min 6 characters"); flag=0; } var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/; var email=document.getElementById("email").value; if(!pattern.test(email)) { alert("Improper email.Should be of the form name@domain.com"); flag=0; } var phne=/^[0-9]{10}$/; var phone=document.getElementById("phone").value; if(!phne.test(phone)) { alert("Phone number contains only ten digits"); flag=0; } if(flag==0) { return false; } else { return true; } } </script> </head> <body background="pics/reg2.jpg" > Page No:

<p style="font-size:20px"> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp Register yourself <br> &nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp </p> <center> <form action="Register" method="post" onsubmit="return val()"> <table style="font-size:20px"> <tbody style="font-size:20px"> <tr> <td><h4 style="font-size:18px">Name :</h4></td> <td><input id="name"type="text" name="uname"></td> </tr> <tr> <td><h4 style="font-size:18px">Password:</h4></td> <td><input id="pass" type="password" name="pass"></td> </tr> <tr> <td><h4 style="font-size:18px">Email ID:</h4></td> <td><input id="email" type="text" name="email"></td> </tr> <tr> <td><h4 style="font-size:18px">Phone number:</h4></td> <td><input id="phone" type="text" name="phone"></td> </tr> </table> <center> <p style="font-size:18px;font-weight:bold"> Sex:<input type="radio" name="gender"> Male&nbsp; <input type="radio" name="gender">Female <br><br><br><br> </p> <table border="0"> <tbody style="font-size:18px;font-weight:bold"> <tr> <td>Address:</td> <td><textarea name="address" rows="4" cols="15"> </textarea></td> </tr> </tbody>+ </table> </center> <input type="submit" value="Submit"> <input type="reset" value="Reset"> </form> </center> </body> </html> Page No:

AIM: /*

XML validation using DOM Parser */

book.xml: <?xml version="1.0"?> <book-info> <book> <title>wt</title> <author>chris bates</author> <isbn>9999-222</isbn> <publishername>tmh</publishername> <edition>2nd</edition> <price>34$</price> </book> <book> Page No:

<title>AI</title> <author>Knight</author> <isbn>8888-222</isbn> <publishername>tmh</publishername> <edition>2nd</edition> <price>24$</price> </book> <book> <title>CG</title> <author>Roger</author> <isbn>77-123-1</isbn> <publishername>TMH</publishername> <edition>3rd</edition> <price>14$</price> </book> <book> <title>MFCS</title> <author>Trembly</author> <isbn>9999-222</isbn> <publishername>Tmh</publishername> <edition>2nd</edition> <price>34$</price> </book> </book-info>

Book.xsl: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"> <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctypesystem="http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"/> <xsl:template match="book-info"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"/> <title>Untitled Document</title> </head> <body> <table border="1"> <thead> <tr> <td>title</td> <td>author</td> Page No:

<td>isbn</td> <td>publishername</td> <td>edition</td> <td>price</td> </tr> </thead> <tbody > <xsl:for-each select="book"> <tr bordercolor="#000000"> <td> <xsl:value-of select="title"/></td> <td> <xsl:value-of select="author"/></td> <td> <xsl:value-of select="isbn"/></td> <td> <xsl:value-of select="publishername"/></td> <td> <xsl:value-of select="edition"/></td> <td> <xsl:value-of select="price"/></td> </tr> </xsl:for-each> </tbody> </table> </body> </html> </xsl:template> </xsl:stylesheet>

Page No:

Aim: /* Developing Color bean using BDK */


Colors.java: package sunw.demo.colors; import java.awt.*; import java.awt.event.*; public class Colors extends Canvas { transient private Color color; private boolean rectangular; public Colors() { addMouseListener(new MouseAdapter() { public void mousePressed(MouseEvent me) { change(); } }); rectangular = false; setSize(200, 100); change(); } public boolean getRectangular() { return rectangular; } public void setRectangular(boolean flag) { this.rectangular = flag; repaint(); } public void change() { color = randomColor(); repaint(); } private Color randomColor() { int r = (int)(255*Math.random()); int g = (int)(255*Math.random()); int b = (int)(255*Math.random()); return new Color(r, g, b); } public void paint(Graphics g) { Dimension d = getSize(); int h = d.height; int w = d.width; g.setColor(color); if(rectangular) { g.fillRect(0, 0, w-1, h-1); } else { Page No:

g.fillOval(0, 0, w-1, h-1); }}} Procedure: Compile the Source Code for the New Bean Compile the source code to create a class file.: javac Colors.java. Create a Manifest File You must now create a manifest file. First, switch to the c:\\bdk\\demo directory. This is the directory in which the manifest files for the BDK demos are located. Put the source code for your manifest file in the file colors.mft. It is shown here: Name: sunw/demo/colors/Colors.class Java-Bean: True This file indicates that there is one .class file in the JAR file and that it is a Java Bean. Notice that the Colors.class file is in the package sunw.demo.colors and in the subdirectory sunw\\demo\\colors relative to the current directory. Generate a JAR File Beans are included in the ToolBox window of the BDK only if they are in JAR files in the directory c:\\bdk\\jars. These files are generated with the jar utility: jar cfm ..\\jars\\colors.jar colors.mft sunw\\demo\\colors\\*.class This command creates the file colors.jar and places it in the directory c:\\bdk\\jars. (You may wish to put this in a batch file for future use.) Start the BDK Change to the directory c:\\bdk\\beanbox and type run. This causes the BDK to start. You should see three windows, titled ToolBox, BeanBox, and Properties. The ToolBox window should include an entry labeled "Colors" for your new Bean. Create an Instance of the Colors Bean After you complete the preceding steps, create an instance of the Colors Bean in the BeanBox window. Test your new component by pressing the mouse anywhere within its borders. Its color immediately changes. Use the Properties window to change the rectangular property from false to true. Its shape immediately changes. Create and Configure an Instance of the OurButton Bean Create an instance of the OurButton Bean in the BeanBox window. Then follow these steps: 1. Go to the Properties window and change the label of the Bean to "Change". You should see that the button appearance changes immediately when this property is changed. 2. Go to the menu bar of the BeanBox and select Edit | Events | action | Page No:

actionPerformed. 3. Move the cursor so that it is inside the Colors Bean display area, and click the left mouse button. You should see the Event Target Dialog dialog box. 4. The dialog box allows you to choose a method that should be invoked when this button is clicked. Select the entry labeled "change" and click the OK button. You should see a message box appear very briefly, stating that the tool is "Generating and compiling adaptor class." 5. Click on the button. You should see the color change.

Page No:

AIM: /*Retrieving request parameters, Init parameter and context parameter using servlets*/
Index.html: <html> <head> </head> <body> <form action="MyServlet " method="post"> username:<input type="text" name="user"></br> password:<input type="password" name="pwd"/></br> <input type="submit" value="click"></form> </body> </html> MyServlet.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class MyServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException { res.setContentType("text/html"); PrintWriter out=res.getWriter(); String user1= req.getParameter("user"); String password=req.getParameter("pwd"); out.println("<html><body><h1>welcome"+ user1+"your password is +password+"</h1></body></html>"); out.println("\nThe email address is " + getServletConfig().getInitParameter("Email")); out.println("The address is " + getServletConfig().getInitParameter("Address")); out.println("The phone no is " + getServletConfig().getInitParameter("Mobile")); out.println("\n"); out.println("The name is " + getServletContext().getInitParameter("name")); } }

Page No:

Web.xml: <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4"> <display-name>Welcome to Tomcat</display-name> <description> Welcome to Tomcat </description> <context-param> <param-name>name</param-name> <param-value>swarna</param-value> </context-param> <servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>MyServlet</servlet-class> <init-param> <param-name>Email</param-name> <param-value>abcd@gmail.com</param-value> </init-param> <init-param> <param-name>Address</param-name> <param-value>c/0 abcd</param-value> </init-param> <init-param> <param-name>Mobile</param-name> <param-value>9857656856</param-value> </init-param> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/MyServlet</url-pattern> </servlet-mapping> </web-app>

Page No:

AIM:/*Create table in database which contain the details of book as book name, quantity, price , total amount . Insert and extract the data from tables and display them by using Statement of jdbc*/ StmtDemo.java: import java.sql.*; public class StmtDemo { public static void main (String[] args) { Connection con = null;

try { String userName = "root"; String password = "abcd"; String url = "jdbc:mysql://localhost:3306/ss"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); con = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); Statement stmt=con.createStatement(); System.out.println ("statement created"); stmt.executeUpdate("CREATE TABLE Books(Name CHAR(30),quantity INT UNSIGNED NOT NULL,price CHAR(10) ,amount CHAR(10) NOT NULL)"); System.out.println ("table created"); stmt.executeUpdate("Insert into Books values('computer Graphics', 4, '300', '1200')"); System.out.println ("values inserted"); ResultSet rs=stmt.executeQuery("select * from Books"); while(rs.next()) Page No:

{ System.out.println(" Book Name is="+rs.getString(1)); System.out.println(" Quantity isis="+rs.getInt(2)); System.out.println("Price is="+rs.getString(3)); System.out.println("total Amount is="+rs.getString(4));

} catch (Exception e) { System.err.println ("Cannot connect to database server"); } finally { if (con != null) { try { con.close (); System.out.println ("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } } }

Page No:

OUTPUT:

AIM:/* Insert and extract the data into/from book table and display them where book table contains book name, quantity, price , total amount using PreparedStatement of jdbc */

PrepareStmtDemo.java: import java.sql.*; public class PrepareStmtDemo { public static void main (String[] args) { Page No:

Connection con = null; try { String userName = "root"; String password = "abcd"; String url = "jdbc:mysql://localhost:3306/ss"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); con = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); Statement stmt=con.createStatement(); System.out.println ("statement created"); PreparedStatement ps=con.prepareStatement("INSERT INTO Books VALUES(?,?,?,?)"); ps.setString(1,"WEBTECHNOLOGIES"); ps.setInt(2,3); ps.setString(3,"200Rs"); ps.setString(4,"600Rs"); ps.executeUpdate(); System.out.println ("values inserted"); ResultSet rs=stmt.executeQuery("select * from Books"); while(rs.next()) { System.out.println("Name is="+rs.getString(1)); System.out.println(" Quantity isis="+rs.getInt(2)); System.out.println("Price is="+rs.getString(3)); System.out.println("total Amount is="+rs.getString(4)); } ps=con.prepareStatement("update Books set Price= ? where Name = ? "); ps.setString(1,"100");

Page No:

ps.setString(2,"WEBTECHNOLOGIES"); ps.executeUpdate(); System.out.println ("values Upted"); ps.executeUpdate(); rs=stmt.executeQuery("select * from Books"); while(rs.next()) { System.out.println("Name is="+ rs.getString(1)); System.out.println("Quantityis="+rs.getInt(2)); System.out.println("Price is="+ rs.getString(3)); System.out.println("Amount is="+rs.getString(4)); } } catch (Exception e) { System.err.println ("Cannot connect to database server"); } finally { if (con != null) { try { con.close (); System.out.println ("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } }

Page No:

} } }

OUTPUT:

AIM:/* create procedure which displays a simle message and call the procedure using Callble Statement of jdbc*/
Procedure -HelloWorld() mysql> DELIMITER / ; mysql> CREATE PROCEDURE Helloworld() BEGIN SELECT HELLO HAI as Meassage; END CallableStmtDemo.java import java.sql.*; public class CallStmtDemo { Page No:

public static void main (String[] args) { Connection con = null; try { String userName = "root"; String password = "abcd"; String url = "jdbc:mysql://localhost:3306/ss"; Class.forName ("com.mysql.jdbc.Driver").newInstance (); con = DriverManager.getConnection (url, userName, password); System.out.println ("Database connection established"); Statement stmt=con.createStatement(); System.out.println ("statement created"); CallableStatement cs=con.prepareCall("{ call Helloworld()}"); cs.executeUpdate(); ResultSet rs=cs.executeQuery(); rs.next(); System.out.println("Message is="+rs.getString("Message")); } catch (Exception e) { System.err.println ("Cannot connect to database server"); } finally { if (con != null) { try { con.close (); System.out.println ("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } } } OUTPUT:

Page No:

Page No:

Page No:

Page No:

Vous aimerez peut-être aussi