Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Ajax Java JSP

Have Programming Question? Ask it here!
 
 
 


Mohammed Fathy
Java JSP
1 Answer(s)      3 years and 8 months ago
Posted in : Ajax


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>&nbsp;</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">&nbsp;</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;">&nbsp;</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////////////////



Advertisement
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:
Java jsp
Java jsp  What is JSP
jsp and java
jsp and java  how to write a jsp and related java code to enter student marks into database
Advertisements
java/jsp
java/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 - JSP-Servlet
java 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 from JSP - JSP-Servlet
Calling Java from JSP  Does anyone have an example of Calling Java from JSP
JSP with java/servlet - JSP-Servlet
JSP 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
JAVA JSP and Servlet - JSP-Servlet
JAVA 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
multiuser in java/jsp? - JSP-Servlet
multiuser 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 jsp
java jsp  please I want code to parse a web page using Dom parser, thanks
java jsp
java jsp  it is : javax.servlet.jsp only but getting error wt is reason?   Use javax.servlet.jsp.* in your code
JAVA,JSP,SERVELTS
JAVA,JSP,SERVELTS  plz Send me Login Page by using core java ,Jsp,Servelts
java - JSP-Servlet
java  why is required to write both jsp and servlet in a application of java
Java or Jsp code - JSP-Servlet
Java 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 - Java Beginners
java+jsp  I want to know how can I use java class in my jsp page?i'm...; Password:     --------------------------------- java file...://www.roseindia.net/jsp/ Thanks
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
A Java Program by using JSP
A Java Program by using JSP  how to draw lines by using JSP plz show me the solution by using program
Java JSP - JDBC
Java 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 bar charts and jsp
java 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-Servlet
java   can anyone help me with an idea to develop whiteboard using jsp. it is very important for me. Thank you. Ram
Java Code - JSP-Servlet
Java 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-Servlet
java charts  Hi,can any one tell me how to create dyanamic charts wrt database contents by using jsp-servlet
Java - JSP-Servlet
Java  Dear Deepak, In my Project we need to integrate Outlook Express mailing system with java/jsp. thanks & regards, vijayababu.m
Java - JSP-Servlet
Java, JSP vs Servlet  If anyone have idea about how to use all these technologies in one project ..please share with me. Thanks
JSP - Java Beginners
JSP  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
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
Display Java in JSP
Display 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 - JSP-Interview Questions
java  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-Servlet
java 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-script,jsp - JSP-Servlet
java-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
JSP using java - Java Beginners
JSP using java  sir, In my jsp page contains 3 hyperlinks say (link1 link2 link3).I want to write some java code using servlet for each hyperlinks.how to forward JSP page to servlet.I m using 3 hyperlinks in my page.My
java servet +jsp+mysqldatabase
java 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
java,servlet,jsp - JSP-Servlet
java,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
java and oracle - JSP-Servlet
java 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-Servlet
Java  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
jsp code - Java Beginners
JSP code and Example  JSP Code Example
Java Problem - JSP-Servlet
Java 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
Jsp count and java bean - JSP-Servlet
Jsp 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
java servlets - JSP-Servlet
java servlets  how to get the parameter value of input type file using java servlets  Hi, You can use request.getParameter(). In Jsp, --- --- IN servlet, String fileName=request.getParameter('fl'); If you
jsp - Java Interview Questions
What 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 Server Pages
JSP 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
Converting jsp variable to java variable
Converting jsp variable to java variable  Hi how to convert java script variable to java variable on same jsp page
JSP - Java Beginners
JSP  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
how to call a java class in jsp - JSP-Servlet
how 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-Servlet
how 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 code to download a video
java/jsp code to download a video  how can i download a video using jsp/servlet
Need help on JAVA JSP
Need help on JAVA JSP  Hi, I have never worked on java and I have been given an assignment where I have to fix existing issues in the tool(created using JAVA JSP). e.g. Tool does not adjust with the resolution of the screen
java - JSP-Interview Questions
Java database connectivity and accessing the database  Please explain, what is Java database connectivity and how to access the database?  Java Database Connectivity in short JDBC is an interface used to access database
Java Mail - JSP-Servlet
Java Mail  hi, i refer ur J2EE Tutorial - Send Email From JSP & Servlet to send emails from my application.but when i run the jsp it will throw thhese exceptions. ERROR.....javax.mail.SendFailedException: Sending failed
java beans - JSP-Servlet
java beans  how to get the values from this page to java page bcoz i want to insert these values into table... the problem visit to : http://www.roseindia.net/jsp/usingbeansinjsp.shtml Thanks
java - JSP-Servlet
java   which is the best tool for executing a online bank application project Netbeans or Eclipce? plz suggest best book for regarding this. ...://www.roseindia.net/jsp/bank.shtml Thanks. Amardeep
 

 

 

DMCA.com