Bulletin Board Implementation Using JSP

Bulletin Board Implementation Using JSP

Start.jsp:
          <h2>Bulliten Board</h2>
<form method="post" action="bb.jsp" >
Select Group : <select name="grp">
                        <option value="grp1"/>Group-1
                         <option value="grp2"/>Group-2
                         </select><br><br>
UserName : <input type="text" name="usr" /><br><br>
Password : <input type="password" name="pass" /><br><br>
                <input type="button" value="Log In" onclick="submit()"/>
 </form>

bb.jsp:
<%@ page import="java.sql.*" %>
<%
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String grp=request.getParameter("grp");
String usr=request.getParameter("usr");
String pass=request.getParameter("pass");

try
{
Connection con =DriverManager.getConnection("jdbc:odbc:server","scott","tiger");
PreparedStatement stmt=con.prepareStatement("select * from login where usr='"+usr+"' and pass='"+pass+"' and grp='"+grp+"'");
ResultSet rs=stmt.executeQuery();
if(rs.next())
            {          %>
<form method="post" action="inbox.jsp" >
<input type="hidden" name="flag" value="<%=grp%>"/>
<input type="button" value="Go to INBOX - - >" onclick="submit()"/>
            </form>
           
<%}
else
            {
%>
Login failed<br>
<form method="post" action="start.jsp" >
            <input type="button" value="< - - Go Back" onclick="submit()"/>
            </form>
            <%
            }
             stmt.close();
}
catch(SQLException se)
{
            %>
Login failed<br>
<form method="post" action="start.jsp" >
            <input type="button" value="< - - Go Back" onclick="submit()"/>
            </form>
            <%
}         
%>

Inbox.jsp:
<%
String flag=request.getParameter("flag");
%>
<h2>INBOX</h2>
<form method="post" action="read.jsp" target="_blank">
<input type="hidden" name="flag" value="<%=flag%>"/>
<input type="button" value="Read Messages" onclick="submit()"/>
</form><br>
<form method="post" action="write.jsp" target="_blank">
<input type="hidden" name="flag" value="<%=flag%>"/>
<input type="button" value="Write Message" onclick="submit()"/>
</form><br>
<form method="post" action="start.jsp" >
<input type="hidden" name="flag" value="<%=flag%>"/>
           <input type="button" value="LogOut" onclick="submit()"/>
           </form>
Read.jsp:
<%@ page import="java.sql.*" %>
<%
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String flag=request.getParameter("flag");

try
{
Connection con =DriverManager.getConnection("jdbc:odbc:server","scott","tiger");
PreparedStatement stmt=con.prepareStatement("select * from "+flag+"");
ResultSet rs=stmt.executeQuery();
%><h3>Messages</h3><br><%
while(rs.next())
            {
     out.println(rs.getString(1)+"<br>");
                        }
            %>
<br><form method="post" action="inbox.jsp" >
<input type="hidden" name="flag" value="<%=flag%>"/>
<input type="button" value="< - - Go back to INBOX" onclick="submit()"/>
            </form>
           
<%
             stmt.close();
}
catch(SQLException se)
{
            %>
Database ERROR
            <%
}         
%>
Write.jsp:
<%
String flag=request.getParameter("flag");
%>
<form method="post" action="update.jsp" >
<input type="hidden" name="flag" value="<%=flag%>"/>
Enter message here : <input type="text" name="msg"/><br>
<input type="button" value="Write message to Database" onclick="submit()"/>
</form>

Update.jsp:
<%@ page import="java.sql.*" %>
<%
Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
String flag=request.getParameter("flag");
String msg=request.getParameter("msg");
try
{
Connection con =DriverManager.getConnection("jdbc:odbc:server","scott","tiger");
PreparedStatement stmt=con.prepareStatement("insert into "+flag+" values('"+msg+"')");
int rs=stmt.executeUpdate();
if(rs  == 1)
 out.pintln("written successfully");
%>

<br><form method="post" action="inbox.jsp" >
<input type="hidden" name="flag" value="<%=flag%>"/>
<input type="button" value="< - - Go back to INBOX" onclick="submit()"/>
            </form>
           
<%
             stmt.close();
}
catch(SQLException se)
{
            %>
Database ERROR
            <%
}         
%>






Tables required –
1.      Login (grp varchar2(20), usr varchar2(20), pass varchar2(20));
2.      grp1 (msg varchar2(50));
3.      grp2 (msg varchar2(50));