Top Banner
PROJECT REPORT clickTObuy.com (Classified website) Done under: NIIT SCO-36, Sector 12 Faridabad
48

Mini Project_ website JSP

Mar 26, 2015

Download

Documents

Pawan Kumar
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Mini Project_ website JSP

PROJECT REPORT

clickTObuy.com(Classified website)

Done under:NIIT

SCO-36, Sector 12Faridabad

Submitted By:Pawan Kumar

Page 2: Mini Project_ website JSP

271104CSE- CB2

Index1. Certificate2. Acknowledgement3. Abstract4. Objective5. Technical Details

a. Hardware requirements and Software Requirementsb. Basic Architecturec. Tools Used

6. ER Diagram7. Tables Used8. Coding9. Screenshots10. Why a Classifieds site

Page 3: Mini Project_ website JSP

Acknowledgement

The special thank goes to my helpful faculty member, Ms. Lata Verma. The supervision and support that he gave truly help the progression and smoothness of the program. The co-operation is much indeed appreciated.

A big contribution and hard worked from him during this six week is very great indeed. Project during the program would be nothing without his enthusiasm and imagination. Not forget, great appreciation go to the rest of staff that help me from time to time during the project.

Pawan Kumar 271104CSE - 7CB2

Page 4: Mini Project_ website JSP

Abstract

The site aims the local community could come together, meet, trade and help each other in many ways. Community members can come here to find an apartment to live in, sell their old car, bike ,music system, laptop or furniture, promote their small business or get a break as a model or actor, join a salsa class, get an audience for a local event, buy any item that they might want or have to offer and make new friends while doing all of the above.

Page 5: Mini Project_ website JSP

ObjectiveBased on the requirements given in the problem statement above

Conceptualize the layout of the system and develop the user interface for the web pages

Create a Solution Architecture identifying the key components of your solution.

Identify the significant entities and carry out detailed design of Classes, database objects and other solution components based on which your programming would be based.

Carry out coding and testing as necessary to produce a program which can be compiled and run without any bugs.

 

Page 6: Mini Project_ website JSP

Technical details

Hardware and Software Requirement

OS independent - hence any OS can be used The Java SE Development Kit (JDK 1.5) which includes the Java Runtime

Environment (JRE) MS ACCESS. Hardware Required- Pentium 166MHz or faster processor with a minimum of

125MB free disk space and a minimum of 32MB of RAM. Java Compatible Web Server

Basic architecture

The system works on client server model

Page 7: Mini Project_ website JSP

Tools used

NetBeans : it’s an IDE for java programming created by Oracle .

NetBeans refers to both a platform framework for Java desktop applications, and an integrated development environment (IDE) for developing with Java, JavaScript, PHP, Python, Ruby, Groovy, C, C++ and others.

The NetBeans IDE is written in Java and runs everywhere where a JVM is installed, including Windows, Mac OS, Linux, and Solaris. A JDK is required for Java development functionality, but is not required for development in other programming languages.

The NetBeans Platform allows applications to be developed from a set of modular software components called modules.

Multiple thread of Execution

HTTP Request

HTTP Response

Page 8: Mini Project_ website JSP

Ms Access:

Microsoft Access, is a relational database management system from Microsoft that combines the relational Microsoft Jet Database Engine with a graphical user interface and software-development tools.

Ms Access is well suited for small applications like in our case of website.

Page 9: Mini Project_ website JSP

Glass Fish Server 3

GlassFish is an open source application server project led by Sun Microsystems for the Java EE platform. The proprietary version is called Oracle GlassFish Enterprise Server. GlassFish is based on source code released by Sun and Oracle Corporation's TopLink persistence system. It uses a derivative of Apache Tomcat as the servlet container for serving Web content.

Page 10: Mini Project_ website JSP

ER Diagram

Page 11: Mini Project_ website JSP

Tables Used

Ads

This table stores a database about ads It also has a field member_id which allow to trace which user had

entered the ad

Page 12: Mini Project_ website JSP

Categories

This table contains the category of ads with a hierarchy number

Page 13: Mini Project_ website JSP

Members

This Table contains the database about Members registered on site

Page 14: Mini Project_ website JSP

CodingDefault.jsp

<%-- Document : Default Created on : 22 June, 2010, 10:29:12 AM Author : Pawan--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"><%@ include file="Common.jsp" %><%!static final String sFileName = "Default.jsp";

