University of Mumbai: Certificate
University of Mumbai: Certificate
SEMESTER-V
University of Mumbai
Certificate
Examiner
Roll No:
M.C.A. SEMESTER-V
University of Mumbai
INDEX
Practical No. 1
Roll No:
M.C.A. SEMESTER-V
Code :Disp.java
import java.io.*;
import javax.servlet.*;
Index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<form name="test1" action="Disp" method="POST">
Enter number:- <input type="text" name="n1" value="" size="10" />
<br><input type="submit" value="show" name="show" />
</form>
</body>
</html>
Output:
Roll No:
M.C.A. SEMESTER-V
Practical No. 2
Code : Authenticate.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class authenticate extends HttpServlet
{
protected void doPost(HttpServletRequest req, HttpServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/html;charset=UTF-8");
PrintWriter out = res.getWriter();
String user=req.getParameter("username");
String passwd=req.getParameter("pwd");
validate(user, passwd, out);
}
protected void validate(String user, String passwd, PrintWriter out)
{
if(user.length()==0 || passwd.length()==0 )
out.println("<h1>Fill both the fields</h1>");
else if(user.equalsIgnoreCase("admin") && passwd.equals("admin"))
out.println("<h1>Welcome "+user+", You are an authorized user</h1>");
else
out.println("<h1>You are not an authorized user</h1>");
}
}
Auth.html
Roll No:
M.C.A. SEMESTER-V
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form action="http://localhost:8080/WebApplication/authenticate" method="post">
UserName:
<input type="text" name="username"><br>
Password:
<input type="password" name="pwd" value=""><br><p></p>
<input type="submit" value="Login" name="login" />
</form>
</body>
</html>
Output:
Practical No. 3
Code : httpsession.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class httpsession extends HttpServlet
{
public void doGet(HttpServletRequest req, HttpServletResponse res) throws ServletException,
IOException
{
res.setContentType("text/html");
Roll No:
M.C.A. SEMESTER-V
Output:
Practical No. 4
Code:
import java.io.*;
Roll No:
M.C.A. SEMESTER-V
import java.util.*;
import javax.servlet.*;
public class servcontext extends GenericServlet
{
public void service(ServletRequest req, ServletResponse res)
throws ServletException, IOException
{
res.setContentType("text/plain");
PrintWriter out = res.getWriter();
Roll No:
M.C.A. SEMESTER-V
Practical No: 5
<Html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<h1>Registration Form</h1>
<form action="http://localhost:8080/db/DatabaseServlet" method="POST">
<table border="1">
<tr><td>Name</td>
<td><input type="text" name="name" value="" /></td>
</tr>
<tr><td>Roll No.</td>
<td><input type="text" name="rollno" value="" /></td>
Roll No:
M.C.A. SEMESTER-V
</tr>
<tr><td>Email</td>
<td><input type="text" name="email" value="" /></td>
</tr>
<tr><td>Address</td>
<td><textarea name="address" rows="4" cols="20"></textarea></td>
</tr>
<tr><td><input type="submit" value="Submit" /></td>
<td><input type="reset" value="Reset" /></td>
</tr>
</table>
</form>
</body>
</html>
Code : DatabaseServlet.java
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.*;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
String name,roll,adr,email;
name =request.getParameter("name");
roll=request.getParameter("rollno");
Roll No:
M.C.A. SEMESTER-V
email=request.getParameter("email");
adr=request.getParameter("address");
}
catch(ClassNotFoundException c1)
{
out.println("ClassNotFoundException");
}
catch(SQLException s1)
{
out.println("SQLException");
}
finally
{
out.close();
}
}
Roll No:
M.C.A. SEMESTER-V
Output:
Practical No. 6
Code : oexam.java
import java.io.IOException;
Roll No:
M.C.A. SEMESTER-V
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.*;
}
catch(Exception e)
{
out.print("Caught" + e);
}
Roll No:
M.C.A. SEMESTER-V
finally
{
out.close();
}
}
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
processRequest(request, response);
}
public String getServletInfo() {
return "Short description";
}
}
Index.html
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
Roll No:
M.C.A. SEMESTER-V
</head>
<body>
<form action="http://localhost:8080/bo/oexam" >
</body>
</html>
Output:
Roll No:
M.C.A. SEMESTER-V
Practical No. 7
Code: Form.jsp
Output.jsp
Roll No:
M.C.A. SEMESTER-V
</table>
</body>
</html>
Output:
Practical No. 8
Code:
Roll No:
M.C.A. SEMESTER-V
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!private int idNum=0;%>
<%synchronized(this)
{
String userId="userId "+idNum;
out.println("Your ID is "+userId+".");
idNum=idNum+1;
}
%>
</body>
</html>
Output:
Practical No. 9
Roll No:
M.C.A. SEMESTER-V
Code :
login.html
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
</head>
<body>
<form name="form" action="shopping.jsp" method="POST">
Uesr Name : <input type="text" name="uname" value="" size="10" /><br/>
Password : <input type="password" name="pwd" value="" size="10" /><br/>
<input type="submit" value="Login" name="login" />
</form>
</body>
</html>
Roll No:
M.C.A. SEMESTER-V
shopping.jsp
<%@page import="java.io.*,java.util.*,java.sql.*" contentType="text/html" pageEncoding="UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Cookie cookies[] = request.getCookies ();
if (cookies != null)
{
for (int j = 0; j < cookies.length; j++)
{ cookies[j].setValue(""); }
}
%>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:logindb");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from login");
while(rs.next())
{
if((request.getParameter("uname").equalsIgnoreCase(rs.getString(1)) &&
(request.getParameter("pwd").equals(rs.getString(2)))))
{
session = request.getSession(true);
%>
<jsp:forward page="products.jsp"/>
<%
break;
}
else
{ out.println("Invalid Login"); }
}
st.close();
con.close();
%>
</body>
</html>
Roll No:
M.C.A. SEMESTER-V
products.jsp
<%@page import="java.io.*,java.util.*,java.sql.*" contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%!
Cookie cookies[];
Cookie myCookie;
int a;
String str;
%>
a = 1;
while(rs.next())
{
cookies = request.getCookies ();
myCookie = null;
if (cookies != null)
{
for (int i = 0; i < cookies.length; i++)
{
Roll No:
M.C.A. SEMESTER-V
Roll No:
M.C.A. SEMESTER-V
receipt.jsp
<%@page import="java.io.*,java.util.*,java.sql.*" contentType="text/html" pageEncoding="UTF-8"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>JSP Page</title>
</head>
<body>
<%
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection con = DriverManager.getConnection("jdbc:odbc:logindb");
Statement st = con.createStatement();
ResultSet rs = st.executeQuery("select * from Products");
int i = 1,total=0;
String str;
while(rs.next())
{
response.addCookie(new Cookie(Integer.toString(i),request.getParameter(Integer.toString(i))));
if(!(request.getParameter(Integer.toString(i)).equals("")))
{
str = request.getParameter(Integer.toString(i));
total = total + (rs.getInt(3)*Integer.parseInt(str));
}
i++;
}
st.close();
con.close();
%>
<h1>Your bill is = <%=total%></h1>
<a href="products.jsp">Continue Shopping</a><br/><br/>
<form method="post" action="login.html">
<input type="submit" value="Logout"action="<%session.invalidate();%>;"/>
</form>
</body>
</html>
Roll No:
M.C.A. SEMESTER-V
Practical No. 10
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace cal
{
class oper
{
int n1, n2;
public void getdata()
{
Console.Write("\nEnter 1st no:");
n1 = Convert.ToInt32(Console.ReadLine());
Console.Write("Enter 2nd no:");
n2 = Convert.ToInt32(Console.ReadLine());
}
public void add()
{
Console.WriteLine("\n{0} + {1}:{2}",n1,n2, (n1 + n2));
}
public void sub()
Roll No:
M.C.A. SEMESTER-V
{
Console.WriteLine("\n{0}-{1}:{2}", n1,n2,(n1-n2));
}
public void mul()
{
Console.WriteLine("\n{0}*{1}:{2}",n1,n2,(n1 * n2));
}
public void div()
{
Console.WriteLine("\n{0}/{1}:{2}",n1,n2,(n1 / n2));
}
}
class calculator
{
static void Main(string[] args)
{
int ch;
oper o = new oper();
Console.WriteLine("1:+");
Console.WriteLine("2:-");
Console.WriteLine("3:*");
Console.WriteLine("4:/");
do
{
Console.Write("\nEnter ur option:");
ch = Convert.ToInt32(Console.ReadLine());
o.getdata();
switch (ch)
{
case 1: o.add();
break;
case 2: o.sub();
break;
case 3: o.mul();
break;
case 4: o.div();
break;
Roll No:
M.C.A. SEMESTER-V
Console.ReadLine();
} while (ch < 5);
}
}
Output:
1:+
2:-
3:*
4:/
Enter ur option : 1
20 + 50:70
Enter ur option : 2
55-78:-23
Enter ur option :3
Roll No:
M.C.A. SEMESTER-V
50*14:700
Enter ur option : 4
250/100 : 2
Practical No. 11
Code :
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace gen
{
class Program
{
static void Main(string[] args)
{
MyList<int> lst = new MyList<int>();
MyItem<int> i0 = new MyItem<int>(1);
MyItem<int> i1 = new MyItem<int>(2);
MyItem<int> i2 = new MyItem<int>(3);
MyItem<int> i3 = new MyItem<int>(4);
MyItem<int> i4 = new MyItem<int>(5);
MyItem<int> i5 = new MyItem<int>(6);
lst.append(i0);
lst.append(i1);
lst.append(i2);
lst.append(i3);
lst.append(i4);
lst.append(i5);
lst.display();
Console.WriteLine("Total count in list : " + lst.getCount());
Roll No:
M.C.A. SEMESTER-V
lst.removeAt(3);
Console.WriteLine("\nNew Count after deletion : " +
lst.getCount());
lst.display();
Console.ReadKey();
}
}
class MyItem<T>
{
private T data;
private MyItem<T> next;
public MyItem(T t)
{
data = t;
next = null;
}
public void setData(T t)
{
data = t;
}
public void setNext(MyItem<T> n)
{
next = n;
}
public T getData()
{
return (data);
}
public MyItem<T> getNext()
{
return (next);
}
}
class MyList<T>
{
private MyItem<T> head;
public MyList()
{
head = null;
}
public void append(MyItem<T> item)
{
if (head == null)
{
head = item;
}
else
{
MyItem<T> ptr = head;
while (ptr.getNext() != null)
ptr = ptr.getNext();
ptr.setNext(item);
}
}
public int getCount()
Roll No:
M.C.A. SEMESTER-V
{
if (head == null)
return (0);
int cnt = 0;
MyItem<T> ptr = head;
while (ptr.getNext() != null)
{
ptr = ptr.getNext();
cnt++;
}
return (++cnt);
}
Output:
Roll No:
M.C.A. SEMESTER-V
Practical No. 12
Code:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
namespace filhandling
{
class operation
{
long phno;
string name, add, str;
public void readfile()
{
FileStream fs = new FileStream("c:\\Milind\\abc.txt",
FileMode.Open, FileAccess.Read);
StreamReader sr = new StreamReader(fs);
str = sr.ReadLine();
Console.WriteLine(str);
Console.WriteLine("\nRecords in the file:");
while (str != null)
{
Console.WriteLine(str);
str = sr.ReadLine();
Roll No:
M.C.A. SEMESTER-V
sr.Close();
fs.Close();
}
public void writefile()
{
}
}
class Program
{
static void Main(string[] args)
{
int ch;
char ans;
operation o = new operation();
Console.WriteLine("1:Append record.");
Console.WriteLine("2:Read records.");
do
{
Console.Write("\nEnter your choice:");
ch = Convert.ToInt32(Console.ReadLine());
switch (ch)
{
case 1: o.writefile();
break;
case 2: o.readfile();
break;
}
Console.Write("\nDo you want to continue:");
Roll No:
M.C.A. SEMESTER-V
ans = Convert.ToChar(Console.ReadLine());
Output:
1:Append record.
2:Read records.
Roll No:
M.C.A. SEMESTER-V
Practical No: 13
Code:
Output:
Practical No: 14
Code:
Login.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
Roll No:
M.C.A. SEMESTER-V
namespace OnlineLibrary
{
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
Bookentry.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
namespace OnlineLibrary
{
public partial class bookentry : System.Web.UI.Page
{
int isbn;
bool isnum = int.TryParse(txtIsbn.Text, out isbn);
Roll No:
M.C.A. SEMESTER-V
int ed;
isnum = int.TryParse(txtEdition.Text, out ed);
int c;
isnum = int.TryParse(txtCost.Text, out c);
int co;
isnum = int.TryParse(txtCopies.Text, out co);
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message +
"')</script>");
}
Roll No:
M.C.A. SEMESTER-V
}
}
Issue.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
namespace OnlineLibrary
{
public partial class issue : System.Web.UI.Page
{
int id;
isnum = int.TryParse(txtId.Text, out id);
try
{
//Response.Write("<script>alert('" + dbReader.Read()
+"')</script>");
Roll No:
M.C.A. SEMESTER-V
//return;
if (!dbReader.Read())
{
Response.Write("<script>alert('Book no doesnt
exist.')</script>");
return;
}
dbReader.Close();
cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM student where sid=" + id;
dbReader = cmd.ExecuteReader();
if (!dbReader.Read())
{
Response.Write("<script>alert('Student id doesnt
exist.')</script>");
return;
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message +
"')</script>");
}
Roll No:
M.C.A. SEMESTER-V
Option.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
namespace OnlineLibrary
{
public partial class option : System.Web.UI.Page
{
protected void btnSubmit_Click(object sender, EventArgs e)
{
if (rbStudent.Checked)
{
Response.Redirect("studententry.aspx");
}
else if (rdBook.Checked)
{
Response.Redirect("bookentry.aspx");
}
else if (rbIssue.Checked)
{
Response.Redirect("issue.aspx");
}
else
{
Response.Redirect("return.aspx");
}
}
}
}
Return.aspx.cs
Roll No:
M.C.A. SEMESTER-V
using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Data.OleDb;
namespace OnlineLibrary
{
public partial class _return : System.Web.UI.Page
{
try
{
int no;
bool isnum = int.TryParse(txtBook.Text, out no);
int id;
isnum = int.TryParse(txtId.Text, out id);
//Response.Write("<script>alert('" + dbReader.Read()
+"')</script>");
//return;
if (!dbReader.Read())
{
Response.Write("<script>alert('Book no doesnt
exist.')</script>");
Roll No:
M.C.A. SEMESTER-V
return;
}
dbReader.Close();
cmd = conn.CreateCommand();
cmd.CommandText = "SELECT * FROM student where sid=" + id;
dbReader = cmd.ExecuteReader();
if (!dbReader.Read())
{
Response.Write("<script>alert('Student id doesnt
exist.')</script>");
return;
}
}
catch (Exception ex)
{
Response.Write("<script>alert('" + ex.Message +
"')</script>");
}
}
public void reset()
{
txtBook.Text = "";
txtId.Text = "";
}
Roll No:
M.C.A. SEMESTER-V
}
}
Output:
Roll No:
M.C.A. SEMESTER-V
Roll No:
M.C.A. SEMESTER-V
Roll No: