Java JSP
package com.wipro.semsary.model.bao;
import com.wipro.semsary.model.SearchList;
import com.wipro.semsary.model.dao.AdminModuleClass;
import java.util.ArrayList;
public class AdminClass implements AdminInterface{
AdminModuleClass admin = new AdminModuleClass();
public AdminClass() {
}
public void addNewSearchList(SearchList list) {
admin.dbConnect();
admin.insertNewSearchList(list);
}
// edit search lists
public void editSearchList(int searchID, String searchValue) {
admin.dbConnect();
admin.editSearchList(searchID, searchValue);
}
public void deleteSearchList(int searchID) {
admin.dbConnect();
admin.deleteSearchList(searchID);
}
public ArrayList<SearchList> getSearchLists(){
admin.dbConnect();
return admin.loadSearchListsFormDatabase();
}
}
*************************************************
package com.wipro.semsary.model.dao;
import com.wipro.semsary.controller.ConnectionString;
import com.wipro.semsary.model.SearchList;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
public class AdminModuleClass extends ConnectionString implements AdminModuleInterface{
public AdminModuleClass() {
}
// insert new admin search list into db
public void insertNewSearchList(SearchList searchlist) {
if (searchlist == null){
System.out.println("Error : Empty Search List !");
}else {
try {
int maxID;
maxID = getMaxIdFromTable("SEARCH_LIST", "SEARCH_ID");
stmnt = connection.createStatement();
String sql = "INSERT INTO SEARCH_LIST (SEARCH_ID,SEARCH_NAME,SEARCH_VALUE)\n" +
"VALUES (000 ," +
"'" + searchlist.getSearchName() + "'," +
"'" + searchlist.getSearchValue() + "')";
int value = stmnt.executeUpdate(sql);
System.out.println(value + " row affected");
} catch (SQLException se) {
System.err.println("SQLException information");
System.err.println ("Error msg: " + se.getMessage());
System.err.println ("SQLSTATE: " + se.getSQLState());
System.err.println ("Error code: " + se.getErrorCode());
se.printStackTrace();
se = se.getNextException(); // For drivers that support chained exceptions
}finally {
closeConnection(connection);
}
}
}
// update admin search list setting
public void editSearchList(int searchID, String searchValue) {
try {
stmnt = connection.createStatement();
String sql = "UPDATE SEARCH_LIST SET SEARCH_VALUE = '" +
searchValue + "' WHERE SEARCH_ID = " + searchID + "";
int val;
val = stmnt.executeUpdate(sql);
} catch (SQLException se) {
System.err.println("SQLException information");
System.err.println ("Error msg: " + se.getMessage());
System.err.println ("SQLSTATE: " + se.getSQLState());
System.err.println ("Error code: " + se.getErrorCode());
se.printStackTrace();
se = se.getNextException(); // For drivers that support chained exceptions
}finally {
try{
connection.close();
}catch (SQLException se){
se.printStackTrace();
}
}
}
// delete admin search list setting
public void deleteSearchList(int searchID) {
try {
stmnt = connection.createStatement();
String sql = "DELETE FROM SEARCH_LIST WHERE \n" +
"SEARCH_ID =" + searchID + "";
int val = stmnt.executeUpdate(sql);
System.out.println(val + " Row affected ! ");
} catch (SQLException se) {
System.err.println("SQLException information");
System.err.println ("Error msg: " + se.getMessage());
System.err.println ("SQLSTATE: " + se.getSQLState());
System.err.println ("Error code: " + se.getErrorCode());
se.printStackTrace();
se = se.getNextException(); // For drivers that support chained exceptions
}finally {
try{
connection.close();
}catch (SQLException se){
se.printStackTrace();
}
}
}
// Get all the search list form database
public ArrayList<SearchList> loadSearchListsFormDatabase() {
ArrayList<SearchList> searchList = new ArrayList<SearchList>();
SearchList list = new SearchList();
try {
stmnt = connection.createStatement();
String sql = "SELECT * FROM SEARCH_LIST";
ResultSet res = stmnt.executeQuery(sql);
while (res.next()){
list = new SearchList();
list.setId(Integer.parseInt(res.getString("SEARCH_ID")));
list.setSearchName(res.getString("SEARCH_NAME"));
list.setSearchValue(res.getString("SEARCH_VALUE"));
searchList.add(list);
}
} catch (SQLException se) {
System.err.println("SQLException information");
System.err.println ("Error msg: " + se.getMessage());
System.err.println ("SQLSTATE: " + se.getSQLState());
System.err.println ("Error code: " + se.getErrorCode());
se.printStackTrace();
se = se.getNextException(); // For drivers that support chained exceptions
}finally {
try{
connection.close();
}catch (SQLException se){
se.printStackTrace();
}
}
return searchList;
}
}
********************************************************
package com.wipro.semsary.presentation;
import com.wipro.semsary.model.SearchList;
import com.wipro.semsary.model.bao.AdminClass;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.*;
import javax.servlet.http.*;
public class AdminServlet extends HttpServlet {
private static final String CONTENT_TYPE = "text/html; charset=windows-1256";
AdminClass admin = new AdminClass();
SearchList list = new SearchList();
public void init(ServletConfig config) throws ServletException {
super.init(config);
}
public void doGet(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<head><title>AdminServlet</title></head>");
out.println("<body>");
out.println("<p>The servlet has received a GET. This is the reply.</p>");
out.println("</body></html>");
out.close();
}
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {
response.setContentType(CONTENT_TYPE);
String searchName = request.getParameter("searchname");
String searchValue = request.getParameter("value");
if (searchName == null || searchValue == null){
System.out.println("Null Values" + searchName + searchValue);
request.setAttribute("adminTable", admin.getSearchLists());
RequestDispatcher view = request.getRequestDispatcher("admin.jsp");
view.forward(request, response);
}else{
list.setId(00);
list.setSearchName(searchName);
list.setSearchValue(searchValue);
admin.addNewSearchList(list);
request.setAttribute("adminTable", admin.getSearchLists());
RequestDispatcher view = request.getRequestDispatcher("admin.jsp");
view.forward(request, response);
}
}
}
**************************************************
LoginServlet > admin
if (commonModule.login(username, password)) {
// Check the user if he is an admin or not
// Load admin page
user = commonModule.getUser(username);
request.getSession().setAttribute("username",user.getUsername());
if (user.getUserType() == 1) {
session.setAttribute("admin", user);
request.setAttribute("adminTable", admin.getSearchLists());
RequestDispatcher view = request.getRequestDispatcher("admin.jsp");
request.getSession().setAttribute("fullname",user.getFullname());
view.forward(request,response);
}
***************************************************
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.wipro.semsary.model.bao.TransactionClass" %>
<%@ page import="java.util.*" %>
<%@ page import="com.wipro.semsary.model.Property" %>
<%@ page import="com.wipro.semsary.model.User" %>
<html>
<head>
<!--Site Mesh Configuration -->
<meta name="selection" content="home">
<!--CSS Import -->
<link href="default.css" rel="stylesheet" type="text/css" media="screen" />
<link rel="stylesheet" href="css/lightbox.css" type="text/css" media="screen" />
<style type="text/css"></style>
<!--JAVASCRIPT Import -->
<script type="text/javascript" src="js/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous.js?load=effects,builder"></script>
<script type="text/javascript" src="js/lightbox.js"></script>
<script type="text/javascript"></script>
</head>
<!--Body Start -->
<body>
<div id="page">
<div id="page-bgtop">
<div id="page-bgbtm">
<div id="sidebar1" class="sidebar" style="height: 75px">
<ul>
<li> Semsary is the biggest company in Selling buildings </li>
<li> -<a href="images/b1.jpg" rel="lightbox">Amoro Building: Buying property requires thinking about what
you want to have as a target property.</a></li>
<li> -<a href="images/b2.jpg" rel="lightbox">Testo Building: Buying property requires thinking about what
you want to have as a target property. </a> </li>
<li> -<a href="images/b3.jpg" rel="lightbox">Supuro Building: Buying property requires thinking about what
you want to have as a target property.</a><br />
</li>
<li> -<a href="images/b4.jpg" rel="lightbox">Thoughts Building: Buying property requires thinking about what
you want to have as a target property.</a></li>
</ul>
<p> </p>
</div>
<!-- start content -->
<div id="content" style="height: 90px">
<div class="post">
<h1 class="title"> Welcome <%= session.getAttribute("fullname")%> </h1>
<p>We are a leading conpany in selling and buying houses and buildings</p>
</div>
<form method="post" action="adminservlet">
<table class="auto-style12" style="width: 100%">
<tr>
<td class="auto-style9">Search Name</td>
<td class="auto-style9">
<select name="searchname" style="width: 132px; height: 23px">
<option value="Price">Price</option>
<option value="Location">Location</option>
<option value="Type">Type</option>
</select>
</td>
</tr>
<tr>
<td class="auto-style9">Search Value(*)</td>
<td class="auto-style9">
<input name="value" type="text" />
</td>
</tr>
<tr>
<td class="auto-style9">
<input name="Submit" type="submit" value="Add Search" />
</td>
<td class="auto-style9"> </td>
</tr>
</table>
</form>
<p></p>
<div style="height:145px">
<table class="auto-style13" style="width: 100%; height: 140px; overflow:scroll" >
<tr>
<td class="auto-style9">Search Name</td>
<td class="auto-style9">Search Value</td>
<td class="auto-style9">Edit</td>
<td class="auto-style9">Delete</td>
</tr>
<c:forEach var="list" items="${requestScope.adminTable}">
<tr>
<td class="auto-style9">${list.searchName}</td>
<td class="auto-style9">${list.searchValue}</td>
<td class="auto-style9"><a href="#" >Edit</a></td>
<td class="auto-style9"><a href="#">Delete</a></td>
</tr>
</c:forEach>
</table>
</div>
</div>
<!-- end content -->
<!-- start sidebars -->
<div id="sidebar2" class="sidebar" style="height: 438px">
<ul>
<li>Welcome<a href="home.jsp"><%= session.getAttribute("fullname")%></a>
<br /><a href="changePassword.jsp">Change Password ?
</a><br />
<a href="#">Logout</a>
<br /><br />
<div class="auto-style2">
<a href="images/b1.jpg" rel="lightbox">
<input alt="Amoro" height="120" longdesc="Amoro" name="Image1" src="images/b1.jpg" type="image" width="160" /></a><br />
<a href="images/b2.jpg" rel="lightbox"><input alt="Testo" class="auto-style3" height="80" longdesc="Testo" name="Image2" src="images/b2.jpg" type="image" width="160" /></a></div>
</li>
</ul>
</div>
<!-- end sidebars -->
<div style="clear: both;"> </div>
</div>
<!-- end page -->
</div>
</div>
</body>
</html>
***********************************************
Comment s
ConnectionString class
This class is responsible for connecting to the database through a property file(config.properties)
Connect() this method is used to make the connection string and connecting to the database
closeConnection() this method is used to close the connection from the database
AdminClass
This class is a data access object that access the database for adding , editing ,deleting the search list for the admin
addNewSearchList : this method add new search to the databass
edit Search : this method edit existing search list in the database
delete search : this method delete existing search list from the database
loadallSearchLists: this method get all existing search list from the database and return them in an arraylist of type SearchList.
CommonClass
This class is responsible for adding ,editing , getting and checking users business and logic
And managing user access
Login() :this method is for logging in the user it checks for the username and password in the database then return true or false as user existence
Register(): this method for registering the user
*********************************************
Hamzaaa
*********************************************
/******************Dao*********************************/
1-AdminRolesBAO
///////////////////////getListValue////////////////////
/**
* @param listName
* @return arraylist of lists
* this method is to get the lists that match the list name parmeter
*/
/////////////////////////////////addSearchCategory//////////////////////
/**
* @param category
* @return added_or_Not
* this method to add new search ctegory to the seach category table
* and return bolean variable that indicate if the recored added succesfuly or not
* if added succesfuly return true
* if not rturn false
*/
//////////////////////////////addValueOfSearchCategory///////////////////////////
/**
* @param CategoryName
* @param CategoryValue
* @return added_or_Not
* this method can ad value for the categoryname parameter
*/
///////////////////////////////////deleteSearchCategory/////////////////////////////
/**
* @param categoryIndex
* @return added_or_Not
* this method delete list from search category table which its index as category index parameter
*/
//////////////////////////////editSearchCategory///////////////
/**
* @param CategoryKey
* @param UpdatedValue
* @return saved_or_Not
* this method can edit in the value of specific list and return true if saved and false otherwise
*/
//////////////////loadSoldBuilding/////////////////
/**
* @param sold
* @return object of type building
* load all bought buildings
*/
////////////////////////loadBuyBuilding////////////////
View Answers
August 19, 2010 at 5:55 AM
Sorry i forget
my Question is :
the Foreach tag does not return any values from the database
i used an arraylist to get the data ana iterate through it to get data
Related Tutorials/Questions & Answers:
jsp and javajsp and java how to write a
jsp and related
java code to enter student marks into database
Advertisements
java jsp - JSP-Servletjava jsp i have a
jsp file, in that i am uploading a file, after uploading the file had to display in the screen. it is displaying if only i refresh the page.
but i want to display the uploaded file without refreshing the page
java - jspjava - jsp program to view and update employee name using
JSP without database
JSP with java/servlet - JSP-ServletJSP with
java/servlet Thanks Deepak for your answere to my previous question.
With reference to my previous question about
JSP populate, actually I... (
java bean or servlet) to fecth the database.
Jsp would get the data from
multiuser in java/jsp? - JSP-Servletmultiuser in
java/
jsp? Hi!!! Rose India Team,
Kindly let me know what is exact meaning of multiuser in
java?
I made an web application using
jsp... friend,
Multi User in
Jsp : More then one User can access in Web appication
java/jspjava/jsp In a
JSP program called books.jsp, the
Java code
out.print(request.getParameter(â??numberâ??));
displays "1111111â??. What are the possible ways for the parameter number to have got its value
JAVA JSP and Servlet - JSP-ServletJAVA JSP and Servlet for sending mail through lan without intenet and also chatting facility for online users using
Java JSP & SERVLET code. Hi Friend,
Please visit the following links:
http://www.roseindia.net
Java or Jsp code - JSP-ServletJava or
Jsp code Hello Sir,
How to create the code for the password recovery page(like forgot gmail password question and answer page)using the radion buttons in display the same page in jsp.I need only how to make
JAVA,JSP,SERVELTSJAVA,
JSP,SERVELTS plz Send me Login Page by using core
java ,
Jsp,Servelts
java - JSP-Servletjava why is required to write both
jsp and servlet in a application of
java java jspjava jsp please I want code to parse a web page using Dom parser,
thanks
java jspjava jsp it is : javax.servlet.jsp only but getting error wt is reason?
Use javax.servlet.jsp.* in your code
Jsp count and java bean - JSP-ServletJsp count and
java bean Please am on a project and i want to create a countdown timer that will have this format HH:MM:SS. Am working with
jsp and
java beans please somebody help. Hi Friend,
Try the following
how to call a java class in jsp - JSP-Servlethow to call a
java class in jsp hi.. friends iam new to roseindia.i found it very nice site to clarify our douts.
i have a problem to use my
java... :
Example of Extends
Attribute of page Directive in
JSP how to call a java class in jsp - JSP-Servlethow to call a
java class in jsp hi.. friends iam new to roseindia.i found it very nice site to clarify our douts.
i have a problem to use my
java... :
Example of Extends
Attribute of page Directive in
JSP Java JSP - JDBCJava JSP JDBC connectivity in
JSP? Hi Friend,
Please visit the following link:
http://www.roseindia.net/
jsp/Accessingdatabase-fromJSP.shtml
Hope that it will be helpful for you.
Thanks
java-script,jsp - JSP-Servletjava-script,jsp how can i shift to other page when my timer shows t<=0 .i.e timeout?
Hi Friend,
Try the following code:
timer.jsp:
var time = null
function go() {
window.location = 'form.jsp
java,servlet,jsp - JSP-Servletjava,servlet,jsp i am doing a project on online examination system and in that there are problems that--
1.i want to disable the back,forward and refresh button.Please give me the code for google crome browser.
2.suppose
JSPJSP Hi,
What is
JSP? What is the use of
JSP?
Thanks
Hi,
JSP Stands for
Java Server Pages. It is
Java technology for developing web applications.
JSP is very easy to learn and it allows the developers to use
Java jsp - Java Beginners currently logged in, using
jsp and
java bean mysql as back end. urgent reply pls ... visit for more information.
http://www.roseindia.net/
jsp/
http://www.roseindia.net/
jsp/loginbean.shtml
http://www.roseindia.net/
jsp/loginstatus.shtml
java bar charts and jspjava bar charts and jsp Hi,
Can any one help me out in how to create
java bar charts using
jsp with the help of data base table values?
thanks.../
jsp/draw-statistical-chart-jsp.shtml
Java - JSP-ServletJava Dear Deepak,
In my Project we need to integrate Outlook Express mailing system with
java/
jsp.
thanks & regards,
vijayababu.m
java - JSP-Servletjava can anyone help me with an idea to develop whiteboard using
jsp.
it is very important for me.
Thank you.
Ram
Java Code - JSP-ServletJava Code Write a
JSP program which displays a webpage containg arrival of new items within a particular month in the different branches of a retail company
java charts - JSP-Servletjava charts Hi,can any one tell me how to create dyanamic charts wrt database contents by using
jsp-servlet
Java - JSP-ServletJava,
JSP vs Servlet If anyone have idea about how to use all these technologies in one project ..please share with me. Thanks
JSP - Java BeginnersJSP sir,
how to use in core jave code?This is not servlet.how to redirect from core
java to servlet or
jsp or html file
java - JSP-Interview Questionsjava hi..
snd some
JSP interview Q&A
and i wnt the JNI(
Java Native Interface) concepts matrial
thanks
krishna Hi friend,
Read more information.
http://www.roseindia.net/interviewquestions/
jsp-interview
java script - JSP-Servletjava script hello buddy......i m new to here....please help me to solve my problem
i have a
jsp page with pre populated value comming from other
jsp.....ones i submitted i have to clear that page and i have to submite
Java Problem - JSP-ServletJava Problem How to run a Simple
JSP program ? what steps... the webapps folder of apache tomcat.
5)Create a
jsp file 'hello.jsp'.You can put your
jsp file either inside the web application folder along with WEB-INF or you
java servet +jsp+mysqldatabasejava servet +
jsp+mysqldatabase I created three servlets(based on title, bookname, author) and one
jsp page. in
jsp page i put one dropdown list box(that is title, author, bookname) and created mysql database column values
how to include a java class in jsp - JSP-Servlethow to include a
java class in jsp hello sir,
this is my first question, i want know that how to use a
java class function's variables and methods of a
java class in jsp.if possible plz tr to explain with a simple example
JSP to output Java String Array - JSP-ServletJSP to output
Java String Array I am just a little confused about the output that I would get from printing a 2D String array loaded with database fields. For example lets say we have the following array: String [ ][ ] array
JSP - Java Server PagesJSP
JSP stands for
Java Server Pages.
JSP is
Java technologies for creating
dynamic web applications.
JSP allows the developer to embed
Java code inside
HTML. It makes the development of dynamic web application very easy in
Java Display Java in JSPDisplay
Java in JSP please i need urgent help. How can i display
Java Applet created in netbeans in
JSP?.
the Application involves MYSQL Database connection. Thanks
java and oracle - JSP-Servletjava and oracle I am developing a small project where I need to upload the resume of the employee and store it into database and retrieve the same... and
jsp Java - JSP-ServletJava Hi All,
How to integrate Outlook Express with
java/
jsp.
Plase any one help me.
thanks®ards,
vijayababu.m Hi Friend,
Use the following:
Send Mail
Thanks
jspjsp how to assign javascript varible to
java method in
jsp without using servlet
jsp - Java Interview QuestionsWhat is
Java JSP and
Java Servlet What is
JSP? and ..What is Servlet in
Java?
jsp: separate the prsentation and business logic.(custom.... * Abbreviation for
JSP is
Java Server Pages. That is
java code can
JSP - Java BeginnersJSP Hai friends,
I want to use the flash image on
jsp or
java script, if i click the image then it goes to the next page...... If any one... the following link:
http://www.roseindia.net/
jsp/add-flash-jsp.shtml
Hope