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



Home Answers Viewqa JSP-Servlet JSP Servlet Search and Edit
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


john
JSP Servlet Search and Edit
2 Answer(s)      4 years and 6 months ago
Posted in : JSP-Servlet


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

Advertisement
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
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
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
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
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
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
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
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
Search operation in JSP page
Search operation in JSP page  How to perform search in jsp with MYSQL database plz help me
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
Search Page in jsp
Search Page in jsp  search page in jsp   Please go through the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
Search page form in jsp
Search page form in jsp  search form in jsp   Please go through the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
search form in jsp
search form in jsp  search page in jsp   Please go through the following links: http://www.roseindia.net/jsp/user-search.shtml http://www.roseindia.net/servlets/search.shtml
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 :how to edit table of data displayed using jsp when clicked on edit button
jsp :how to edit table of data displayed using jsp when clicked on edit button  i have a jsp program which displays data in the form of table ..now i want to delete this information in table when click on delete button and save
Delete and edit data in xml file using JSP
Delete and edit data in xml file using JSP   I want to know how to delete and edit data from an XML file by use of JSP. I have XML file having tasks... in the xml file,I want to delete and edit some tasks using task id then how can i do
jsp :how to edit table of data displayed using jsp when clicked on edit button
jsp :how to edit table of data displayed using jsp when clicked on edit button  i have a jsp program which displays data in the form of table ..now i want to edit this information in table when clicked on edit button and save
input type dialog box take text and search a list and focus that text - JSP-Servlet
input type dialog box take text and search a list and focus that text  i have a button..when i press it will prompt a dialog box with a text box... then it will search a list which contains data in the same page and if found
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?
create,edit and delete in JSP using struts and SQL server2005 as database in jdeveloper?  I have a project ie create an application for users to create,edit and delete tasks: taskid, taskname, date, project in JSP and struts
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
search functionality using jsp from database
search functionality using jsp from database  search functionality using jsp from database
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
Advertisements
 

 

 

DMCA.com