kanishka webtech
kanishka webtech
kanishka webtech
Submitted To
Ajay Kumar Garg Engineering College, Ghaziabad
9.
Write a program to create a frame window that
contains two text box and a button named
swap. The text in the text boxes should interchange
after clicking on swap.
10.
Write an HTML program to design an entry form of
student details and apply suitable CSS. Also
apply required validations in the form fields.
11.
Writing program in XML for creation of DTD,
which specifies a set of rules. Create a style sheet in
CSS/ XSL & display the document in internet
explorer.
12.
Program to illustrate JDBC connectivity. Program for
maintaining database by sending queries.
13.
Install TOMCAT web server and APACHE. Access any
developed static web pages using these servers by putting
the web pages developed.
14.
Install a database (Mysql or Oracle). Create a table
which should contain at least the following
fields: name, password, email-id, phone number
Write a java program/servlet/JSP to connect to that
database and extract data from the tables and display
them. Insert the details of the users who register with
the web site, whenever a new user clicks the submit
button in the registration page.
15.
Write a JSP which insert the details of the 3 or 4
users who register with the web site by using
registration form. Authenticate the user when he
submits the login form using the user name and
password from the database.
Program-1
Code:
Index.html
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<div class="container">
<div><a
href="https://docs.google.com/document/d/1vEvNEM1yDAVK2vxsqZ79RkcidAeUopC2QHw
ahnxF_3o/edit?usp=sharing">CV</a></div>
<div><a href="https://www.akgec.ac.in">Institute
Website</a></div> <div><a
href="https://www.akgec.ac.in/departments/information-
technology/">Department Website</a></div>
<div><a
href="https://www.youtube.com/channel/UCxs6M6Um-IYd9eD3XUHRlkg/playlists">Tutorial
Website</a></div>
</div>
</body>
</html>
style.css
.container{
display: flex;
justify-content: space-between;
align-items: center;
color: rgb(1, 0, 0);
background-color: aqua;
font-size: 2em;
}
body{
Output:
Code:
class Box {
double length;
double width;
double height;
public Box() {}
public Box(double l, double b, double h) {
this.length = l;
this.width = b;
this.height = h;
}
Box(Box copyBox) {
this.length = copyBox.length;
this.width = copyBox.width;
this.height = copyBox.height;
}
void getVolume() {
System.out.println("Volume is:"+length*width*height);
}
void getSurfaceArea() {
System.out.println("Surface Area is:"+2 * (length * width + width * height + height * length));
}
}
public class Main {
public static void main(String[] args) {
Box box1 = new Box();
Box box2 = new Box(3.0, 4.0, 5.0);
Box box3 = new Box(box2);
box1.getSurfaceArea();
Output:
Code:
Super
class Animal {
String color = "white";
}
class Dog extends Animal {
String color = "black";
void printColor() {
System.out.println(color);
System.out.println(super.color);
}}
class TestSuper1 {
public static void main(String args[]) {
Dog d = new Dog();
d.printColor();
}}
Output:
Super
class Test {
static int x=10;
public static void main (String args[]) {
System.out.println ("x=" +Test.x);
}}
Output:
Final
Output:
This
class Volume {
int l,b,h;
Volume (int l, int b, int h)
{
this.l=l;
this.b=b;
this.h=h;
}
public static void main (String[] args)
{
Volume v1= new Volume(10,10,10);
System.out.println("Length ="+v1.l);
System.out.println("Breadth ="+v1.b);
System.out.println("Height ="+v1.h);
}
}
Output:
interface bark {
void barks();
}
interface meow {
void meoww();
}
class Dog implements bark {
public void barks() {
System.out.println("Dog can bark");
}
}
class cat implements meow {
public void meoww() {
System.out.println("cat can meow");
}
}
class Animal implements bark, meow {
public void barks() {
System.out.println("Animal can bark");
}
public void meoww() {
System.out.println("Animal can meow");
}
}
public class Main {
public static void main(String[] args) {
Dog Dog = new Dog();
Dog.barks();
cat cat = new cat();
cat.meoww();
Animal Animal = new Animal();
Animal.barks();
Animal.meoww();
}
}
Multilevel Inheritance
class Parent {
void parentMethod() {
System.out.println("This is the parent method.");
}
}
class Child extends Parent {
void childMethod() {
System.out.println("This is the child method.");
}
}
class Grandchild extends Child {
void grandchildMethod() {
System.out.println("This is the grandchild method.");
}
}
public class Main {
public static void main(String[] args) {
Grandchild obj = new Grandchild();
obj.parentMethod();
obj.childMethod();
obj.grandchildMethod();
}
}
Output:
Method overloading
Output
Output
Code:
public class ExceptionHandlingExample {
public static int divide (int dividend, int divisor) throws ArithmeticException
{ if (divisor == 0) {
throw new ArithmeticException("Division by zero is not allowed.");
}
return dividend / divisor;
}
}
Output
Program name: Write a program in java to create a package and import it.
Code:
//Package file
package mypackage;
public class Main2 {
public static void HI(){
System.out.println("Hello World");
}
}
//Importing package
import mypackage.Main2;
public class Main1 {
public static void main(String[] args) {
Main2.HI();
}
}
Output:
Program name: Write a program to create a frame window that contains two
text box and a button named swap. The text in the text boxes should interchange
after clicking on swap.
Code:
/*<applet code="MyWindow2" width="400" height="500"></applet>*/
import java.awt.*;
import java.awt.event.*;
import java.applet.*;
public class MyWindow2 extends Applet implements ActionListener{
Label l1,l2;
TextField t1,t2;
Button c;
public void init(){
l1=new Label("Text1:");
t1=new TextField();
l2=new Label("Text2:");
l1.setBounds(10,10,80,30);
t1.setBounds(90,10,80,30);
l2.setBounds(10,40,80,30);
t2=new TextField();
t2.setBounds(90,40,80,30);
c=new Button("Copy");
c.setBounds(10,80,80,30);
c.addActionListener(this);
add(l1);add(t1);add(l2);add(t2);add(c);
setLayout(null);}
public void actionPerformed(ActionEvent e){
if(e.getSource()==c){
String s=t1.getText();
String s2=t.getText();
t2.setText(s);
t1.setText(s2);
}
}}
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, chooseSystem, 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
Since servlets and JSP are not part of the Java 2 platform, standard edition, youhave to identify the
servlet classes to the compiler. The server already knows about theservlet 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 unknownclasses.
Name: JAVA_HOME
Value: install_dir/common/lib/servlet-api.jar
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 theserver's memory. This slightly
degrades performance in deployment situations, so isturned 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 beenloaded into the server's memory.
Be sure to make a backup copy of server.xm before making the above change.
The invoker servlet lets you run servlets without first making changes to yourWeb
application's deployment descriptor. Instead, you just drop your servlet into WEB-
INF/classes and use the URL http://host/servlet/ServletName . The invoker servlet
isextremely convenient when you are learning and even when you are doing your
initialdevelopment.
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 copyof 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>
Ini.java:
import javax.servlet.*;
import java.sql.*;
import java.io.*;
public class Ini extends GenericServlet
{
private String user1,pwd1,email1;
web.xml:
<web-app>
<servlet>
<servlet-name>init1</servlet-name>
<servlet-class>Ini</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>init1</servlet-name>
<url-pattern>/regis</url-pattern>
</servlet-mapping>
</web-app>
Program name: Write a JSP which insert the details of the 3 or 4 users who
register with the web site by using registration form. Authenticate the user when
he submits the login form using the user name and password from the database
Code:
Register_1.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Guru Registration Form</title>
</head>
<body>
<h1>Guru Register Form</h1>
<form action="guru_register" method="post">
<table style="with: 50%">
<tr>
<td>First Name</td>
<td><input type="text" name="first_name" /></td>
</tr>
<tr>
<td>Last Name</td>
<td><input type="text" name="last_name" /></td>
</tr>
<tr>
<td>UserName</td>
<td><input type="text" name="username" /></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" name="password" /></td>
</tr>
<tr>
<td>Address</td>
<td><input type="text" name="address" /></td>
</tr>
<tr>
<td>Contact No</td>
<td><input type="text" name="contact" /></td>
</tr></table>
<input type="submit" value="Submit" /></form>
Guru_register.java
package demotest;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class
guru_register */
public class guru_register extends HttpServlet { private
static final long serialVersionUID = 1L;
OUTPUT: