0% found this document useful (0 votes)
13 views20 pages

JavaScript Form Validation Guide

Here are the steps to create a database table to store book details, insert data into the table, and retrieve and display the data: 1. Create a database connection: ```java Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/bookdb", "username", "password"); ``` 2. Create a Statement object to execute the SQL statements: ```java Statement stmt = conn.createStatement(); ``` 3. Create the books table: ```sql CREATE TABLE books ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), quantity INT, price FLOAT, total FLOAT ); ```

Uploaded by

John Timothy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views20 pages

JavaScript Form Validation Guide

Here are the steps to create a database table to store book details, insert data into the table, and retrieve and display the data: 1. Create a database connection: ```java Connection conn = DriverManager.getConnection( "jdbc:mysql://localhost:3306/bookdb", "username", "password"); ``` 2. Create a Statement object to execute the SQL statements: ```java Statement stmt = conn.createStatement(); ``` 3. Create the books table: ```sql CREATE TABLE books ( id INT PRIMARY KEY AUTO_INCREMENT, name VARCHAR(100), quantity INT, price FLOAT, total FLOAT ); ```

Uploaded by

John Timothy
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd

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=[Link]("name").value; var ps=[Link]("pass").value; var flag=1; if(![Link](uname)) { alert("Improper [Link] have only characters\n\ and length should be > 6"); flag=0; } if(![Link](ps)) { alert("Improper [Link] have min 6 characters"); flag=0; } var pattern=/^([a-zA-Z0-9_.-])+@([a-zA-Z0-9_.-])+\.([a-zA-Z])+([a-zA-Z])+/; var email=[Link]("email").value; if(![Link](email)) { alert("Improper [Link] be of the form name@[Link]"); flag=0; } var phne=/^[0-9]{10}$/; var phone=[Link]("phone").value; if(![Link](phone)) { alert("Phone number contains only ten digits"); flag=0; } if(flag==0) { return false; } else { return true; } } </script> </head> <body background="pics/[Link]" > 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 */

[Link]: <?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>

[Link]: <?xml version="1.0" encoding="iso-8859-1"?> <xsl:stylesheet version="1.0" xmlns:xsl="[Link] <xsl:output method="html" encoding="iso-8859-1" doctype-public="-//W3C//DTD XHTML 1.0 Transitional//EN" doctypesystem="[Link] <xsl:template match="book-info"> <html xmlns="[Link] <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 */


[Link]: package [Link]; import [Link].*; import [Link].*; 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) { [Link] = flag; repaint(); } public void change() { color = randomColor(); repaint(); } private Color randomColor() { int r = (int)(255*[Link]()); int g = (int)(255*[Link]()); int b = (int)(255*[Link]()); return new Color(r, g, b); } public void paint(Graphics g) { Dimension d = getSize(); int h = [Link]; int w = [Link]; [Link](color); if(rectangular) { [Link](0, 0, w-1, h-1); } else { Page No:

[Link](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 [Link]. 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 [Link]. It is shown here: Name: sunw/demo/colors/[Link] 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 [Link] file is in the package [Link] 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\\[Link] [Link] sunw\\demo\\colors\\*.class This command creates the file [Link] 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*/
[Link]: <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> [Link] import [Link].*; import [Link].*; import [Link].*; public class MyServlet extends HttpServlet { public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException,IOException { [Link]("text/html"); PrintWriter out=[Link](); String user1= [Link]("user"); String password=[Link]("pwd"); [Link]("<html><body><h1>welcome"+ user1+"your password is +password+"</h1></body></html>"); [Link]("\nThe email address is " + getServletConfig().getInitParameter("Email")); [Link]("The address is " + getServletConfig().getInitParameter("Address")); [Link]("The phone no is " + getServletConfig().getInitParameter("Mobile")); [Link]("\n"); [Link]("The name is " + getServletContext().getInitParameter("name")); } }

Page No:

[Link]: <?xml version="1.0" encoding="ISO-8859-1"?> <web-app xmlns="[Link] xmlns:xsi="[Link] xsi:schemaLocation="[Link] [Link] 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@[Link]</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*/ [Link]: import [Link].*; 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"; [Link] ("[Link]").newInstance (); con = [Link] (url, userName, password); [Link] ("Database connection established"); Statement stmt=[Link](); [Link] ("statement created"); [Link]("CREATE TABLE Books(Name CHAR(30),quantity INT UNSIGNED NOT NULL,price CHAR(10) ,amount CHAR(10) NOT NULL)"); [Link] ("table created"); [Link]("Insert into Books values('computer Graphics', 4, '300', '1200')"); [Link] ("values inserted"); ResultSet rs=[Link]("select * from Books"); while([Link]()) Page No:

{ [Link](" Book Name is="+[Link](1)); [Link](" Quantity isis="+[Link](2)); [Link]("Price is="+[Link](3)); [Link]("total Amount is="+[Link](4));

} catch (Exception e) { [Link] ("Cannot connect to database server"); } finally { if (con != null) { try { [Link] (); [Link] ("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 */

[Link]: import [Link].*; 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"; [Link] ("[Link]").newInstance (); con = [Link] (url, userName, password); [Link] ("Database connection established"); Statement stmt=[Link](); [Link] ("statement created"); PreparedStatement ps=[Link]("INSERT INTO Books VALUES(?,?,?,?)"); [Link](1,"WEBTECHNOLOGIES"); [Link](2,3); [Link](3,"200Rs"); [Link](4,"600Rs"); [Link](); [Link] ("values inserted"); ResultSet rs=[Link]("select * from Books"); while([Link]()) { [Link]("Name is="+[Link](1)); [Link](" Quantity isis="+[Link](2)); [Link]("Price is="+[Link](3)); [Link]("total Amount is="+[Link](4)); } ps=[Link]("update Books set Price= ? where Name = ? "); [Link](1,"100");

Page No:

[Link](2,"WEBTECHNOLOGIES"); [Link](); [Link] ("values Upted"); [Link](); rs=[Link]("select * from Books"); while([Link]()) { [Link]("Name is="+ [Link](1)); [Link]("Quantityis="+[Link](2)); [Link]("Price is="+ [Link](3)); [Link]("Amount is="+[Link](4)); } } catch (Exception e) { [Link] ("Cannot connect to database server"); } finally { if (con != null) { try { [Link] (); [Link] ("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 [Link] import [Link].*; 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"; [Link] ("[Link]").newInstance (); con = [Link] (url, userName, password); [Link] ("Database connection established"); Statement stmt=[Link](); [Link] ("statement created"); CallableStatement cs=[Link]("{ call Helloworld()}"); [Link](); ResultSet rs=[Link](); [Link](); [Link]("Message is="+[Link]("Message")); } catch (Exception e) { [Link] ("Cannot connect to database server"); } finally { if (con != null) { try { [Link] (); [Link] ("Database connection terminated"); } catch (Exception e) { /* ignore close errors */ } } } } } OUTPUT:

Page No:

Page No:

Page No:

Page No:

Common questions

Powered by AI

Constructing a manifest file for a JavaBean involves specifying the path to the class file and specifying that it is a Java Bean. The manifest file, typically named with a .mft extension, includes entries such as 'Name:', which indicates the class file path, and 'Java-Bean: True', which identifies it as a JavaBean. This file is essential for generating a JAR which the BDK can recognize and incorporate into its ToolBox .

MyServlet.java retrieves initialization parameters using getServletConfig().getInitParameter() for servlet-specific parameters like 'Email', 'Address', and 'Mobile', which are respectively set to 'abcd@gmail.com', 'c/0 abcd', and '9857656856'. It retrieves context parameters using getServletContext().getInitParameter(), specifically for the 'name' parameter, which is set to 'swarna' .

The registration form uses JavaScript to enforce validation criteria as follows: the username must contain only characters and have a length between 6 and 20 characters, the password must be a string of characters between 6 and 20 characters long and can include special characters, the email must conform to the pattern of 'name@domain.com', and the phone number must be exactly ten digits long .

The transformation between XML and HTML is performed using an XSLT stylesheet. The stylesheet specifies an HTML structure that matches the elements in the XML file, rendering each 'book' element as a row in an HTML table with extracted data from XML elements such as 'title', 'author', 'isbn', etc. The purpose of this transformation is to allow XML data, which is well-organized and easily parsed, to be displayed in a web browser-friendly HTML format .

The DOM parser is used to parse the XML file (book.xml) into a DOM tree structure, allowing for validation and data extraction. In the context of the document, it supports validating the structure of XML data against rules defined within the DOM and facilitates the transformation of XML data into HTML using XSLT stylesheets. This mechanism enables the display of XML content in a specified format .

The servlet example in MyServlet.java exposes security vulnerabilities such as displaying passwords in HTML, which can lead to eavesdropping and storing sensitive information in plaintext. The servlet uses init parameters and context parameters that could be exploited if not secured properly. The application does not implement HTTPS for secure communication, lacks input validation to prevent injection attacks, and does not sanitize parameters, potentially exposing it to cross-site scripting (XSS) or SQL injection .

The document demonstrates several SQL operations using JDBC including creating a table with specified columns, inserting records using both Statement and PreparedStatement, executing queries and processing results with ResultSet, updating existing records, and closing connections. Additionally, it involves executing stored procedures using CallableStatement for invoking a predefined procedure in the database .

Creating a JavaBean using BDK involves the following steps: compiling the Java source to create a class file (e.g., Colors.java), creating a manifest file denoting the class as a Java Bean and placing it in the appropriate directory, generating a JAR file containing the Bean's class file using the jar utility, and finally placing this JAR in the BDK's jars directory. Starting the BDK should show the new Bean in the ToolBox window. The Bean can then be tested by interacting with it in the BeanBox and altering its properties through the Properties window .

The regular expressions used in the form validation effectively ensure that usernames only consist of alphabetic characters with a specified length, passwords allow specific special characters, emails conform to a standard address pattern, and phone numbers are exactly ten digits. However, they have limitations such as being unable to validate complex email rules (e.g., domain validation) or preventing all possible invalid input forms (e.g., bypassing restrictions using special character encodings).

The 'randomColor()' method in the Colors JavaBean generates a random color by creating Color objects with random RGB values. This method returns a Color object made with random integers between 0 and 255 for the red, green, and blue components, and is used to change the color display of the JavaBean during interaction .

You might also like