JSP Servlet Search and Edit

JSP Servlet Search and Edit

Hi,

I want to thank the people who took the time and made the effort to respond to my 2 questions posted, truly ROSEINDIA and its employees are very helpful and responsive and understand developer's needs.

This is a follow up to the HTML Form in-place editing(Previous Post). The code works fine when I've incorporated it in my web application, its really an excellent way of editing a form. I just have a few adjustments if any of you could help me, I'd really appreciate it.

1. The window.open(http:///...) I want to be able to open a page instead of a window for the editing which opens in the same location. Can you please show me how that can be achieved?

2. Also, your example suggests a customer id as the basis of editing. I have tired it for other String(char) columns as well and date columns, it works to some extent but not completely. It will highlight the rows but the editing page comes out empty for some reason its not excepting date/char columns to be passed to the following jsp. Also, when I use it for a character column, if the backend table column has more than one word in the table for example the mouse over and click will not distinguish when there are 2 words with a space in the middle(meaning it works for single word highlighting). Can you tell me if I can use the character columns or date columns as the basis of editing instead of the customer id? because there is such a need in my application

3. Last thing I wanted to know if you have an example, where you can do the similar thing with javascript, what I want to achieve is

- user fills out a form on one page. On the SAME page there is a search which populates the search result table, On single click or double click of the row selection, it populates the SAME form for editing. I've seen it in a VB application, I was wondering if this can be achieved with javascript?

Thank you so much in advance.

Regards,

freind
View Answers

May 11, 2010 at 12:45 PM

Hi Friend,

You can search on the basis of any field but it should be in the form of string.

Try the following code:

1)tablepopup.jsp:

<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
String n=request.getParameter("name");
String address=request.getParameter("address");
String contact=request.getParameter("contactNo");
if((id!=null)&&(n!=null)&&(address!=null)&&(contact!=null)){
%>
<form action="edits.jsp">
<table border="1" >
<tr><td>Name:</td><td><input type="text" name="name" value="<%=n%>"></td></tr>
<tr><td>Address:</td><td><input type="text" name="address" value="<%=address%>"></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="contactNo" value="<%=contact%>"></td></tr>
<tr><td></td><td><input type=submit name="edit" value="Edit"></td></tr>
</table>
<input type="hidden" name="id" value="<%=id%>">
</form>
<%
}
else{
%>
<form action="adds.jsp">
<table border="1">
<tr><td>Name:</td><td><input type="text" name="name" value=""></td></tr>
<tr><td>Address:</td><td><input type="text" name="address" value=""></td></tr>
<tr><td>Contact No:</td><td><input type="text" name="contactNo" value=""></td></tr>
<tr><td></td><td><input type=submit name="button" value="Add"></td></tr>
</table>
</form>
<%}
%>
<style>
.c1 {background-color: white;}
.c2 {background-color: white;}
.c3 {background-color: red;}
</style>
<script>
function ov(i){
document.getElementById(i).className="c3";
}
function ot(i,c){
document.getElementById(i).className=c;
}
function click(id){
alert(id);
window.location.replace('http://localhost:8080/examples/jsp/popup.jsp?id='+id,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
</script>
</head>
<form>
Search:<input type="text" name="customer"><input type=submit value="Search">
</form>
<%
String name=request.getParameter("customer");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
Statement st = con.createStatement();
ResultSet rs=st.executeQuery("select * from client where name='"+name+"'");
%>
<table id="table" border="1">
<%
while(rs.next()){
%>
<tr id=<%=rs.getString("id")%> class=c1 onclick='click(<%=rs.getString("id")%>)' onmouseover='ov("<%=rs.getString("id")%>")' onmouseout='ot("<%=rs.getString("id")%>","c1")'><td><%=rs.getString("name")%></td><td><%=rs.getString("address")%></td><td><%=rs.getString("contactNo")%></td></tr>
<%
}%>
</table>
</html>

May 11, 2010 at 12:46 PM

continue..

2)popup.jsp:

<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
String query = "select * from client where id='"+id+"'";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);
%>
<form action="edits.jsp">
<table border="1">
<%
String name="",add="",contact="",ide="";
while(rs.next()){
name=rs.getString("name");
add=rs.getString("address");
contact=rs.getString("contactNo");
ide=rs.getString("id");
}
response.sendRedirect("tablepopup.jsp?id="+ide+"&&name="+name+"&&contactNo="+contact+"&&address="+add);
%>

3)adds.jsp:

<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
String query = "select * from client where id='"+id+"'";
Statement st = con.createStatement();
String name=request.getParameter("name");
String address=request.getParameter("address");
String contactNo=request.getParameter("contactNo");
int i=st.executeUpdate("insert into client(name,address,contactNo) values('"+name+"','"+address+"','"+contactNo+"')");
out.println("Data is inserted successfully");
%>

4)edits.jsp:

<%@page import="java.sql.*"%>
<%
String id=request.getParameter("id");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
String query = "select * from client where id='"+id+"'";
Statement st = con.createStatement();
String name=request.getParameter("name");
String address=request.getParameter("address");
String contactNo=request.getParameter("contactNo");
int i=st.executeUpdate("update client set name='"+name+"',address='"+address+"',contactNo='"+contactNo+"' where id='"+id+"'");
out.println("Data is updated successfully");
%>

Thanks









Related Tutorials/Questions & Answers:
JSP Servlet Search and Edit - JSP-Servlet
JSP Servlet Search and Edit  Hi, I want to thank the people who... to the following jsp. Also, when I use it for a character column, if the backend table... there is a search which populates the search result table, On single click
edit database using jsp and servlet
edit database using jsp and servlet  I am creating a website using jsp and servlets that is used to view houses from a database. I want to be able to edit the information of each house. showAll.jsp shows all the houses and beside
Advertisements
Block edit menu option - JSP-Servlet
Block edit menu option  I am doing a jsp project. I have to control number of characters in a text area upto a limit. How can i block pasting through edit menu and pasting through short cut key [ctrl+v
search feature - JSP-Servlet
search feature  i need help to do a search feature servlet to search for employees from the database. the search will be done by search by employee name, department and email  Hi friend, As per your problem
Lucene Search in JSP - JSP-Servlet
Lucene Search in JSP  Hello Sir, I want to Develop lucene - Search engine in Jsp page which can Search full text from XML file..through XML parser.. Example: in Search interface there are one textbox after putting some value
JSP search engine - JSP-Servlet
JSP search engine  Hi! In my project i have a concept of search engine which has to search in google and display the results in my page. My PM told me use GOOGLE API for search engine. I am developing applicatin in JSP. Can
in order to create jsp and servlet code to add,delete,edit,list of persons in eclipsejavaee
in order to create jsp and servlet code to add,delete,edit,list of persons in eclipsejavaee  in order to create jsp and servlet code what all files we need to create in eclipse --dynamic web project
Source Code for Implementing Search Feature in JSP using Java action/Servlet - JSP-Servlet
Source Code for Implementing Search Feature in JSP using Java action/Servlet  How do I write the source code to implement search feature in JSP using Java action/servlet? My query is: SELECT @rownum:=@rownum+1 'rownum', X
jsp and servlet
submit button,edit button and delete button,through which we can acces the data edit the data and delete the data,using jsp and servlet...jsp and servlet  I want to create a login form,which have many fields
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
edit values of database using jsp
edit values of database using jsp  hi i want a code to edit the row from tye database and display in a page which containd radio buttons and drop down boxes using jsp code
jsp/servlet - JSP-Servlet
jsp/servlet  Hello ! How can we call a servlet on a link on html page like a href="servletname"> Call Servlet Is it possible?   Hi friend, I am sending simple application using servlet. This is form
jsp/servlet - JSP-Servlet
jsp/servlet  How to create and save the excel file on given location using jsp/servlet?  hi Geetanjali, Read for more information, http://www.roseindia.net/jsp/poi/excelPOI.shtml Thanks
JSP-Servlet - JSP-Servlet
JSP-Servlet   how to pass the value or parameter from jsp page to servlet and view the passed value.   Hi Friend, Please visit the following links: http://www.roseindia.net/tutorial/servlet/passParameters.html
jsp and servlet
jsp and servlet  what is the difference between jsp and servlet ? what is the advantages and disadvantages of jsp and servlet
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
JSP - JSP-Servlet
JSP & Servlet Example Code  Need example of JSP & Servlet
Searching for Code - JSP-Servlet
JSP, Servlet Searching for Code  Hi, i am looking for a jsp servlet code examples for the search function in my application.Thanks
servlet and jsp - JSP-Servlet
servlet and jsp  can any one give me jsp-servlet related project-its urgent- 1-chat application 2-bug tracking system 3-online shopping 4-online...://www.roseindia.net/jsp/bank.shtml Thanks
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
servlet/jsp - JSP-Servlet
servlet/jsp  hi, get me the source code to upload all file formats in servlet/jsp plaese help me as soon as possible its urgent!!! by saravanan.k  Hi friend, Code to help in solving the problem
Source Code for Implementing Search Feature in JSP using Java Action/Servlet - JSP-Interview Questions
Source Code for Implementing Search Feature in JSP using Java Action/Servlet  How do I write the source code to implement search feature in JSP using Java action/servlet? (java action is the priority, but servlet is OK) My
Servlet - JSP - JSP-Servlet
Servlet - JSP  Here is my complete code. all my code is running with out any error. the for loop in servlet is running as many times as my checkboxes... Servlet Code: ---------------------- package com.servlet
Servlet-JSP population - JSP-Servlet
Servlet-JSP population  Hi, this is regarding my previous question... let me know how to edit my code. Servlet ------------ package com.servlet... and display in the next page. I changed my servlet code something like this but i
Servlet - JSP - JSP-Servlet
Servlet - JSP  i used arraylist in servlet as shown ArrayList total = new ArrayList (); ... total.add(k[i]); session.setAttribute("efg",total); when I code this like in my jsp <%ArrayList<Integer> data= new
servlet and jsp - JSP-Servlet
servlet and jsp  Hello folks, I am very new JDBC. I am doing a project on java messaging service on the part of the project we are using JDBC. In my...   write in the jsp form action="path of servlet" and wirite
servlet and jsp - JSP-Servlet
servlet and jsp  Hi friend, please show one sample program, how to connect jsp and servlet using backend a ms-access.  Hi friend,<%@ page language="java" import="java.sql.*,java.util.*,java.text.*"
insert , edit , and delete button in one jsp page
insert , edit , and delete button in one jsp page  hello I want to ask about the way of creating a jsp page contains insert , edit , and delete buttons and manipulate data in database directly. any help please or hints
java (servlet) - JSP-Servlet
java (servlet)  how can i disable back button in brower while using servlet or JSP
Servlet-JSP population - JSP-Servlet
Servlet-JSP population  In refernce to this Question http://www.roseindia.net/answers/viewanswers/9843.html I reduced my servlet code and JSP... in my jsp page my code is working fine. If I dont check any of the item in my
Jsp-Servlet
Jsp-Servlet  how can i display the values in jsp pages as list from servlet ? can you help me out plz ? thanks
JSP,Servlet - JSP-Servlet
JSP,Servlet  How can i pass a list of objects from jsp to an Action? Please help me to do
jsp query - JSP-Servlet
jsp query  in first division there is one table which contains data with edit button... when i will click on edit button that division will become hidden and new division come with all related data
Source Code for Implementing Search Feature in JSF/JSP using Servlet - Java Beginners
Source Code for Implementing Search Feature in JSF/JSP using Servlet  How do I write the source code to implement search feature in JSF/JSP using Servlet?? Please advice using the example data below:- Thank You!! Employee
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
jsp servlet
jsp servlet  i dont know how to write a code to Create a JSP with one text field to enter the URL and a submit button.On clicking the submit button, send the request to a servlet .Once the servlet receives the request, it need
JSP & Servlet - JSP-Servlet
JSP & Servlet  In the process of login validation. i'm entering the username correct and pass wrong. when using response.sendRedirect() a new req... help me with coding ? i'm just a beginner with JSP and sServlets
JSP & Servlet - JSP-Servlet
JSP & Servlet  Its an IBM Question In the process of login validation. i'm entering the username correct and pass wrong. when using... is wrong ? can any one help me with coding ? i'm just a beginner with JSP
Advance Search in Servlet
this problem. Please provide me with the necessary coding. I'm using servlet and JSP...Advance Search in Servlet  Sir, I have built an application where.... the string typed in is "With regards to the correction in pay" later on in the search
Advance Search in Servlet
this problem. Please provide me with the necessary coding. I'm using servlet and JSP...Advance Search in Servlet  Sir, I have built an application where.... the string typed in is "With regards to the correction in pay" later on in the search
Advance Search in Servlet
this problem. Please provide me with the necessary coding. I'm using servlet and JSP...Advance Search in Servlet  Sir, I have built an application where.... the string typed in is "With regards to the correction in pay" later on in the search
Advance Search in Servlet
this problem. Please provide me with the necessary coding. I'm using servlet and JSP...Advance Search in Servlet  Sir, I have built an application where.... the string typed in is "With regards to the correction in pay" later on in the search
jsp-servlet - JSP-Servlet
jsp-servlet  what is the problem with using microsoft access as database? The sample example, i got from you is: database:mysql. One of my java faculty said, we cannot use ms-access as database because it has some dis-advantage
jsp/servlet - JSP-Servlet
jsp/servlet  Hello friends ! I want to create columns in a table at run time everyday. I am using mysql database.how should I do it? thanks in advance  Hi friend, Plz explain your problem in details to solve
servlet/jsp - JSP-Servlet
servlet/jsp  Thanks for ur feedback! But this program shows an error showing package.org.apache.commons.fileupload.servlet does not exists package.org.apache.commons.fileupload.disk does not exists
JSP - JSP-Servlet
JSP  if the jsp is converted into servlet which type of code genreted and it will exend which type of servlet?i want answer plzzzz replyyyyyyyyyy
JSP-Servlet
JSP-Servlet  Hi have created a JSP page and I need to print it when the user clicks on the print button. I have put a print button on the JSP page. Can somebody plz help me out with the Servlet page coding

Ads