JSP Servlet Search and Edit

Ads
 

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

Ads









Related Tutorials/Questions & Answers:
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
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
Advertisements
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
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
servlet and jsp
servlet and jsp  how to connect an jsp and an servlet without connecting to database
Servlet - JSP-Servlet
Servlet and Java Code  Example and source code in Servlet and JSP
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; import
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
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  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
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 and servlet
jsp and servlet  hello friends just want to create a jsp page... login from login page and if we submit it shud be validated in a servlet using... links: http://www.roseindia.net/jsp/loginbean.shtml http://www.roseindia.net
jsp servlet
how to write a code to Create a JSP with one text field to enter the URL  i dont know how to write a code to Create a JSP with one text field... to a servlet .Once the servlet receives the request, it need to create a thread
jsp servlet
code to Create a JSP with one text field to enter the URL and a submit button  i dont know how to write a code to Create a JSP with one text field... the request to a servlet .Once the servlet receives the request, it need to create
servlet and jsp
servlet and jsp  how can i get a form question from a database... with servlets and jspīs   Have a look at the following links: http://www.roseindia.net/jsp/paging.shtml http://www.roseindia.net/jsp/navigation
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
How to call servlet in JSP?
How to call servlet in JSP?  How to call servlet in JSP
SERVLET AND JSP
-Servlet-Search-and-Edit.html...SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user
SERVLET AND JSP
-Servlet-Search-and-Edit.html...SERVLET AND JSP  If i want tio create a login form using SUBMIT,ADD...;For more information visit the following links: http://www.roseindia.net/jsp/user
jsp servlet
jsp servlet  dispay hindi in jsp
Java Servlet - JSP-Servlet
Java Servlet   Hello Sir Could you help me in understanding directory Structure for servlet page in eclipse (IDE). I save my Sevlet in WEB-INF but it is not displaying, it is displaying code of servlet. Process used
jsp and servlet
jsp and servlet  If i want to get dynamic value in html textbox or in jsp,then how can I get the value,how the value will be transfered from servlet... javax.servlet.*; import javax.servlet.http.*; public class Servlet extends
calling servlet from jsp
calling servlet from jsp  how to call a servlet from jsp
Servlet Question - JSP-Servlet
Servlet Question  I want to call one servlet when the browser window is closed by User
Servlet Question - JSP-Servlet
Servlet Question  I want to call one servlet when the browser window is closed by User
jsp page authentication panel using jsp/servlet?
jsp page authentication panel using jsp/servlet?  I have 10 jsp jsp forms and 7 users and i want to grant variour permission like edit,delete and save for users dynamically on forms.So please refer me code

Ads