static final String PageBODY = "bgcolor=\"#FFFFFF\"";static final String FormTABLE = "";static final String FormHeaderTD = "bgcolor=\"#808080\" align=\"center\"";static final String FormHeaderFONT = "face=\"arial\" color=\"#FFFFFF\" style=\"font:bold\"";static final String FieldCaptionTD = "bgcolor=\"#CCCCCC\"";static final String FieldCaptionFONT = "face=\"arial\" size=\"2\" style=\"font:bold\"";static final String DataTD = "bgcolor=\"#EEEEEE\"";static final String DataFONT = "face=\"arial\" size=\"2\"";static final String ColumnFONT = "face=\"arial\" size=\"2\" style=\"font:bold\"";static final String ColumnTD = "bgcolor=\"#CCCCCC\"";%><%

boolean bDebug = false;

String sAction = getParam( request, "FormAction");String sForm = getParam( request, "FormName");String sTreeErr = "";String sSearchErr = "";

Page 15: Mini Project_ website JSP

String sLoginErr = "";String sMenuErr = "";

java.sql.Connection conn = null;java.sql.Statement stat = null;String sErr = loadDriver();conn = cn();stat = conn.createStatement();if ( ! sErr.equals("") ) { try { out.println(sErr); } catch (Exception e) {}}if ( sForm.equals("Tree") ) { sTreeErr = TreeAction(request, response, session, out, sAction, sForm, conn, stat); if ( "sendRedirect".equals(sTreeErr)) return;}if ( sForm.equals("Login") ) { sLoginErr = LoginAction(request, response, session, out, sAction, sForm, conn, stat); if ( "sendRedirect".equals(sLoginErr)) return;}

%><html><head><title>Click to buy</title></head><body bgcolor="#FFFFFF"><jsp:include page="Header.jsp" flush="true"/> <table> <tr>

<td valign="top"><% Search_Show(request, response, session, out, sSearchErr, sForm, sAction, conn, stat); %>

</td> <td valign="top"><% Menu_Show(request, response, session, out, sMenuErr, sForm, sAction, conn, stat); %>

</td> </tr>

Page 16: Mini Project_ website JSP

</table> <table> <tr> <td valign="top"><% Tree_Show(request, response, session, out, sTreeErr, sForm, sAction, conn, stat); %>

</td> </tr> </table> <table> <tr> <td valign="top"><% Login_Show(request, response, session, out, sLoginErr, sForm, sAction, conn, stat); %>

</td> </tr> </table>

<jsp:include page="Footer.jsp" flush="true"/></body></html><%%><%if ( stat != null ) stat.close();if ( conn != null ) conn.close();%><%!

String sActionFileName = "Default.jsp";

String TreeAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sAction, String sForm, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException { try {

String sCatId = getParam( request, "category_id"); String sOp = "="; if ( isEmpty(sCatId) || ! isNumber(sCatId) ) { sCatId = "null"; sOp = " is "; }

Page 17: Mini Project_ website JSP

long lNRec = dCountRec( stat, "categories", "par_category_id"+ sOp + sCatId); if ( lNRec == 0 ) { try { if ( stat != null ) stat.close(); if ( conn != null ) conn.close(); } catch ( java.sql.SQLException ignore ) {} response.sendRedirect("AdsGrid.jsp?category_id=" + sCatId); return "sendRedirect";

} } catch (Exception e) { out.println(e.toString()); }; return (""); }

