You are on page 1of 51

Week-1: HTML AIM: Design the following static web pages required for an online book store web

site. 1) HOME PAGE: 2) LOGIN PAGE 3) CATALOGE PAGE DESCRIPTION: 1. HOME PAGE The static home page must contain three frames. Top frame : Logo and the college name and links to Home page, Login page, Registration page, Catalogue page and Cart page (the description of these pages will be given below). Left frame : At least four links for navigation, which will display the catalogue of respective links. For e.g.: When you click the link CSE the catalogue for CSE Books should be displayed in the Right frame. Right frame: The pages to the links in the left frame must be loaded here. Initially this page contains description of the web site. Web Site Name Logo Home CSE ECE EEE CIVIL Login Registration Catalogue Cart

Description of the Web Site

2. LOGIN PAGE: Logo Home CSE ECE EEE CIVIL

This page looks like below: Web Site Name

Login

Registration

Catalogue

Cart

Login : Password: Submit Reset

3) CATOLOGUE PAGE: The catalogue page should contain the details of all the books available in the web site in a table. The details should contain the following: 1. 2. 3. 4. 5. Snap shot of Cover Page. Author Name. Publisher. Price. Add to cart button.

Web Site Name Logo Home CSE ECE EEE CIVIL Book : AI Author : S.Russel Publication Princeton hall $ 63 : Login Registration Book : XML Bible Author : Winston Publication : Wiely Catalogue $ 40.5 Cart

Book : Java 2 $ 35.5 Author : Watson Publication : BPB publications Book : HTML in 24 $ 50 hours Author : Sam Peter Publication : Sam publication

Note: Week 2 contains the remaining pages and their description.

atri.html <html> <head> <title>Home Page</title> </head> <frameset rows="20%,*"> <frame src="top.html"name="top" noresize> <frameset cols="15%,*"> <frame src="left.html" name="left" noresize> <frame src="right.html" name="frame2" noresize> </frameset> </frameset> </html> top.html </html> <head> <title>logo</title> </head> <body bgcolor=#7D9EC0> <img src="a.jpg" width=50 height=50 align=left> <center><font size=6 color="green"> AURORA SHOPPING CART</font> </center></br> <pre> </pre> <font face="copperplate Gothic Bold" size=5> <pre> <a href=right.html target="frame2">HOME</a> <a href=login.html target="frame2">LOGIN</a> <a href=registration.html target="frame2">REGISTRATION</a> <a href=catalog.html target="frame2">CATALOG</a> <a href=cart.html target="frame2">CART</a> </pre> </font> </body> </html>

left.html <html> <head> <title>Links</title> </head> <body bgcolor="#B6AFA9"> <a href=catalog.html target="frame2"> CSE</a></br> <a href=tobedone.html target="frame2"> ECE</a></br> <a href=tobedone.html target="frame2"> EEE</a></br> <a href=tobedone.html target="frame2"> MECH</a></br> </body> </html> right.html <html> <head> <title>Links</title> </head> <body bgcolor="#EBC79E"> <pre> </pre> <center> <p> This is information about the site </p></center> </body> </html>

Output Screen:

LOGIN PAGE login.html <html> <head> <title>LOGIN</title> </head> <body bgcolor=#EBC79E> <center> </br> </br> </br> </br> USERNAME:<input type=text name=login></br> <p>PASSWORD:<input type=password name=password></br></p> </br> <p><pre><input type="submit" value="submit"> <input type="reset" value="clear"></p> </pre> </body> </html>

Output Screen:

CATALOGUE PAGE catalog.html <html> <head> <title> Catalog</title> </head> <body bgcolor=#EBC79E > <table border=1 align=center width=100% height=100%> <tr> <td> <img src="JSP.jpg" align=center width=200 height=150> <td> Book:Java Server Pages<br> Author:winston<br> publisher:ORIELLY<br> </td> <td> $40</td> <td><input type=button value="add to cart" name=cart></td> </tr> <tr> <td> <img src="SCJP.jpg" width=200 height=150> <td> Book:Sun Certified JavaProgramming <br> Author:B-russel <br> publisher:Princeton <br> </td> <td> $50</td> <td><input type=button value="add to cart" align=cnetername=cart></td> </tr> <tr> <td> <img src="java2.jpg" width=200 height=150> <td> Book:Java2<br> Author:Schildth<br> publisher:Tata McGrawHill<br> </td> <td> $60</td> <td><input type=button value="add to cart" name=cart></td> <tr> <td> <img src="WP.jpg" width=200 height=150> <td> Book:Web Programming<br> Author:cHRIS BATES<br> publisher:Tata McGrawHill<br>

</td> <td> $60</td> <td><input type=button value="add to cart" name=cart></td> </tr> </tr> </table> </body> </html>

10

Output Screen:

11

Week-2: HTML AIM: To design web page 4) CART PAGE: 5) REGISTARTION PAGE DESCRIPTION:The cart page contains the details about the books which are added to the cart. The cart page should look like this: Web Site Name Logo Home CSE ECE EEE CIVIL Lo Registration gin Book name Java 2 XML bible Catalogue Price $35.5 $40.5 Quantity 2 1 Total amount Cart Amount $70 $40.5 $130.5

5) REGISTRATION PAGE: Create a registration form with the following fields 1) Name (Text field) 2) Password (password field) 3) E-mail id (text field) 4) Phone number (text field) 5) Sex (radio button) 6) Date of birth (3 select boxes) 7) Languages known (check boxes English, Telugu, Hindi, Tamil) 8) Address (text area)

12

CART PAGE: cart.html <html> <head> <title> cart</title> </head> <body bgcolor=#EBC79E > <table align="center" width=500 height=250 > <thead> <th> <font color=green> Book Name </font></th> <th> <font color=green> Price </font> </th> <th> <font color=green> Quantity </font> </th> <th> <font color=green> Amount </font></th> </thead> <tbody> <tr> <th> Java 2</th> <th> $35.5</th> <th> 2</th> <th> $71</th> </tr> <tr> <th> Oracle</th> <th> $55.5</th> <th> 3</th> <th> $120</th> </tr> <tr> <th> Operating System</th> <th> $25.5</th> <th> 2</th> <th> $51</th> </tr> </tbody> </table> </body> </html>

13

Output Screen:

14

REGISTRATION PAGE registration.html <html> <head> <title>Registration</title> </head> <body bgcolor=#EBC79E> <center> <table align=center cellspacing=10 cellpadding=5> <caption align=center> REGISTRATION </caption> <tr > <td>USERNAME :</td> <td > <input type=text name=login></td> <td></td> <td></td> </tr> <tr > <td>PASSWORD:</td> <td ><input type=password name=password></td> <td></td> <td></td> </tr> <tr > <td>E-mail id:</td> <td ><input type=text name=email></td> <td></td> <td></td> </tr> <tr> <td>Phone Number:</td> <td ><input type=text name=phonenum></td> <td></td> <td></td> </tr> <tr > <td>sex</td> <td><input type=radio name=sex value="male">male</td>

15

<td ><input type=radio name=sex value="female"> female</td> <td></td> </tr> <tr > <td>Date of Birth:</td> <td> Date<select> <option>1</option> <option>2</option> </select> </td> <td> Month<select> <option>1</option> <option>2</option> </select> </td> <td> Year<select> <option>1988</option> <option>2008</option> </select> </td> </tr> </tr> <tr> <td>Languages</td> </tr> <tr> <td></td> <td><input type=checkbox name=lgroup>Telugu</td> <td><input type=checkbox name=lgroup>Hindi</td> <td></td> </tr> <tr> <td></td> <td><input type=checkbox name=lgroup>English</td> <td><input type=checkbox name=lgroup>Tamil</td></tr> <tr> <td> Address</td><td><textarea rows=5 columns=10></textarea></td></tr> </body></html>

16

Output Screens:

17

WEEK 3: VALIDATION AIM: To do validation for registration page using JavaScript. DESCRIPTION: Write JavaScript to validate the following fields of the above registration page. 1. Name (Name should contains alphabets and the length should not be less than 6 characters). 2. Password (Password should not be less than 6 characters length). 3. E-mail id (should not contain any invalid and must follow the standard pattern (name@domain.com) 4. Phone number (Phone number should contain 10 digits only). Note: You can also validate the login page with these parameters. validation.html <html> <head> <title>Registration</title> <script type="text/javascript"> function validate() { var c1=new RegExp("^[\\w]{6,}$"); var c2=new RegExp("^[\\w]{6,}$"); var c3=new RegExp("^[\\w]+@[\\w]+.com$"); var c4=new RegExp("^[\\d]{10}$"); var name=document.f.user.value; var pwd=document.f.pwd.value; var email=document.f.email.value; var phone=document.f.phone.value; var error=""; if(!name.match(c1)) { error+="should be min of 6 char\n" }

18

if(!pwd.match(c2)) { error+="should be min of 6 char\n" } if(!email.match(c3)) { error+="should be of format name@domain.com\n" } if(!phone.match(c4)) { error+="should be of 10 digits" } window.alert(error); } </script> </head> <body bgcolor=#7D9EC0> <center> <form name=f> <table align=center border=0 width=65% height=100%> <caption align=center> REGISTRATION FORM </caption> <tr > <td>UserName :</td> <td > <input type=text name=user></td> </td> </tr> <tr> <td>Password:</td> <td ><input type=password name=pwd></td> </tr> <tr > <td>E-mail id:</td> <td ><input type=text name=email></td> </tr>

19

<tr> <td>Phone Number:</td> <td ><input type=text name=phone></td> <td> <p id= "ph"> </p></td> </tr> <tr> <td><input type=button value="Submit" onclick=validate()></td> <td><input type=reset value="Reset"></td> </tr> </table> </form> </body> </html>

20

Output Screen:

21

Week-4: CSS AIM: Write a program illustrating various methods in cascading style sheets. 1) Use different font, styles 2) Set a background image 3) Control the repetition of the image 4) Define styles for links 5) Work with layers 6) Add a customized cursor DESCRIPTION: Design a web page using CSS (Cascading Style Sheets) which includes the following: 1) Use different font, styles: In the style definition you define how each selector should work (font, color etc.).Then, in the body of your pages, you refer to these selectors to activate the styles. 2) Set a background image for both the page and single elements on the page. You can define the background image for the page like this: 3) Control the repetition of the image with the background-repeat property. As background-repeat: repeat 4) Define styles for links as 5) Work with layers: 6) Add a customized cursor: Selector {cursor:value} .xlink {cursor:crosshair} .hlink{cursor:help}

22

1. Font syles <html> <head> <title> styles</title> <style type="text/css"> b.headline {color:red;font-size:22pt;font-family:arial;text-decoration:none} </style> </head> <body> <b> this is normal bold</b> <br /> <b class="headline"> this is headline style bold</b> </body> </html> Output Screen:

23

2. Background image 0 Output Screens:

3.Control repeat <html> <head> <style> body{ background-image:url(winter.jpg); background-repeat:no-repeat; } </style> </head> </body> <h2> this is the body of the page where the image is repeated</h2> </body> </html> Output Screen:

24

5. Different types of links <html> <head> <style type="text/css"> a:link {text-decoration:underline;color=red} a:active{ text-decoration;OVERLINE;COLOR:green} a:visited{ text-decoration;COLOR:yellow} a:hover{ text-decoration:overline; color=green} </style></head> <body> <h2> these are links </h2> <a href=LINKSTYLES.html >LINK1</a><br /><br /><br /> <a href=LINKSTYLES.html >LINK2</a><br /><br /><br /> <a href=3.html >LINK3</a><br /><br /><br /> <a href=4.html >LINK4</a><br /> </body></html>

25

Output Screens:

6. Work with layers <html> <head> <title> WORKING WITH LAYERS</TITLE> </head> <body> <div style="position: absolute;top: 50px;left: 5px;z-index: 2;fontsize:50PX;color:red">LAYER 1 </div> <div style="position: absolute;top: 70px;left: 50px;z-index: 1;fontsize:50PX;color:green">LAYER 2 </div> </body> </html> Output Screens:

26

Week-5: User Authentication: Assume four users user1,user2,user3 and user4 having the passwords pwd1,pwd2,pwd3 and pwd4 respectively. Write a servelet for doing the following. If he is a valid user(i.e., user-name and password match) you should welcome him by name(user-name) else you should display You are not an authenticated user . Use init-parameters to do this. Store the user-names and passwords in the web.xml and access them in the servlet by using the getInitParameters() method. login.html <html> <head> <title>LOGIN</title> </head>

27

<body bgcolor=pink> <pre> <form method="post" action="valid"> USERNAME:<input type=text name=user> PASSWORD:<input type=password name=pwd> <input type="submit" value="submit"> </form> </pre> </body> </html> web.xml <web-app> <servlet> <init-param> <param-name>shyam</param-name> <param-value>sunder</param-value> </init-param> <init-param> <param-name>shy</param-name> <param-value>sun</param-value> </init-param> <init-param> <param-name>pshyam</param-name> <param-value>psunder</param-value> </init-param> <servlet-name>a</servlet-name> <servlet-class>Validation</servlet-class> </servlet> <servlet-mapping> <servlet-name>a</servlet-name> <url-pattern>/valid</url-pattern> </servlet-mapping> </web-app> Validation.java <input type="reset" value="clear">

28

import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Validation extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Get parameter from HTTP request. String user = request.getParameter("user"); String pwd = request.getParameter("pwd"); ServletConfig config =getServletConfig(); if(((String)config.getInitParameter(user))!=null) { String pass=(String)config.getInitParameter(user); if(pass.equals(pwd)) out.println("<h1>Welcome to "+user+"</h1>"); else out.println("<h1>Not a valid User</h1>"); }else out.println("<h1>Not a valid User</h1>"); } } Output Screens:

29

Week-6:

30

Install Tomcat web server and APACHE. While installation assign port number 4040 to TOMCAT and 8080 to APACHE. Make sure that these ports are available i.e., no other process is using this port. Access the above developed static web pages for books web site, using these servers by putting the web pages developed in week-1 and week-2 in the document root. Access the pages by suing the urls http://localhost:4040/rama/books.html(for tomcat) http://localhost:8080/books.html(for Apache) Installation of Tomcat Server and Apache Server Tomcat is a Pure Java Web Server with support for the Servlet and JSP Specification. In order to use it you must first install a Java Runtime Environment. JSP requires a Java Compiler included in the SDK, but not in the JRE. So one have to install SDK instead of JRE. Before you install and Run TOMCAT, make sure that the JAVA-HOME Environment variable is set to the installation directory of your Java Environment and that the Java bin is included in the PATH Environment variable. To set JAVA-HOME Right click on the My Computer icon on your Desktop and select properties. Click the Advanced tab Click the Environment variable Button Click new Enter JAVA-HOME as the variable name and the directory where you installed Java.

Tomcat server is an Open-Server Job based Web Application contains creator to Run Servlet and Java server page Web application. For installing TOMCAT on windows, select Jakarta Tomcat-5.5.zip from the driver(where we save it) for instance in a directory named C:\>Jakarta Use the command prompt window where you set the JAVA-HOME and Path environment variable earlier change to the directories in which we downloaded. C:\>cd jakarta C:\>Jakarta>jar It creates a director structure.

31

We should set the Catalina-home environment variable to point to the Tomcatinstallation directory.To start the server in a separate window, change to bin directory and run the startup.bat file.Just leaves this window open; this is where the server process is running. Testing The tomcat installation directory contains a number of sub directories. BIN- it contains windows batch files for starting and stopping the server. Conf-Tomcat Configuration files. Web-apps-Default location web application served by Tomcat. Logs-Server log file, if something doesnt work as excepted, look in this file directory for clues as to whats wrong. Work-a directory for tempory files created by the JSP contain and other files. To test the server run the start up script and open a browser and enter URL in the Address field.http://localhost:8080/...... The Tomcat main page is shown in the browser and we can run now as servlets and JSP examples bond led with TOMCAT to ensure everything works. To execute application. User application folder---WEB-INF, classes, web.xml Classes---.java,. class. To execute a simple application for ex.login page. Click on startup batch file to start server Create an application folder ex.servletone Create subfolder for classes. In class folder write a java file. Compile the java files,it gives.class file. Create an xml file place web.xml in WEB-INF. Keep our application folder in web page. Open internet explorer. Type http://localhost:8080/,we get TOMCAT home page. Select Tomcat manager enter user and password. Check our context path is present /not. Append the Url name specified in .xml file to the browser http://localhost:8080/servletone/login

32

register.html <html> <head> <title>LOGIN</title> </head> <body bgcolor=pink> <pre> <form method="post" action="register"> USERNAME:<input type=text name=name> AGE:<input type=text name=age> ADDRESS:<input type=text name=addr> <input type="submit" value="submit"> <input type="reset" value="clear"> </form> </pre> </body> </html> web.xml <web-app> <servlet> <servlet-name>a</servlet-name> <servlet-class>Register</servlet-class> </servlet> <servlet-mapping> <servlet-name>a</servlet-name> <url-pattern>/register</url-pattern> </servlet-mapping> <servlet> <servlet-name>b</servlet-name> <servlet-class>View</servlet-class> </servlet> <servlet-mapping> <servlet-name>b</servlet-name>

33

<url-pattern>/view</url-pattern> </servlet-mapping> </web-app> Register.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Register extends HttpServlet { public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Get parameter from HTTP request. String name = request.getParameter("name"); String age = request.getParameter("age"); String addr = request.getParameter("addr"); ServletContext ctxt =getServletContext(); ctxt.setAttribute("name",name); ctxt.setAttribute("age",age); ctxt.setAttribute("addr",addr); out.println("<h1>All your details are succefully set to Context parameters</h1>"); out.println("<h1><a href='view'>Click Here to view your deatails</a></h1>"); } } View.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class View extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); ServletContext ctxt =getServletContext();

34

String name=(String)ctxt.getAttribute("name"); String age=(String)ctxt.getAttribute("age"); String addr=(String)ctxt.getAttribute("addr"); out.println("Name:"+name); out.println("<br>Age:"+age); out.println("<br>Addr:"+addr); } }

Output Screens:

35

36

37

Week-7: Write a servlet program illustrating Cookies. Addcookie.html <html> <body> <center> <form name="Form1" method="post" action="addcookieservlet"> <B>Enter a value for MyCookie:</B> <input type=textbox name="data" size=25 value=""> <input type=submit value="Submit"> </form> </body> </html> web.xml <web-app> <servlet> <servlet-name>add</servlet-name> <servlet-class>AddCookieServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>add</servlet-name> <url-pattern>/addcookieservlet</url-pattern> </servlet-mapping> <servlet> <servlet-name>get</servlet-name> <servlet-class>GetCookiesServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>get</servlet-name> <url-pattern>/getcookiesservlet</url-pattern> </servlet-mapping>

38

