Вы находитесь на странице: 1из 22

/

***************************************************************
**/
Mini Project: Develop a mini project in jsp (messaging application) .
/
***************************************************************
**/
About Topic
Online chat may refer to any kind of communication over the Internet that
offers a real-time transmission of text messages from sender to receiver.
Chat messages are generally short in order to enable other participants to
respond quickly. Thereby, a feeling similar to a spoken conversation is
created, which distinguishes chatting from other text-based online
communication forms such as Internet forums and email. Online chat may
address point-to-point communications as well as multicast communications
from one sender to many receivers.

Introduction About Project


This project is BASED ON online messaging is to develop an online and viable
messaging
system.

Objective Of Project
The major objectives of this project are as follows: Providing an interactive user interface for messaging using the flavors of
H.T.M.L blended with JSP. To help the users whether they are teen, adult or
any new user to extract the best.
Providing Secured Environment for secured data access wherever
necessary.
Retrieval of data from database using easy buttons links and interfaces in a
very
fast and efficient manner.
Scope Of Project:-

Faster and accurate information retrieval.


Login dependent information retrieval and updating.
Correct and consistent maintenance of data and its Quick retrieval.

DATABASE DESIGN
1.User Table
Field Name
Usern
Fname
Lname
Passwd
status

Datatype
Varchar(20)
Varchar(20)
Varchar(20)
Varchar(20)
Int

Description
Username
First name
Last name
Password
Login status

Datatype
Varchar(20)
Varchar(20)
Varchar(100)

Description
Message from
Message to
Message

2.Message Table
Field Name
Msg_to
Msg_from
messg

E-R DIAGRAM

DATA FLOW DIAGRAM

CODING AND SCREENS


Home page.html
<html>
<body bgcolor="#F2F5A9">
<center><h1>login Form</h1>
<form action="login.jsp" method="post">
Username <input type="text" name="p1"><br>
Password <input type="password" name="p2"><br>
<input type="submit" value="Login">
</form>
</center>
</body>
</html>

Login.jsp
<%@ page import="java.sql.*,java.util.*" %>
<%! String username,password,name; %>
<% username=request.getParameter("p1");
password=request.getParameter("p2");
Connection con=null;
Statement stmt=null,stmt1=null;
ResultSet rs=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root
","root");
stmt=con.createStatement();
String query="select * from user where usern='"+username+"' and
passwd='"+password+"'";
rs=stmt.executeQuery(query);
if(rs.next())
{
stmt1=con.createStatement();
String query1="update user set status=1 where usern='"+username+"'";
int row=stmt1.executeUpdate(query1);
if(row !=0)
{
name=rs.getString(2);
session.setAttribute("NAME",name);
response.sendRedirect("http://localhost:8080/wa22/loginprocess.jsp");
}
}
else
{%>
<h2>
<font color="red">
"Invalid Access..."
</font>
</h2>
<a href="./home.html">Try Again</a>
<%
}
}
catch(ClassNotFoundException cnfe)

{
out.println(cnfe);
}
catch(SQLException sqle)
{
out.println(sqle);
}
finally
{
try
{
if(rs!=null)
rs.close();
if(stmt1!=null)
stmt1.close();
if(stmt!=null)
stmt.close();
if(con!=null)
con.close();
}
catch(SQLException sqle)
{
out.println(sqle);
}
}
%>

Loginprocess.jsp
<%@ page import="java.sql.*,java.util.*" %>
<%! String name; %>
<%
name=(String) session.getAttribute("NAME");
%>
<body bgcolor="#E0ECF8">
<table border="1" width="100%">
<tr>
<th><a href="http://localhost:8080/wa22/loginprocess.jsp">
Home</a></th>
<th><a href="http://localhost:8080/wa22/send.jsp">
Send Message</a></th>
<th><a href="http://localhost:8080/wa22/messagelog.jsp">
View Message</a></th>
<th>

<a href="http://localhost:8080/wa22/logout.jsp">
Logout</a></th>
</tr>
<h2>
welcome <%= name%>
</h2>
</body>

s
send.jsp

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


<%! String name; %>
</body bgcolor="#F2F5A9"><h2>Send A Message</h2><center>
<form action="msgprocess.jsp" method ="post">
<table>
<tr><td>To</td>
<%name=(String) session.getAttribute("NAME");
Connection con=null;
Statement stmt=null;
ResultSet rs=null;
ArrayList<String> al =new ArrayList<String>();
Try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root
","root");
stmt=con.createStatement();
String query="select fname from user where fname !='"+name+"' AND
status=1 ";
rs=stmt.executeQuery(query);
if(rs!= null)
{
while(rs.next())
{
al.add(rs.getString("fname"));

}
}
else
{%>
<script type="text/javascript"> alert("error"); </script>
<%
}
}
catch(ClassNotFoundException cnfe)
{out.println(cnfe);
}
catch(SQLException sqle)
{
out.println(sqle);
}
finally
{
try
{
if(stmt!=null)
stmt.close();
if(con!=null)
con.close();
}catch(SQLException sqle)
{out.println(sqle);

}
}
<td> <select name="p1">
<% Iterator itr=al.iterator();
String s;
while(itr.hasNext())
{
s=(String)itr.next();%>
<option> <%out.println(s);%></option>
<%}
%></select>

</td>

</tr>
<tr>
<td>Message</td>
<td><textarea cols="50" rows="5" name = "p2"></textarea></td>
</tr>
<tr>
<td><input type="submit" value="Submit"></td>
<td><input type="reset" value="Reset"></td>
</tr></table></form></center>
</body>

msgprocess.jsp
<body bgcolor="#F2F5A9">
<%@ page import="java.sql.*,java.util.*" %>
<%! String msgto,mssg,name; %>
<%name=(String) session.getAttribute("NAME");
msgto=request.getParameter("p1");
mssg=request.getParameter("p2");
Connection con=null;
Statement stmt=null;
try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root
","root");
stmt=con.createStatement();
String query=" insert into message
values('"+name+"','"+msgto+"','"+mssg+"')";
int row=stmt.executeUpdate(query);
if(row !=0)
{
response.sendRedirect("http://localhost:8080/wa22/back.jsp");
}
else
{%>
<script type="text/javascript"> alert("error"); </script>
<%
}
}
catch(ClassNotFoundException cnfe)
{
out.println(cnfe);
}
catch(SQLException sqle)
{
out.println(sqle);
}
finally
{
try
{
if(stmt!=null)
stmt.close();
if(con!=null)

con.close();
}
catch(SQLException sqle)
{
out.println(sqle);
}
}
%></body>

back.jsp
<body bgcolor="#F2F5A9">
<%! String name; %><%
name=(String) session.getAttribute("NAME");
%>
<h2 font-color="red">
successfull </h2>
<table border="1" width="100%">
<tr>
<th><a href="http://localhost:8080/wa22/loginprocess.jsp">
Home</a></th>
<th><a href="http://localhost:8080/wa22/send.jsp">
Send Message</a></th>
</tr>

</table>
</body>

messagelog.jsp
<H1><b><u>Message Log</u></b></h1>
<body bgcolor="#A9F5F2">
<%@ page import="java.sql.*"%>
<%!String from_name,to_name,message,name;%>
<%Connection con = null;
ResultSet rs = null;
ResultSet rs1 = null;
Statement stmt = null;
name = session.getAttribute("NAME").toString();
try
{

Class.forName("com.mysql.jdbc.Driver");
con =
DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","roo
t");
stmt = con.createStatement();
String query = "SELECT msg_to, messg FROM message WHERE
msg_from='"+name+"'";
rs = stmt.executeQuery(query);
%>
<h4><b><u>Sent Messages</u></b></h4>
<table border ="2">
<tr>
<th>To</th>
<th>Message</th>
</tr>
<%
if(rs!=null)
{
while(rs.next())
{
to_name = rs.getString(1);
message = rs.getString(2);%>
<tr>
<td><%out.println(to_name);%></td>
<td><%out.println(message);%></td>
</tr>

<%}%>
</table>
<%
String query1 = "SELECT msg_from, messg FROM message WHERE
msg_to='"+name+"'";
rs1 = stmt.executeQuery(query1);
}else{
%><h4> The List is empty</h4><%}
%>
<h4><b><u>Recieved Messages</u></b></h4>
<table border ="2">
<tr>
<th>From</th>
<th>Message</th>
</tr>
<%
if(rs1!=null)
{
while(rs1.next())
{
from_name = rs1.getString(1);
message = rs1.getString(2);%>
<tr>
<td><%out.println(from_name);%></td>
<td><%out.println(message);%></td>

</tr>
<%}%>
</table>
<%
}
else
{
%><h4> The List is empty</h4><%
}
}
catch(ClassNotFoundException cnfe)
{
out.println(cnfe);
}
catch(SQLException sqle)
{
out.println(sqle);
}
catch(Exception e)
{
out.println(e);
}
finally
{
try

if(con!=null)
con.close();
if(stmt!=null)
stmt.close();
}
catch(SQLException sqle)
{
out.println(sqle);
}
catch(Exception e)
{
out.println(e);
}
}%></body>

logout.jsp

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


<%! String name; %>
<% HttpSession ses=request.getSession();
name=(String) session.getAttribute("NAME");
Connection con=null;
Statement stmt=null;

try
{
Class.forName("com.mysql.jdbc.Driver");
con=DriverManager.getConnection("jdbc:mysql://localhost:3306/demo","root","root"
);
stmt=con.createStatement();
if (name != null)
{
String query="update user set status=0 where fname='"+name+"'";
stmt.executeUpdate(query);
}
if(ses != null)
{
ses.invalidate();
response.sendRedirect("http://localhost:8080/wa22");
}
}
catch(ClassNotFoundException cnfe)
{
out.println(cnfe);
}
catch(SQLException sqle)
{
out.println(sqle);
}
finally
{

try
{
if(stmt!=null)
stmt.close();
if(con!=null)
con.close();
}
catch(SQLException sqle)
{
out.println(sqle);
}
}
%>

Вам также может понравиться