Home Answers Viewqa JSP-Servlet how to write a program to search a record using mvc2

 
 


josh
how to write a program to search a record using mvc2
1 Answer(s)      a year and 10 months ago
Posted in : JSP-Servlet

how can we write a code to search a record in table by using java bean as model, servlet as contoller and jsp as view

View Answers

July 12, 2011 at 10:57 AM


1)EmpBean.java:

package form;
import java.sql.*;
import java.util.*;
public class EmpBean {

public List dataList(){
ArrayList list=new ArrayList();
try{
     Class.forName("com.mysql.jdbc.Driver");
           Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/test", "root", "root");
           Statement st=con.createStatement();
           ResultSet rs=st.executeQuery("select * from employee");
           while(rs.next()){
               list.add(rs.getString("name"));
               list.add(rs.getString("address"));
               list.add(rs.getString("contactNo"));
               list.add(rs.getString("email"));

}
}
catch(Exception e){}
return list;

}
}

2)BeanInServlet.java:

import java.io.*;
import java.util.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class BeanInServlet extends HttpServlet{
    protected void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException{
        form.EmpBean p = new form.EmpBean();
        List list=p.dataList();

        req.setAttribute("data", list);
        RequestDispatcher rd = req.getRequestDispatcher("/jsp/beandata.jsp");
        rd.forward(req, res);
    }
}

3)beandata.jsp:

<%@page language="java" import="java.util.*" %>
<html>
<body> 
<table border="1" width="303">
<tr>
<td width="119"><b>Name</b></td>
<td width="168"><b>Address</b></td>
<td width="119"><b>Contact no</b></td>
<td width="168"><b>Email</b></td>
</tr>
<% Iterator itr;%>
<% List data=(List)request.getAttribute("data");
for(itr=data.iterator(); itr.hasNext(); ){
%>
<tr>
<td width="119"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
<td width="168"><%=itr.next()%></td>
</tr>
<%}%>
</table>
</body>
</html>









Related Pages:
how to write a program to search a record using mvc2
how to write a program to search a record using mvc2   how can we write a code to search a record in table by using java bean as model, servlet as contoller and jsp as view
How to write a search functionality using javascript/jquery
How to write a search functionality using javascript/jquery   How to write a search functionality using javascript/jquery for ex: im searching "s" names it wil display "s" names
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
binary search program
binary search program  write a program to searching a string using binary search
how to write this program
how to write this program  Write a program in java which calculates... or numerical grade. You will be submitting TWO versions of this program. Write one...?¢s GPA. This program should take a studentââ?¬â?¢s First Name, Last Name a GPA
linear search
linear search  write a program to find string using linear search
search program
search program  i m writing program which takes company names from.......m confused....how can i find best match..between my company name ..and all links after google search...plzz help
How to write to file using FileOutputStream
How to write to file using FileOutputStream  Hi friends, Please help me in java program. How to write to file using FileOutputStream? thanks,   Hi, To write a file using FileOutputStream, we have to use
Business Logic in mvc2 - JSP-Servlet
Business Logic in mvc2  What is business logic and where it is written using servlet and jsp
How to write to file using FileWriter
How to write to file using FileWriter  hi, How to write to file using FileWriter thanks,   Hi, To writing in a file in Java program we... of the FileWriter class can be created using the following of its constructor i.e. FileWriter
JAVA: Recusrion, Binary Search
it using a recursive implementation of Binary Search. For the cases when more than...JAVA: Recusrion, Binary Search  I want to learn about Binary Search and Recursion but I'm confused on how to do it. I know that I also need arrays
Insert record into a table using DBCP
-pool.jar, j2ee.jar and mysql-connector-java-5.1.7-bin.jar In the pathset.bat write
JSP Delete Record From Table Using MySQL
JSP Delete Record From Table Using MySQL This tutorial explains you that how to write a JSP for deleting a record from database table. In this section you.... In this tutorial you will learn that how to delete a record of a database table in JSP
How to write Java Program
How to write Java Program  how to write a program to find average of 5 student marks
how to record qvga video using j2me - Applet
how to record qvga video using j2me  hello if it is possible how i can record qvga video usin j2me
Write a program to print using for loop
Write a program to print using for loop  Write a program to print using for loop * * * *  
how to fetch the record using AJAX? - Ajax
how to fetch the record using AJAX?  Can anyone tell me how to fetch the records from database using Ajax
delete record
delete record  how to delete record using checkbox and button in php   We are providing you the jsp code that displays the database table data into the html table. Along each table row there is a checkbox consists
How to write in File in Java
How to write in File in Java  Hi, How to write in File in Java... bufferedWriter object to write in the file. For more details and examples related to How to write in File of Java Program
how to record qvga video using j2me - Applet
how to record qvga video using j2me  hello if it is possible how i can record qvga video usin j2me?   Hi Friend, Please visit the following links: http://www.roseindia.net/j2me/video-midlet.shtml http
how to write servlet program in eclipse?
how to write servlet program in eclipse?  how to write servlet program in eclipse
How to write calculator in J2ME program?
How to write calculator in J2ME program?  How to write calculator in J2ME program
How to perform search using AJAX?
How to perform search using AJAX?  Hi, I have following HTML code...; <td><label for="status">Search Status</td> <td><input..." value="Please enter search criteria"/></td> </tr> <tr>
Search index
Search index  how to write code for advanced search button
SEO and Search Engines,Best Search Engines on Web,What is Search Engine
of the search engine while doing SEO work. Since in SEO we are using search... which search engine is most important, how to get indexed in the search etc... is Search Engine? Search engine is a computer program for searching
how to write this program? - Java Beginners
how to write this program?  (game:scissor,rock ,paper) A program that plays the sciccor-rock-paper game.Revise the program to let the user continuously play until either the user or the computer wins more than 4 times
J2ME Record Store Example
J2ME Record Store Example       In this Midlet, we are going to read string data and write by using the RecordStore class. The package of the RecordStore class
how to write to file at the end of the line
how to write to file at the end of the line  Hi, Where do i learn how to write to file at the end of the line using Java program. Plz suggest... will help you for "How to write the file at the end of line using Java language
how to write the program - Java Beginners
how to write the program  WAP to create the report card user input Name, Class, Division, Roll no., Marks obtained in following subjects Lang Hindi History Geography Math Phy Chem. Bio Eve CSTA Also has a back up
Write a java application program........?
Write a java application program........?  Welcome every One : I have Q in Java? Q : Write a java application program that reads 20 integer numbers input by the user and prints how many numbers > 100 and how many numbers
using servlets and jsp technologies search the documents - Development process
using servlets and jsp technologies search the documents   write a program to develop search contents,uploading data and advance searching options using servlets and jsp with source code
add record to database - JDBC
add record to database  How to create program in java that can save record in database ?  Hi friend, import java.io.*; import java.sql....); if(i!=0){ out.println("The record has been inserted
binary search - Java Beginners
binary search  Write a java program to search an array by using recursive binary search.  /* * To change this template, choose Tools... program public static void main( String [ ] args ) { int SIZE
WRITE A PROGRAM IN JAVA
WRITE A PROGRAM IN JAVA  How do I write a program in Java, have the program display a message with your name in it and a number (Hello john Smith!1) The number must increment from zero to nine, or decrement fron nine to zero. You
search
search  how to develop search box and how to retrive data from database..   Please visit the following link: Search box
Search word from text file using Java
How to Search word from text file using Java In this section, we are going to search a word from the text file. For this, we have created a swing button... void main(String[] args) { SearchName search = new SearchName(); JButton
how to search data in xml files using php
how to search data in xml files using php  So I want to create a website that allows me (or others) to type in a words and select a relevent search... this and how can I use PHP to allow them to search through, and then display
SEARCH AND SORT
SEARCH AND SORT  Cam any one provide me the code in java that : Program to search for MAX,MIN and then SORT the set using any of the Divide and conquer method
Program
Program  hey please help me ... How can write multiple choice question paper using radio button.After submit calculate marks and display our marks... can any body help for me.using servlet,html   Here is a jsp test
Write a query to insert a record into a table
Write a query to insert a record into a table  Write a query to insert a record into a table   Hi, The query string is as follows- Insert into employee values ('35','gyan','singh'); Thanks
How to using Binary Search Array Java ?
How to using Binary Search Array Java ?  Hi, I am beginners in Java Programming Language. I am trying to create small application using Array functions. The problem is that how to use binary search array in Java. Please give
write following program
write following program  Q1 What is the difference between single...-threading. Explain with examples Q2 Write a java applet that takes your name through a parameter from the HTML file and displays it Q3 Write a short note
SEARCH
SEARCH  how can we do search in jsp...? option for search criteria like name and DOB...   Please visit the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
search for a name
search for a name  Search for a name Write a program to accept an array of names and a name and check whether the name is present in the array. Return the count of occurrence. Use the following array as input {?Dave?, ?Ann
write program have product - using loops
write program have product - using loops  Write a program for a grocery that reads products data and determine and display the product that has...), name (String) and price (double). Your program should continue reading new
how to search - WebSevices
how to search  how can I write mysql query for the following search format? Search By:(this have following options)(name,username,email) gender : male or female or both age : fromage to toage country
How i upload file and save that record in database using JSP?
How i upload file and save that record in database using JSP?  Hi All, I m the beginner in JSP and I want to upload the file and store that file and some other form data in MySQL database. Ex. There is one employee detail form

Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.