</web-app> AddCookieServlet.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class AddCookieServlet extends HttpServlet { public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get parameter from HTTP request. String data = request.getParameter("data"); // Create cookie. Cookie cookie = new Cookie("MyCookie", data); // Add cookie to HTTP response. response.addCookie(cookie); // Write output to browser. response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.println("<B>MyCookie has been set to"); pw.println(data); pw.println("<br><a href='getcookiesservlet'>Show my Cookie Data</a>"); pw.close(); } } GetCookieServlet.java import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class GetCookiesServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { // Get cookies from header of HTTP request.

39

Cookie[] cookies = request.getCookies(); // Display these cookies. response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.println("<B>"); for(int i = 0; i < cookies.length; i++) { String name = cookies[i].getName(); String value = cookies[i].getValue(); pw.println("name = " + name + "; value = " + value); } pw.close(); } }

40

Output Screens:

41

42

Week-8: Write a program illustrating HttpSession interface web.xml <web-app> <servlet> <servlet-name>date</servlet-name> <servlet-class>DateServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>date</servlet-name> <url-pattern>/dateservlet</url-pattern> </servlet-mapping> </web-app> DateServlet.java import java.io.*; import java.util.*; import javax.servlet.*; import javax.servlet.http.*; public class DateServlet extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { HttpSession hs = request.getSession(true); response.setContentType("text/html"); PrintWriter pw = response.getWriter(); pw.print("<B>"); // Display date/time of last access. Date date = (Date)hs.getAttribute("date"); if(date != null) { pw.print("Last access: " + date + "<br>"); } // Display current date/time. date = new Date(); hs.setAttribute("date", date); pw.println("Current date: " + date); }}

43

Output Screens:

44

Week-9: AIM: Install a database(Mysql or Oracle). Create a table which should contains at least the following fields:name,password,email-id,phone number(these should hold the data from the registration form). Practice JDBC connectivity. Write a java program/servlet/JSP to connect to that database and extract data from the tables and display them.Experiment with various SQL queries. Insert the details of the users who register with the web site whenever a new user clicks the submit button in the registration page. JavaToMySQL.java import java.sql.*; public class JavaToMySQL { public static void main(String[] args) throws SQLException, ClassNotFoundException { // Load the JDBC driver Class.forName("com.mysql.jdbc.Driver"); System.out.println("Driver loaded"); // Establish a connection Connection connection = DriverManager.getConnection("jdbc:MySQL://localhost/shyamp","root","sunder"); System.out.println("Database connected"); // Create a statement Statement statement = connection.createStatement(); // Execute a statement ResultSet resultSet = statement.executeQuery ("select * from shy"); // Iterate through the result and print the student names while (resultSet.next()) System.out.println(resultSet.getString(1) + "\t" + resultSet.getString(2) + "\t"); // Close the connection connection.close(); } }

45

MySQL Table Creation: 1.Create tatabase Mysql>create database shyamp; 2 use database. Mysql>use atri 3.Create table Mysql>create table atri(user varchar(20),pwd varchar(20)); 4.Insert values into table Mysql>insert into shy values(nestham,sai); Mysql>insert into shy values(shy,sun); enter password: ****** Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 6 Server version: 5.1.23-rc-community MySQL Community Server (GPL) Type 'help;' or '\h' for help. Type '\c' to clear the buffer. mysql> create database users; Query OK, 1 row affected (0.00 sec) mysql> use users; Database changed mysql> create table userstable(user varchar(20),pwd varchar(20)); Query OK, 0 rows affected (0.11 sec) mysql> insert into userstable values("shyam","sunder"); Query OK, 1 row affected (0.03 sec) mysql> insert into userstable values("shy","sun"); Query OK, 1 row affected (0.03 sec) mysql>

46

Output: C:\>javac JavaToMySQL.java C:\>java JavaToMySQL Driver loaded Database connected shy sun shyam sunder MySQL Table Cration: 1.Create tatabase Mysql>create database shyamp; Mysql>use shyamp Mysql>create table shy(user varchar(20),pwd varchar(20)); Mysql>insert into shy values(shyam,sunder); Mysql>insert into shy values(shy,sun);

47

Week10: AIM: Write a JSP which does the following job: Insert the details of the 3 or 4 users who register with the web site(week9) by using registration form. Authenticate the user when the submits the login form using the user name and password from the database (similar to week8 instead of cookies). Validate.java import java.sql.*; import java.io.*; import javax.servlet.*; import javax.servlet.http.*; public class Validate extends HttpServlet { public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { response.setContentType("text/html"); PrintWriter out = response.getWriter(); // Get parameter from HTTP request. String user = request.getParameter("user"); String pwd = request.getParameter("pwd"); // Load the JDBC driver try{ Class.forName("com.mysql.jdbc.Driver"); // Establish a connection Connection connection = DriverManager.getConnection("jdbc:MySQL://localhost/shyamp","root","sunder"); // Create a statement Statement statement = connection.createStatement(); // Execute a statement ResultSet resultSet = statement.executeQuery("select * from shy"); while(resultSet.next()) { if(user.equals(resultSet.getString(1))) {

48

if(pwd.equals(resultSet.getString(2))) {out.println("Welcome to "+user); return;} } } if(!resultSet.next()) out.println("Invalid User"); } catch(Exception e) { out.println("error"+e); } } } web.xml <web-app> <servlet> <servlet-name>get</servlet-name> <servlet-class>Validate</servlet-class> </servlet> <servlet-mapping> <servlet-name>get</servlet-name> <url-pattern>/validate</url-pattern> </servlet-mapping> </web-app>

49

Output Screens:

50

51

You might also like