EXP1. Time Table Using External CSS

Aim: To display my MTech time table using external CSS.

time.html

<html>

<head>

<title>M.Tech 1st Year Time Table</title>

<link rel="stylesheet" href="style.css">

</head>

<body bgcolor="white" text=black>

<img href="banner-logo_01.jpg">

<h1<center>DRK GROUP of INTITUTIONS</h1>

<h2<center>M.TECH 1<sup>st</sup> YEAR 1<sup>st</sup> SEM STUDENT TIME TABLE</h2>

<h3<center>COMMON FOR M.TECH- CSE, CS, and SE</H3>

<center>

<p<table border="10" border color="black" bgcolor="pink" height="60%" width="80%">

<tr align="center">

<th&nbsp</th>

<th>1</th>

<th>2</th>

<th>3</th>

<th>4</th>

<th>LUNCH</th>

<th>5</th>

<th>6</th>

<th>7</th>

</tr>

<tr align="center">

<th>Hour/day</th>

<th>08:00-08:50</th>

<th>08:50-09:40</th>

<th>09:40-10:30</th>

<th>10:30-11:20</th>

<th>11:20-12:10</th>

<th>12:10-01:00</th>

<th>01:00-01:50</th>

<th>01:50-02:40</th>

</tr>

<tr align="center">

<td>MON</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

<td>L</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

</tr>

<tr align="center">

<td>TUE</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

<td>U</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

</tr>

<tr align="center">

<td>WED</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

<td>N</td>

<td&nbsp</td>

<td&nbsp</td>

<td&nbsp</td>

</tr>

<tr align="center">

<td>THUR</td>

<td>SDE</td>

<td>SDE</td>

<td>OOM</td>

<td>ES</td>

<td>C</td>

<td>OOM</td>

<td>JWT</td>

<td>JWT</td>

</tr>

<tr align="center">

<td>FRI</td>

<td>APS</td>

<td>CSD</td>

<td>ES</td>

<td>CSD</td>

<td>H</td>

<td colspan=3>JWTLAB</td>

</tr>

<tr align="center">

<td>SAT</td>

<td>APS</td>

<td>JWT</td>

<td>CSD</td>

<td>SDE</td>

<td>*</td>

<td>APS</td>

<td>ES</td>

<td>OOM</td>

</tr>

</table</p>

<br>

<h3>DETAILS OF SUBJECT AND STAFF:</h3>

<table color="black" bgcolor="pink" height="30%" width="60%">

<tr align="left">

<th>S.NO</TH>

<th>CODE</TH>

<th>SUBJECT</TH>

<th>STAFF</TH>

</TR>

<tr align="left">

<TD<OL TYPE=1<LI</TD>

<TD&nbsp</TD>

<TD>APS</TD>

<TD>PURUSHOTTAM</TD>

</tr>

<tr align="left">

<TD<OL TYPE=1 start="2"<LI</TD>

<TD&nbsp</TD>

<TD>ES</TD>

<TD>SRINIVASULU</TD>

</tr>

<tr align="left">

<TD<OL TYPE=1 start="3"<LI</TD>

<TD&nbsp</TD>

<TD>SDE</TD>

<TD>FATHIMA</TD>

</tr>

<tr align="left">

<TD<OL TYPE=1 start="4"<LI</TD>

<TD&nbsp</TD>

<TD>JWT</TD>

<TD>NARESH</TD>

</tr>

<tr align="left">

<TD<OL TYPE=1 start="5"<LI</TD>

<TD&nbsp</TD>

<TD>CSD</TD>

<TD>SANDHYA</TD>

</tr>

<tr align="left">

<TD<OL TYPE=1 start="6"<LI</TD>

<TD&nbsp</TD>

<TD>OOM</TD>

<TD>KALPANA</TD>

</tr>

</body>

</TABLE>

</CENTER>

Style.css

p{color:"red";font-family:arial;}

h1{align:center;color:RED}

h2{align:center;color:RED}

h3{align:center;color:RED}

body{background-color:wheat}

OUTPUT:

EXP2. Student Registration Form

Aim: To design and validate Student Registration Form.

RegistrationValid.html:

<html>

<head<title>REGISTRATION</title>

<script type="text/javascript">

function fnamevalid(){

var a=window.document.f1.fname.value;

if(a=="" || !isNaN(a)|| a.length>10){

window.alert("please enter a valid name");

window.document.f1.fname.focus();

}

}

function lnamevalid(){

var a=window.document.f1.lname.value;

if(a=="" || !isNaN(a)|| a.length>10){

window.alert("please enter a valid name");

window.document.f1.lname.focus();

}

}

function mnovalid(){

var a=window.document.f1.mno.value;

if(a=="" || isNaN(a)|| a.length!=10){

window.alert("please enter valid mobile num");

window.document.f1.mno.focus();

}

}

function dobvalidd(){

var a=window.document.f1.date.value;

if(a=="day" ){

window.alert("please enter a valid day");

window.document.f1.date.focus();

}

}

function dobvalidm(){

var b=window.document.f1.month.value;

if(b=="month" ){

window.alert("please enter a valid month");

window.document.f1.date.focus();

}

}

function dobvalidy(){

var c=window.document.f1.year.value;

if(c=="year" ){

window.alert("please enter a valid year");

window.document.f1.date.focus();

}

}

function eidvalid(){

var a=window.document.f1.eid.value;

if(a=="" || a.indexOf('@')<1 || a.indexOf('.')<0 || a.lastIndexOf('.')==a.lastIndexOf('@')+1){

window.alert("please enter a valid email id");

window.document.f1.eid.focus();

}

}

function passwordvalid(){

var a=window.document.f1.password.value;

if(a=="" || a.length<5){

window.alert("please enter a valid password");

window.document.f1.password.focus();

}

}

function repasswordvalid(){

var b=window.document.f1.password.value;

var a=window.document.f1.repassword.value;

if(a=="" || a.length<5 || !a.match(b)){

window.alert("please reenter password");

window.document.f1.repassword.focus();

}

}

function addvalid(){

var a=window.document.f1.address.value;

if(a=="" ){

window.alert("please enter address");

window.document.f1.address.focus();

}

}

function statevalid(){

var c=window.document.f1.state.value;

if(c=="state" ){

window.alert("please enter a state");

window.document.f1.state.focus();

}

}

</script>

</head>

<body bgcolor="pink">

<hr<form name="f1" method="post" action="srf"<pre>

<h1> STUDENT REGISTRATION FORM </h1>

First Name: <input type="text" name="fname" Onblur="fnamevalid()"/</br>

Last Name: <input type="text" name="lname" Onblur="lnamevalid()"/</br>

Sex: <input type="radio" name="sex" value="Male" <span>Male</span> <input type="radio" name="sex" value="Female" <span>Female</span<br>

Mobile No: <input type="text" name="mno" Onblur="mnovalid()"/</br>

Email Id: <input type="text" name="eid" Onblur="eidvalid()"/</br>

Password: <input type="password" name="password" Onblur="passwordvalid()"/</br>

Confirm Password: <input type="password" name="repassword" Onblur="repasswordvalid()"/</br>

Address: <textarea name="address" rows="2" cols="30" Onblur="addvalid()"</textarea</br>

DOB: <select name="date" Onblur="dobvalidd()">

<option selected="" value="day">--day--</option>

<option>1</option>

<option>2</option>

<option>3</option>

<option>4</option>

<option>5</option>

</select> <select name="month" Onblur="dobvalidm()">

<option selected="" value="month">--month--</option>

<option>JAN</option>

<option>FEB</option>

<option>MAR</option>

<option>APRIL</option>

</select> <select name="year" Onblur="dobvalidy()">

<option selected="" value="year">-year--</option>

<option>1988</option>

<option>1989</option>

<option>1990</option>

<option>1991</option>

<option>1992</option>

<option>1993</option>

<option>1994</option>

<option>1995</option>

<option>1996</option</br>

</select</br>

Hobbies: <INPUT TYPE="CHECKBOX" NAME="h0" value="cricket">Games/Sports

