Académique Documents
Professionnel Documents
Culture Documents
PART A:
Code:
<!DOCTYPE html>
<html>
<head>
<title>P10_3a</title>
<SCRIPT LANGUAGE="JavaScript">
function Add(form)
{
form.result.value = parseInt(form.no1.value) +
parseInt(form.no2.value);
}
function Subtract(form)
{
form.result.value = form.no1.value - form.no2.value;
}
</SCRIPT>
</head>
<body>
<!-- code for creation of form not required in asked question..! -->
<form>
<table>
<tr><td width="45" >No1</td><td><input name="no1"
size=25></td></tr>
<tr><td>No2</td><td><input name="no2" size=25></td></tr>
<tr><td>Result</td><td><input name="result" size=25></td></tr>
</table>
<input type="button" value="Add" onClick = "Add(this.form)">
<input type="button" value="Subtract" onClick = "Subtract(this.form)">
</form>
</body>
</html>
PART B:
Code:
<!DOCTYPE html>
<html>
<head>
<title>P10_3a</title>
<SCRIPT LANGUAGE="JavaScript">
function UpperCaseConvertor(form)
{
var s = form.field1.value;
form.field2.value = s.toUpperCase();
}
</SCRIPT>
</head>
<body>
<form>
<input type="text" name="field1">
Multithreaded Server:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
public final class P10_5 extends Thread {
private final Socket socket;
public P10_5(Socket socket) {
setName("P10_5");
this.socket = socket;
}
public void run() {
BufferedReader in = null;
PrintWriter out = null;
int n = 3;
String request;
try {
// Get the input and output streams
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
class dic {
String word, mean;
dic(String w, String m) {
word = w;
mean = m;
}
}
dic d[] = new dic[4];
d[0] = new dic("coincidence", "itifaq");
d[1] = new dic("thanks", "shukriya");
d[2] = new dic("problem", "masla");
d[3] = new dic("night", "raat");
while ((request = in.readLine()) != null) {
for (int i = 0; i < n; i++) {
if (request.equals(d[i].word)) {
out.println(d[i].mean);
break;
}
if (i == n - 1) {
out.println("No knowledge for " + request);
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (socket != null) {
socket.close(); // Close the socket (closing the socket also
closes the input and output streams)
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
Client:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.net.Socket;
import java.util.Scanner;
public final class P10_5Client {
private void process() {
Socket socket = null;
BufferedReader in = null;
PrintWriter out = null;
try {
/* Establish a TCP connection with the server running locally on the
port number 7777.
* You can write "localhost" instead of "127.0.0.1".
* If the server is running on a remote computer, replace "127.0.0.1"
with the server's IP address or hostname
*/
socket = new Socket("127.0.0.1", 7777);
// Get the input and output streams
in = new BufferedReader(new
InputStreamReader(socket.getInputStream()));
out = new PrintWriter(socket.getOutputStream(), true);
Scanner user = new Scanner(System.in); // Scanning for user input
String input;
while (true) {
System.out.print("Enter String: ");
input = user.next(); // Hold the input from the user
if (input.equals("end")) {
System.out.println("You ended...");
break;
} else {
out.println(input); // Send it to the server
System.out.println("Name: " + input + " Meaning: " +
in.readLine());
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
if (socket != null) {
socket.close(); // Close the socket (closing the socket also
closes the input and output streams)
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
public static void main(String[] args) {
new P10_5Client().process();
}
}
QUESTION-5
PART B:
Code:
import java.io.*;
class CopyFile {
public static void main(String args[])
throws IOException {
int i;
FileInputStream fin;
FileOutputStream fout;
try {
// open input file
try {
fin = new FileInputStream(args[0]);
} catch (FileNotFoundException e) {
System.out.println("Input File Not Found");
return;
}
// open output file
try {
fout = new FileOutputStream(args[1]);
} catch (FileNotFoundException e) {
System.out.println("Error Opening Output File");
return;
}
} catch (ArrayIndexOutOfBoundsException e) {
System.out.println("Usage: CopyFile From To");
return;
}
// Copy File
try {
do {
i = fin.read();
if (i != -1) {
fout.write(i);
}
} while (i != -1);
} catch (IOException e) {
System.out.println("File Error");
}
fin.close();
fout.close();
}
}
QUESTION-5
PART B:
Code:
interface Computer {
String getComputerModel();
String getVersion();
String getModel();
String getType();
double getPrice();
}
String cable;
boolean b;
public CD_ROM(String m, String t, double p, boolean n) {
super(m, t, p);
b = n;
}
String port;
class P10_5b {
QUESTION-6
PART B:
Code:
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.sql.*;
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
}
QUESTION-7
Code:
HTML Form:
<!DOCTYPE html>
<html>
<head>
<title>HTML Form</title>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form action = "process.jsp">
RollNo: <input name = "t1"/><br><br>
Name: <input name = "t2"/><br><br>
<input type = "submit" value = "Submit">
</form>
</body>
</html>
VIEW COOKIES:
<%--
Document : view
Created on : 16-Nov-2014, 22:17:47
Author : ali
--%>