void Tree_Show(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sTreeErr, String sForm, String sAction, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException { try {

String transitParams = ""; String sQueryString = ""; String sPage = ""; String sSQL = "select category_id, name, par_category_id from categories"; String sCatID = getParam( request, "category_id"); String sWhere = ""; java.sql.ResultSet rs = null; String sCatPath = ""; String sCatList = ""; String sParCatID = ""; String sCatName = ""; String sPath = ""; String stCatID = ""; String stParCatID = ""; String stCatName = "";

out.println(" <table >");

out.println(" <tr>\n <td bgcolor=\"#CCCCCC\"><nobr><font face=\"arial\" size=\"2\" style=\"font:bold\"><a

Page 18: Mini Project_ website JSP

href=\""+sActionFileName+"?FormName=Tree\"><font face=\"arial\" size=\"2\" style=\"font:bold\">Top</font></a>");

if (sCatID == null || sCatID.compareTo("") == 0 || ! isNumber(sCatID)) { // Root category sWhere = " where par_category_id is Null"; } else {

// Subcategory sWhere = " where category_id=" + sCatID; rs = openrs ( stat, sSQL + sWhere); if ( rs.next()) { java.util.Hashtable rsHash = new java.util.Hashtable(); String[] aFields = getFieldsName( rs ); getRecordToHash( rs, rsHash, aFields );

sCatPath = ""; sCatList = ""; sParCatID = toHTML((String) rsHash.get("par_category_id")); sCatName = toHTML((String) rsHash.get("name")); } rs.close(); sPath = " > "+sCatName+"</font></nobr></td>\n </tr>";

// Build Path stParCatID = sParCatID; while ( stParCatID.compareTo("") != 0 ) { rs = openrs ( stat, sSQL + " where category_id=" + stParCatID); java.util.Hashtable rsHash = new java.util.Hashtable(); String[] aFields = getFieldsName( rs ); if ( rs.next() ) { getRecordToHash( rs, rsHash, aFields ); stCatID = toHTML((String) rsHash.get("category_id")); stParCatID = toHTML((String) rsHash.get("par_category_id")); stCatName = toHTML((String) rsHash.get("name")); sPath = "> <a href=\""+sActionFileName+"?FormName=Tree&category_id="+stCatID+"\"><font face=\"arial\" size=\"2\" style=\"font:bold\">"+stCatName+"</font></a>" + sPath; } rs.close(); } out.println(sPath); sWhere = " where par_category_id=" + sCatID;

Page 19: Mini Project_ website JSP

}

// Categories list rs = openrs ( stat, sSQL + sWhere); if (rs != null) { java.util.Hashtable rsHash = new java.util.Hashtable(); String[] aFields = getFieldsName( rs ); while ( rs.next() ) { // Print subcategories getRecordToHash( rs, rsHash, aFields ); stCatID = toHTML((String) rsHash.get("category_id")); stParCatID = toHTML((String) rsHash.get("par_category_id")); stCatName = toHTML((String) rsHash.get("name"));

out.println(" <tr>\n <td bgcolor=\"#EEEEEE\"><a href=\""+sActionFileName+"?FormName=Tree&category_id="+stCatID+"\"><font face=\"arial\" size=\"2\">"+stCatName+"</font></a></td>\n </tr>"); } } rs.close();

out.println(" </table>"); } catch (Exception e) { out.println(e.toString()); }; }

void Search_Show (javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sSearchErr, String sForm, String sAction, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException { try {

String fldname=""; String sSQL=""; String transitParams = ""; String sQueryString = ""; String sPage = ""; out.println(" <table >");

Page 20: Mini Project_ website JSP

out.println(" <tr>\n <td bgcolor=\"#808080\" align=\"center\" colspan=\"3\"><a name=\"Search\"><font face=\"arial\" color=\"#FFFFFF\" style=\"font:bold\">Search</font></a></td>\n </tr>"); out.println(" <form method=\"get\" action=\"AdsGrid.jsp\" name=\"Search\">\n <tr>"); // Set variables with search parameters fldname = getParam( request, "name"); // Show fields out.println(" <td bgcolor=\"#CCCCCC\"><font face=\"arial\" size=\"2\" style=\"font:bold\">Name</font></td>"); out.print(" <td bgcolor=\"#EEEEEE\">"); out.print("<input type=\"text\" name=\"name\" maxlength=\"20\" value=\""+toHTML(fldname)+"\" size=\"20\">"); out.println("</td>"); out.println(" <td ><input type=\"submit\" value=\"Search\"/></td>"); out.println(" </tr>\n </form>\n </table>"); out.println(""); } catch (Exception e) { out.println(e.toString()); } } String LoginAction(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sAction, String sForm, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException { String sLoginErr = ""; try { final int iloginAction = 1; final int ilogoutAction = 2; String transitParams = ""; String sQueryString = ""; String sPage = ""; String sSQL=""; int iAction = 0; if ( sAction.equals("login") ) iAction = iloginAction; if ( sAction.equals("logout") ) iAction = ilogoutAction; switch (iAction) { case iloginAction: { // Login action String sLogin = getParam( request, "Login"); String sPassword = getParam( request, "Password"); java.sql.ResultSet rs = null; rs = openrs( stat, "select member_id, member_level from members where member_login =" + toSQL(sLogin, adText) + " and member_password=" + toSQL(sPassword, adText));

Page 21: Mini Project_ website JSP

if ( rs.next() ) { // Login and password passed session.setAttribute("UserID", rs.getString(1));

session.setAttribute("UserRights", rs.getString(2)); sQueryString = getParam( request, "querystring"); sPage = getParam( request, "ret_page"); if ( ! sPage.equals(request.getRequestURI() ) && ! "".equals(sPage)) { try { if ( stat != null ) stat.close(); if ( conn != null ) conn.close(); } catch ( java.sql.SQLException ignore ) {} response.sendRedirect(sPage + "?" + sQueryString); return "sendRedirect"; }

} else sLoginErr = "Login or Password is incorrect."; rs.close();

break; } case ilogoutAction: { // Logout action

session.setAttribute("UserID", ""); session.setAttribute("UserRights", "");

break; } } } catch (Exception e) { out.println(e.toString()); } return (sLoginErr); }

void Login_Show(javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sLoginErr, String sForm, String sAction, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException { try {

Page 22: Mini Project_ website JSP

String sSQL=""; String transitParams = ""; String sQueryString = getParam( request, "querystring"); String sPage = getParam( request, "ret_page");

out.println(" <table border=1>"); out.println(" <tr>\n <td bgcolor=\"#808080\" align=\"center\" colspan=\"2\"><font face=\"arial\" color=\"#FFFFFF\" style=\"font:bold\">Login</font></td>\n </tr>");

if ( sLoginErr.compareTo("") != 0 ) { out.println(" <tr>\n <td colspan=\"2\" bgcolor=\"#EEEEEE\"><font face=\"arial\" size=\"2\">"+sLoginErr+"</font></td>\n </tr>"); } sLoginErr=""; out.println(" <form action=\""+sFileName+"\" method=\"POST\">"); out.println(" <input type=\"hidden\" name=\"FormName\" value=\"Login\">"); if ( session.getAttribute("UserID") == null || ((String) session.getAttribute("UserID")).compareTo("") == 0 ) { // User did not login out.println(" <tr>\n <td bgcolor=\"#CCCCCC\"><font face=\"arial\" size=\"2\" style=\"font:bold\">Login</font></td><td bgcolor=\"#EEEEEE\"><input type=\"text\" name=\"Login\" maxlength=\"50\" value=\""+toHTML(getParam( request, "Login"))+"\"></td>\n </tr>"); out.println(" <tr>\n <td bgcolor=\"#CCCCCC\"><font face=\"arial\" size=\"2\" style=\"font:bold\">Password</font></td><td bgcolor=\"#EEEEEE\"><input type=\"password\" name=\"Password\" maxlength=\"50\"></td>\n </tr>"); out.print(" <tr>\n <td colspan=\"2\"><input type=\"hidden\" name=\"FormAction\" value=\"login\"><input type=\"submit\" value=\"Login\">"); out.println("<input type=\"hidden\" name=\"ret_page\" value=\""+sPage+"\"><input type=\"hidden\" name=\"querystring\" value=\""+sQueryString+"\"></td>\n </form>\n </tr>"); } else { // User logged in String sUserID = dLookUp( stat, "members", "member_login", "member_id =" + session.getAttribute("UserID")); out.print(" <tr><td bgcolor=\"#EEEEEE\"><font face=\"arial\" size=\"2\">"+sUserID+"&nbsp;&nbsp;"+"</font><input type=\"hidden\" name=\"FormAction\" value=\"logout\"/><input type=\"submit\" value=\"Logout\"/>");

Page 23: Mini Project_ website JSP

out.print("<input type=\"hidden\" name=\"ret_page\" value=\""+sPage+"\"><input type=\"hidden\" name=\"querystring\" value=\""+sQueryString+"\">"); out.println("</td>\n </form>\n </tr>"); } out.println(" </table>"); } catch (Exception e) { out.println(e.toString()); } } void Menu_Show (javax.servlet.http.HttpServletRequest request, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpSession session, javax.servlet.jsp.JspWriter out, String sMenuErr, String sForm, String sAction, java.sql.Connection conn, java.sql.Statement stat) throws java.io.IOException { try {

out.println(" <table >"); out.print(" <tr>"); // Set URLs String fldField1 = "AdvSearch.jsp"; // Show fields out.print("\n <td bgcolor=\"#EEEEEE\"><a href=\""+fldField1+"\"><font face=\"arial\" size=\"2\">Advanced Search</font></a></td>"); out.println("\n </tr>\n </table>"); } catch (Exception e) { out.println(e.toString()); } }%>

Common.jsp// this file include all the common database access methods which are used in every page

public static void absolute(java.sql.ResultSet rs, int row) throws java.sql.SQLException{ for(int x=1;x<row;x++) rs.next(); } java.sql.ResultSet openrs(java.sql.Statement stat, String sql) throws java.sql.SQLException { java.sql.ResultSet rs = stat.executeQuery(sql); return (rs); }

Page 24: Mini Project_ website JSP

String dLookUp(java.sql.Statement stat, String table, String fName, String where) { java.sql.Connection conn1 = null; java.sql.Statement stat1 = null; try { conn1 = cn(); stat1 = conn1.createStatement(); java.sql.ResultSet rsLookUp = openrs( stat1, "SELECT " + fName + " FROM " + table + " WHERE " + where); if (! rsLookUp.next()) { rsLookUp.close(); stat1.close(); conn1.close(); return ""; } String res = rsLookUp.getString(1); rsLookUp.close(); stat1.close(); conn1.close(); return (res == null ? "" : res); } catch (Exception e) { return ""; } }

long dCountRec(java.sql.Statement stat, String table, String sWhere) { long lNumRecs = 0; try { java.sql.ResultSet rs = stat.executeQuery("select count(*) from " + table + " where " + sWhere); if ( rs != null && rs.next() ) { lNumRecs = rs.getLong(1); } rs.close(); } catch (Exception e ) {}; return lNumRecs; } String proceedError(javax.servlet.http.HttpServletResponse response, Exception e) { return e.toString(); } String[] getFieldsName ( java.sql.ResultSet rs ) throws java.sql.SQLException { java.sql.ResultSetMetaData metaData = rs.getMetaData();

Page 25: Mini Project_ website JSP

int count = metaData.getColumnCount(); String[] aFields = new String[count]; for(int j = 0; j < count; j++) { aFields[j] = metaData.getColumnLabel(j+1); } return aFields; }

java.util.Hashtable getRecordToHash ( java.sql.ResultSet rs, java.util.Hashtable rsHash, String[] aFields ) throws java.sql.SQLException { for ( int iF = 0; iF < aFields.length; iF++ ) { rsHash.put( aFields[iF], getValue(rs, aFields[iF])); } return rsHash; }

java.sql.Connection cn() throws java.sql.SQLException { return java.sql.DriverManager.getConnection(strConn , DBusername, DBpassword); }

String toURL(String strValue){ if ( strValue == null ) return ""; if ( strValue.compareTo("") == 0 ) return ""; return java.net.URLEncoder.encode(strValue); } String toHTML(String value) { if ( value == null ) return ""; value = replace(value, "&", "&amp;"); value = replace(value, "<", "&lt;"); value = replace(value, ">", "&gt;"); value = replace(value, "\"", "&" + "quot;"); return value; } String getValueHTML(java.sql.ResultSet rs, String fieldName) { try { String value = rs.getString(fieldName); if (value != null) { return toHTML(value); } } catch (java.sql.SQLException sqle) {} return ""; } String getValue(java.sql.ResultSet rs, String strFieldName) {

Page 26: Mini Project_ website JSP

if ((rs==null) ||(isEmpty(strFieldName)) || ("".equals(strFieldName))) return ""; try { String sValue = rs.getString(strFieldName); if ( sValue == null ) sValue = ""; return sValue; } catch (Exception e) { return ""; } }

String getParam(javax.servlet.http.HttpServletRequest req, String paramName) { String param = req.getParameter(paramName); if ( param == null || param.equals("") ) return ""; param = replace(param,"&amp;","&"); param = replace(param,"&lt;","<"); param = replace(param,"&gt;",">"); param = replace(param,"&amp;lt;","<"); param = replace(param,"&amp;gt;",">"); return param; }

boolean isNumber (String param) { boolean result; if ( param == null || param.equals("")) return true; param=param.replace('d','_').replace('f','_'); try { Double dbl = new Double(param); result = true; } catch (NumberFormatException nfe) { result = false; } return result; }

boolean isEmpty (int val){ return val==UNDEFINT; } boolean isEmpty (String val){ return (val==null || val.equals("")||val.equals(Integer.toString(UNDEFINT))); }

Page 27: Mini Project_ website JSP

String getCheckBoxValue (String val, String checkVal, String uncheckVal, int ctype) { if (val==null || val.equals("") ) return toSQL(uncheckVal, ctype); else return toSQL(checkVal, ctype); } String toWhereSQL(String fieldName, String fieldVal, int type) { String res = ""; switch(type) { case adText: if (! "".equals(fieldVal)) { res = " " + fieldName + " like '%" + fieldVal + "%'"; } case adNumber: res = " " + fieldName + " = " + fieldVal + " "; case adDate: res = " " + fieldName + " = '" + fieldVal + "' "; default: res = " " + fieldName + " = '" + fieldVal + "' "; } return res; }

String toSQL(String value, int type) { if ( value == null ) return "Null"; String param = value; if ("".equals(param) && (type == adText || type == adDate) ) { return "Null"; } switch (type) { case adText: { param = replace(param, "'", "''"); param = replace(param, "&amp;", "&"); param = "'" + param + "'"; break; } case adSearch_: case ad_Search_: { param = replace(param, "'", "''"); break; } case adNumber: { try { if (! isNumber(value) || "".equals(param)) param="null"; else param = value; } catch (NumberFormatException nfe) {

Page 28: Mini Project_ website JSP

param = "null"; } break; } case adDate: { param = "'" + param + "'"; break; } } return param; }

private String replace(String str, String pattern, String replace) { if (replace == null) { replace = ""; } int s = 0, e = 0; StringBuffer result = new StringBuffer((int) str.length()*2); while ((e = str.indexOf(pattern, s)) >= 0) { result.append(str.substring(s, e)); result.append(replace); s = e + pattern.length(); } result.append(str.substring(s)); return result.toString(); }

String getOptions( java.sql.Connection conn, String sql, boolean isSearch, boolean isRequired, String selectedValue ) {

String sOptions = ""; String sSel = "";

if ( isSearch ) { sOptions += "<option value=\"\">All</option>"; } else { if ( ! isRequired ) { sOptions += "<option value=\"\"></option>"; } } try { java.sql.Statement stat = conn.createStatement(); java.sql.ResultSet rs = null; rs = openrs (stat, sql); while (rs.next() ) {

Page 29: Mini Project_ website JSP

String id = toHTML( rs.getString(1) ); String val = toHTML( rs.getString(2) ); if ( id.compareTo(selectedValue) == 0 ) { sSel = "SELECTED"; } else { sSel = ""; } sOptions += "<option value=\""+id+"\" "+sSel+">"+val+"</option>"; } rs.close(); stat.close(); } catch (Exception e) {} return sOptions; }

String getOptionsLOV( String sLOV, boolean isSearch, boolean isRequired, String selectedValue ) { String sSel = ""; String slOptions = ""; String sOptions = ""; String id = ""; String val = ""; java.util.StringTokenizer LOV = new java.util.StringTokenizer( sLOV, ";", true); int i = 0; String old = ";"; while ( LOV.hasMoreTokens() ) { id = LOV.nextToken(); if ( ! old.equals(";") && ( id.equals(";") ) ) { id = LOV.nextToken(); } else { if ( old.equals(";") && ( id.equals(";") ) ) { id = ""; } } if ( ! id.equals("") ) { old = id; }

i++;

if (LOV.hasMoreTokens()) { val = LOV.nextToken(); if ( ! old.equals(";") && (val.equals(";") ) ) { val = LOV.nextToken();

Page 30: Mini Project_ website JSP

} else { if (old.equals(";") && (val.equals(";"))) { val = ""; } } if ( val.equals(";") ) { val = ""; } if ( ! val.equals("")) { old = val; } i++; }

if ( id.compareTo( selectedValue ) == 0 ) { sSel = "SELECTED"; } else { sSel = ""; } slOptions += "<option value=\""+id+"\" "+sSel+">"+val+"</option>"; } if ( ( i % 2 ) == 0 ) sOptions += slOptions; return sOptions; }

String getValFromLOV( String selectedValue , String sLOV) { String sRes = ""; String id = ""; String val = ""; java.util.StringTokenizer LOV = new java.util.StringTokenizer( sLOV, ";", true); int i = 0; String old = ";"; while ( LOV.hasMoreTokens() ) { id = LOV.nextToken(); if ( ! old.equals(";") && ( id.equals(";") ) ) { id = LOV.nextToken(); } else { if ( old.equals(";") && ( id.equals(";") ) ) { id = ""; } } if ( ! id.equals("") ) { old = id; }

i++;

if (LOV.hasMoreTokens()) {

Page 31: Mini Project_ website JSP

val = LOV.nextToken(); if ( ! old.equals(";") && (val.equals(";") ) ) { val = LOV.nextToken(); } else { if (old.equals(";") && (val.equals(";"))) { val = ""; } } if ( val.equals(";") ) { val = ""; } if ( ! val.equals("")) { old = val; } i++; }

if ( id.compareTo( selectedValue ) == 0 ) { sRes = val; } } return sRes; }

String checkSecurity(int iLevel, javax.servlet.http.HttpSession session, javax.servlet.http.HttpServletResponse response, javax.servlet.http.HttpServletRequest request){ try { Object o1 = session.getAttribute("UserID"); Object o2 = session.getAttribute("UserRights"); boolean bRedirect = false; if ( o1 == null || o2 == null ) { bRedirect = true; } if ( ! bRedirect ) { if ( (o1.toString()).equals("")) { bRedirect = true; } else if ( (new Integer(o2.toString())).intValue() < iLevel) { bRedirect = true; } }

if ( bRedirect ) { response.sendRedirect("Login.jsp?querystring=" + toURL(request.getQueryString()) + "&ret_page=" + toURL(request.getRequestURI())); return "sendRedirect"; } } catch(Exception e){}; return ""; }

Page 32: Mini Project_ website JSP

%>

Header.jsp// common header used in every page

<table cellspacing="0" cellpadding="0" background="images/background.gif"> <tr> <td><img src="images/logo.gif"><a href="http://www.clicktobuy.com"><img border="0" src="images/banner.gif"></a> </td><tr><td><hr color="#000000" size="1"><br></td></tr></table><table cellspacing="0" cellpadding="0" background="images/background.gif"><tr><td valign="top"> <table> <tr> <td valign="top"><% Header_Show(request, response, session, out, sHeaderErr, sForm, sAction, conn, stat); %> </td> </tr> </table></td><td><img src="images/0-0.gif" width="30"></td><td>

Login.jsp

<body bgcolor="#FFFFFF"><jsp:include page="Header.jsp" flush="true"/> <table> <tr>

<td valign="top"><% Login_Show(request, response, session, out, sLoginErr, sForm, sAction, conn, stat); %> admin/admin<br>

Page 33: Mini Project_ website JSP

guest/guest </td> </tr> </table>

<jsp:include page="Footer.jsp" flush="true"/></body></html>

Output Screenshots

Page 34: Mini Project_ website JSP

Default.jsp - Home Screen

– A common header which will follow on every page.– A Search box to search particular ad.– A Tree notifying all adds in hierarchical manner.– A login box which will ask to enter username if none is logged in

Page 35: Mini Project_ website JSP

Registration page

• This page is used to make a new user account by taking basic information.

• This page also assign a unique user id to every user

Page 36: Mini Project_ website JSP

Login• This page is used to Login to a specific user account to provide Access

privilege.• This window will popup for every unauthorized access

Page 37: Mini Project_ website JSP

Administration Window

• This is Admin page which allows admin to make changes in Member info and can also make changes to Categories.

Page 38: Mini Project_ website JSP

Member Registration Administration

• Here Admin can make changes to user accounts or can also add new accounts.

Page 39: Mini Project_ website JSP

My Classifieds

• This page Shows the ads entered in database by current logged in user.

Page 40: Mini Project_ website JSP

New Ad

This page allow current logged in user to add a new ad

Page 41: Mini Project_ website JSP

Adv. Search

• Adv Search box search for the entries of ads in database according to price bars and also in particular order.

Page 42: Mini Project_ website JSP

Why a Classifieds Site?

In 2003, the market for online classified ads was over $100 billion according to market researcher Classified Intelligence. In 2006 it generated revenue of $2.1 billion

Newspapers have continued their downward trend in classifieds revenue as internet classifieds grow. Classified advertising at some of the larger newspaper chains has dropped 14% to 20% in 2007 while traffic to classified sites has grown 23%.

As the online classified advertising sector develops, there is an increasing emphasis toward specialization. Vertical markets for classifieds are developing quickly along with the general marketplace for classifieds websites. Like search engines, classified websites are often vertical in nature with sites providing advertising platforms for niche markets of buyers of sellers.