<INPUT TYPE="CHECKBOX" NAME="h1" value="reading">Music/Movies

<INPUT TYPE="CHECKBOX" NAME="h2" value="movies">Reading/Browsing

<INPUT TYPE="CHECKBOX" NAME="h3" value="soccer">Other Activities<br>

State: <select name="state" Onblur="statevalid()">

<option selected="" value="state">--state--</option>

<option>AP</option>

<option>KA</option>

<option>KL</option>

<option>TN</option>

</select</br>

<input type="submit" value="SUBMIT"/>

<input type="reset" value="CLEAR"/</br>

</form>

</body>

</html>

OUTPUT:

EXP:3. Bio-data using external DTD

Aim: To describe my Bio-data using external DTD.

myself.dtd

<!ELEMENT aboutmyself (name, branch, institute, place, educationalqualification+, hobbies+, aim, extraactivities+)>

<!ELEMENT educationalqualification (schooling, intermediate, graduation)>

<!ELEMENT hobbies (readingnovels, music, gardening)>

<!ELEMENT extraactivities (sports, writing, music)>

<!ELEMENT name (#PCDATA)>

<!ELEMENT branch (#PCDATA)>

<!ELEMENT institute (#PCDATA)>

<!ELEMENT place (#PCDATA)>

<!ELEMENT schooling (#PCDATA)>

<!ELEMENT intermediate (#PCDATA)>

<!ELEMENT graduation (#PCDATA)>

<!ELEMENT readingnovels (#PCDATA)>

<!ELEMENT music (#PCDATA)>

<!ELEMENT gardening (#PCDATA)>

<!ELEMENT aim (#PCDATA)>

<!ELEMENT sports (#PCDATA)>

<!ELEMENT writing (#PCDATA)>

myself.xml

<!DOCTYPE aboutmyself SYSTEM "myself.dtd">

<aboutmyself>

<name> sravya </name>

<branch> it-a </branch>

<institute> drkist </institute>

<place> hyderabad </place>

<schooling> BVB public school </schooling>

<intermediate> sri chaitanya college </intermediate>

<graduation> Drk institute of science and technology </graduation>

<readingnovels> mystery novels </readingnovels>

<music> melody </music>

<gardening> flowering plants </gardening>

<aim> to be successful in life </aim>

<sports> badminton </sports>

<writing> articles,essays </writing>

<music> playing casio </music>

</aboutmyself>

OUTPUT:

EXP4.TimeTable using XSLT

Aim: To describe Mtech Time Table using XSLT.

timetable.xml

<?xml-stylesheet type="text/xsl" href="timetable.xsl"?>

<timetable>

<mon>

<p1> </p1>

<p2> </p2>

<p3> </p3>

<p4> </p4>

<p6> </p6>

<p7> </p7>

<p8> </p8>

</mon>

<tue>

<p1> </p1>

<p2> </p2>

<p3> </p3>

<p4> </p4>

<p6> </p6>

<p7> </p7>

<p8> </p8>

</tue>

<wed>

<p1> </p1>

<p2> </p2>

<p3> </p3>

<p4> </p4>

<p6> </p6>

<p7> </p7>

<p8> </p8>

</wed>

<thu>

<p1>JWT</p1>

<p2>APS</p2>

<p3>CSD</p3>

<p4>CSD</p4>

<p6>SDE</p6>

<p7>SDE</p7>

<p8>ES</p8>

</thu>

<fri>

<p1>ES</p1>

<p2>ES</p2>

<p3>OOM</p3>

<p4>JWT</p4>

<p6>JWT Lab</p6>

</fri>

<sat>

<p1>JWT</p1>

<p2>JWT</p2>

<p3>OOM</p3>

<p4>OOM</p4>

<p6>APS</p6>

<p7>ES</p7>

<p8>CSD</p8>

</sat>

</timetable>

timetable.xsl

<?xml version="1.0" encoding="ISO-8859-1"?>

<xsl:stylesheet version="1.0"

xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

<xsl:template match="/">

<html>

<body>

<center<h1>DRK GROUP OF INSTITUTIONS</h1>

<h2>M.TECH 1<sup>st</sup> YEAR 1<sup>st</sup> SEM STUDENT TIME TABLE</h2>

<h3>Common for M.Tech-CSE,CS and SE braches</h3>

<table border="1">

<tr bgcolor="#9acd32">

<th>Day</th>

<th>8-8:50</th>

<th>8:50-9:40</th>

<th>9:40-10:30</th>

<th>10:30-11:20</th>

<th>11:20-12:10</th>

<th>12:10-01:00</th>

<th>01:00-01:50</th>

<th>01:50-02:40</th>

</tr>

<xsl:for-each select="timetable/mon">

<tr>

<td>Monday</td>

<td<xsl:value-of select="p1" /</td>

<td<xsl:value-of select="p2" /</td>

<td<xsl:value-of select="p3" /</td>

<td<xsl:value-of select="p4" /</td>

<td rowspan="6"<center<br>L</br<br>U</br<br>N</br<br>C</br<br>H</br</center</td>

<td<xsl:value-of select="p6" /</td>

<td<xsl:value-of select="p7" /</td>

<td<xsl:value-of select="p8" /</td>

</tr>

</xsl:for-each>

<xsl:for-each select="timetable/tue">

<tr>

<td>Tuesday</td>

<td<xsl:value-of select="p1" /</td>

<td<xsl:value-of select="p2" /</td>

<td<xsl:value-of select="p3" /</td>

<td<xsl:value-of select="p4" /</td>

<td<xsl:value-of select="p6" /</td>

<td<xsl:value-of select="p7" /</td>

<td<xsl:value-of select="p8" /</td>

</tr>

</xsl:for-each>

<xsl:for-each select="timetable/wed">

<tr>

<td>Wednesday</td>

<td<xsl:value-of select="p1" /</td>

<td<xsl:value-of select="p2" /</td>

<td<xsl:value-of select="p3" /</td>

<td<xsl:value-of select="p4" /</td>

<td<xsl:value-of select="p6" /</td>

<td<xsl:value-of select="p7" /</td>

<td<xsl:value-of select="p8" /</td>

</tr>

</xsl:for-each>

<xsl:for-each select="timetable/thu">

<tr>

<td>Thursday</td>

<td<xsl:value-of select="p1" /</td>

<td<xsl:value-of select="p2" /</td>

<td<xsl:value-of select="p3" /</td>

<td<xsl:value-of select="p4" /</td>

<td<xsl:value-of select="p6" /</td>

<td<xsl:value-of select="p7" /</td>

<td<xsl:value-of select="p8" /</td>

</tr>

</xsl:for-each>

<xsl:for-each select="timetable/fri">

<tr>

<td>Friday</td>

<td<xsl:value-of select="p1" /</td>

<td<xsl:value-of select="p2" /</td>

<td<xsl:value-of select="p3" /</td>

<td<xsl:value-of select="p4" /</td>

<td colspan="3"<center<xsl:value-of select="p6" /</center</td>

</tr>

</xsl:for-each>

<xsl:for-each select="timetable/sat">

<tr>

<td>Saturday</td>

<td<xsl:value-of select="p1" /</td>

<td<xsl:value-of select="p2" /</td>

<td<xsl:value-of select="p3" /</td>

<td<xsl:value-of select="p4" /</td>

<td<xsl:value-of select="p6" /</td>

<td<xsl:value-of select="p7" /</td>

<td<xsl:value-of select="p8" /</td>

</tr>

</xsl:for-each>

</table>

</center>

</body>

</html>

</xsl:template>

</xsl:stylesheet>

OUTPUT:

EXP:5 Select Queries Using Statement object

Aim: To retrieve data from database server using JDBC Statement object(Type-4).

DbConnect.java:

import java.sql.*;

public class DbConnect{

public static void main(String a[])throws Exception{

//register jdbc driver by supplying Driver class object as a parameter to registerDriver method.

Driver d= DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

//get the connection from oracle-10g db sever by suppying url,username,password as parameters to getConnection method.

Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");

System.out.println("conneaction is established");

// create Statement object to send sql query

Statement s=c.createStatement();

//execute the sql query using Statement object

ResultSet r=s.executeQuery("select *from emp");

while(r.next()){

System.out.println(r.getString("ename")+"\t\t" +r.getInt("eid"));

}

//close the connection

c.close();

}

}

Procedure:

For oracle 10g, set CLASSPATH=ojdbc14.jar;.;

For oracle 9i(in our lab), set CLASSPATH=classes12.zip;.;

IP:192.168.0.249 portno:1521 sid:ora249 username:scott password:tiger

Output:

EXP:6. Non-Select queries using Statement object

Aim: To update table using JDBC Statement object(Type-4 driver).

Update.java:

import java.sql.*;

public class Update{

public static void main(String... a) {

try{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection c=DriverManager.getConnection("jdbc:oracle:thin:@locahost:1521:xe","system","tiger");

Statement s=c.createStatement();

int i=s.executeUpdate("update emp set ename='sai' where eid=456 ");

System.out.println(i);

System.out.println("the emp table is uupdated");

System.out.println(c.getClass());

System.out.println(s.getClass());

c.commit();

c.close();

}catch(SQLException s){

System.out.println("not able to get the connection");

s.printStackTrace();

}

}

}

Output:

EXP7. Non-Select query using PreparedStatement object

Aim: To insert data into emp table using JDBC PreparedStatement object(Type-4).

Prepare.java:

import java.sql.*;

public class Prepare{

public static void main(String... a){

try{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection c=DriverManager.getConnection("jdbc:oracle:thin:@127.0.0.1:1521:xe","system","tiger");

PreparedStatement p=c.prepareStatement("insert into emp values(?,?,?,?)");

p.setInt(1,456);

p.setString(2,"guru");

p.setString(3,"hyd");

p.setString(4,"cse");

p.executeUpdate();

c.commit();

c.close();

System.out.println("record is updated");

}catch(Exception e){

System.out.println("not able to get the connection");

}

}

}

Output:

EXP8. FirstServlet based on Servlet Interface

Aim: To design web-based application to implement Servlet lifecycle methods based on Servlet interface.

Project Folder Structure:

FirstServlet.java

import javax.servlet.*;

public class FirstServlet implements Servlet{

ServletConfig config;

public FirstServlet(){

this.config=config;

System.out.println("object is created");

}

public void init(ServletConfig con){

System.out.println("this s from init()");

}

public void service(ServletRequest req,ServletResponse res){

System.out.println("this s from sevice()");

}

public void destroy(){

System.out.println("this s from destroy()");

}

public ServletConfig getServletConfig(){

System.out.println("this s from getServletConfig()");

return config;

}

public String getServletInfo(){

System.out.println("this s from getServletInfo()");

return "hi from getServletInfo";

}

}

Compile the above one by setting classpath and place in classes folder.

set CLASSPATH=servlet-api.jar;.;

web.xml:

<web-app>

<servlet>

<servlet-name>fs</servlet-name>

<servlet-class>FirstServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>fs</servlet-name>

<url-pattern>/fs</url-pattern>

</servlet-mapping>

</web-app>

OUTPUT:

EXP9: RDServlet based on HttpSevlet class

Aim: To design web-based application which retrieves the data from database server using Servlet

RDServlet.java:

import javax.servlet.http.*;

import java.sql.*;

import java.io.*;

public class RDServlet extends HttpServlet{

Connection c=null;

public void init(){

System.out.println("this s from init()");

try{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

c=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.249:ora249","scott","tiger");

}catch(Exception e){

System.out.println("not able to get the connection");

}

}

public void service(HttpServletRequest req,HttpServletResponse res) throws IOException{

System.out.println("this s from service()");

res.setContentType("text/html");

res.addHeader("Cache-Control","no-cache");

PrintWriter out=res.getWriter();

try{

Statement s=c.createStatement();

ResultSet rs=s.executeQuery("select *from sai");

while(rs.next()){

out.println(rs.getString(1) +"\t" +rs.getString(2)+"\t"+rs.getString(3)+"<br>");

}

}catch(Exception e){

e.printStackTrace();

}

}

public void destroy(){

System.out.println("this s from destroy()");

try{

c.close();

}catch(Exception e){

e.printStackTrace();

}

}

}

web.xml:

<web-app>

<servlet>

<servlet-name>rd</servlet-name>

<servlet-class>RDServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>rd</servlet-name>

<url-pattern>/rds</url-pattern>

</servlet-mapping>

</web-app>

Output:

EXP10. Form Based Application Using Servlet

Aim: To design Form-based application which stores user information into db server using Servlet.

FBServlet.java:

import javax.servlet.http.*;

import javax.servlet.*;

import java.io.*;

import java.sql.*;

public class FBServlet extends HttpServlet{

Connection c=null;

public void init(){

System.out.println("this s from init()");

try{

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");

}catch(Exception e){

System.out.println("not able to get the connection");

}

}

public void service(HttpServletRequest request,HttpServletResponse response)throws IOException{

response.setContentType("text/html");

response.addHeader("cache-contol","no-cache");

PrintWriter out=response.getWriter();

String uname=request.getParameter("uname");

String pwd=request.getParameter("pwd");

String mno=request.getParameter("mno");

String gender=request.getParameter("gender");

String em=request.getParameter("em");

String addr=request.getParameter("addr");

String qual[]=request.getParameterValues("qual");

String hob[]=request.getParameterValues("hob");

try{

PreparedStatement ps=c.prepareStatement("insert into jan values(?,?,?,?,?,?,?,?)");

ps.setString(1,uname);

ps.setString(2,pwd);

ps.setString(3,mno);

ps.setString(4,gender);

ps.setString(5,em);

ps.setString(6,addr);

for(int i=0;i<qual.length;i++){

ps.setString(7,qual[i]);

}

for(int i=0;i<hob.length;i++){

ps.setString(8,hob[i]);

}

ps.executeUpdate();

out.println("the form values have been stored in jan table");

}catch(Exception e){

}

}

public void destroy(){

System.out.println("this s from destroy()");

try{

c.close();

}catch(Exception e){

e.printStackTrace();

}

}

}

web.xml:

<web-app>

<servlet>

<servlet-name>fb</servlet-name>

<servlet-class>FBServlet</servlet-class>

</servlet>

<servlet-mapping>

<servlet-name>fb</servlet-name>

<url-pattern>/fb</url-pattern>

</servlet-mapping>

</web-app>

login.htm:

<h2 align="center">STUDENT FORM</h2>

<form name="f" method="POST" action="/fbbasic/fb"align="center">

<pre>

UserName: <input type="text" name="uname"<br>

Password: <input type="password" name="pwd"<br>

MobileNumber: <input type="text" name="mno"<br>

Gender: Male<input type="radio" name="gender" value="male"> Female<input type="radio" name="gender" value="female"<br>

Email: <input type="text" name="em"<br>

Address: <textarea name="addr" row="10" cols="10" /</textarea<br>

Qualification:<select name="qual" multiple>

<option value="SSC">SSC</option>

<option value="+2">+2</option>

<option value="BTech">BTech</option>

<option value="MTech">MTech</option>

</select<br>

Hobbies: Reading<input type="checkbox" name="hob" value="Reading"> Cricket<input type="checkbox" name="hob" value="Cricket"> Chess<input type="checkbox" name="hob" value="Chess"> Tennicoit<input type="checkbox" name="hob" value="Tennicoit"> Movies<input type="checkbox" name="hob" value="Movies"<br>

<input type="submit" value="Submit"/>

</pre>

</form>

Output:

EXP11: Retrieve data using JSP

Aim: To retrieve data from emp table using JSP.

db.jsp:

<%@ page import="java.sql.*" %>

<%@ page errorPage="er.jsp" %>

<%

DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());

Connection c=DriverManager.getConnection("jdbc:oracle:thin:@localhost:1521:xe","system","tiger");

out.println("hi got connection<br<br>");

Statement s=c.createStatement();

ResultSet rs=s.executeQuery("select *from emp");

while(rs.next()){

out.println(rs.getString(1) +"\t"+ rs.getString("ename")+"\t"+ rs.getString("eaddress")+"<br>");

}

c.close();

%>

er.jsp:

<%@ page isErrorPage="true"%>

some problem please contact sys admin<br>

Name:Naresh

Contact:9989803310/ <br>

<%=exception%>

Output:

EXP12. Form-based application using JSP

Aim:To design form-based application which captures the data from the form and stores in db server and display the updated table.

form.jsp:

<h2 bgcolor="red" align="left">STUDENT REGISTRATION FORM</h2>

<form action="/fbrd/rd.jsp" method="POST" align="center" bgcolor="yellow">

<pre>

UserName: <input type="text" name="uname"<br>

Password: <input type="password" name="pwd"<br>

MobileNumber: <input type="text" name="mno"<br>

Gender: Male<input type="radio" name="gender" value="male"> Female<input type="radio" name="gender" value="female"<br>

Email: <input type="text" name="em"<br>

Address: <textarea name="addr" row="10" cols="10" /</textarea<br>

Qualification:<select name="qual" multiple>

<option value="SSC">SSC</option>

<option value="+2">+2</option>

<option value="BTech">BTech</option>

<option value="MTech">MTech</option>

</select<br>

Hobbies: Reading<input type="checkbox" name="hob" value="Reading"> Cricket<input type="checkbox" name="hob" value="Cricket"> Chess<input type="checkbox" name="hob" value="Chess"> Tennicoit<input type="checkbox" name="hob" value="Tennicoit"> Movies<input type="checkbox" name="hob" value="Movies"<br>

<input type="submit" value="Store & Display"/>

</pre>

</form>

rd.jsp:

<%@ page import="java.sql.*"%>

<%@ page import="java.io.*"%>

<%@ page errorPage="er.jsp"%>

<h2>the following is the updated table</h2<br>

<%!

Connection c=null;

PrintWriter out=null;

%>

<%!

public void jspInit(){

System.out.println("from init");

try{

Class.forName("oracle.jdbc.driver.OracleDriver");

c=DriverManager.getConnection("jdbc:oracle:thin:@192.168.0.249:ora249","scott","tiger");

}catch(Exception e){

out.println("not able to get the connection");

}

System.out.println("got connection");

}

%>

<%

String uname=request.getParameter("uname");

String pwd=request.getParameter("pwd");

String mno=request.getParameter("mno");

String gender=request.getParameter("gender");

String em=request.getParameter("em");

String addr=request.getParameter("addr");

String qual[]=request.getParameterValues("qual");

String hob[]=request.getParameterValues("hob");

PreparedStatement ps=c.prepareStatement("insert into jan values(?,?,?,?,?,?,?,?)");

ps.setString(1,uname);

ps.setString(2,pwd);

ps.setString(3,mno);

ps.setString(4,gender);

ps.setString(5,em);

ps.setString(6,addr);

for(int i=0;i<qual.length;i++){

ps.setString(7,qual[i]);

}

for(int i=0;i<hob.length;i++){

ps.setString(8,hob[i]);

}

ps.executeUpdate();

System.out.println("updated");

Statement s=c.createStatement();

ResultSet r=s.executeQuery("select *from jan");

while(r.next()){

out.println(r.getString(1)+"\t\t"+ r.getString(2)+"\t\t"+r.getString(3)+"\t\t"+r.getString(4)+"\t\t"+r.getString(5)+"\t\t"+r.getString(6)+"\t\t"+r.getString(7)+"\t\t"+r.getString(8)+"<br>");

}

%>

<%!

public void jspDestroy(){

System.out.println("from destroy");

try{

c.close();

}catch(Exception e){}

}

%>

er.jsp:

<%@ page isErrorPage="true"%>

<h3>some problem in code-please contact your guide</h3<br>

Name:Naresh<br>

Contact:9989803310/ <br>

<%=exception%>

OUTPUT:

For wrong enterd data: