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



Home Answers Viewqa JSP-Servlet JSP:NEED RESPONSE ASAP PLEASE!

Have Programming Question? Ask it here!
 
 
 


john
JSP:NEED RESPONSE ASAP PLEASE!
2 Answer(s)      3 years and 11 months ago
Posted in : JSP-Servlet


Hi freind,

If you could respond to my previous thread which hasn't been addressed for over a week, I'd really appreciate it. and most important if you could just respond to below. thank you
I have a javascript that captures data from a highlighted row in a table and then sends this data in url to the next jsp page. The code works fine for a highlighted row that has one integer (id) column and a date column. However, i have another requirement similar where instead of the id I have to get a String a (name) column with a date. Im putting up the code, really appreciate if you can respond asap have a deadline in a day!!!! thanks


.c1 {background-color: #a6c4d4;}
.c2 {background-color: #a6c4d4;}
.c3 {background-color: #68C2EF;}


function ov(i){
document.getElementById(i).className="c3";
}
function ot(i,c){
document.getElementById(i).className=c;
}
function click(ide,d1,d2,d3){
var st=new String(d3);
if(st.length==1){
d3="0"+d3;
var d=d1+"-"+d2+"-"+d3;
alert("Editing Patient Data with ID: " +ide)
window.location.replace('http://localhost:8080/Medicare/visit_edit.jsp?id='+ide+'&&dd='+d,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
else{
var d=d1+"-"+d2+"-"+d3;
alert("Editing Patient Data with ID: " +ide)
window.location.replace('http://localhost:8080/Medicare/visit_edit.jsp?id='+ide+'&&dd='+d,'mywindow','width=500, height=350,toolbar=no,resizable=yes,menubar=yes');
}
}

Advertisement
View Answers

May 26, 2010 at 1:15 PM


Hi Friend,

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(i){
var x = document.getElementById('table');
var row = x.rows[i];
var cell1 = row.cells[0];
var content1 = cell1.firstChild.nodeValue;
var cell2 = row.cells[3];
var content2 = cell2.firstChild.nodeValue;
window.location.replace('http://localhost:8080/examples/jsp/popup.jsp?name='+content1+'&&dd='+content2,'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 id=request.getParameter("id");
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+"'");
%>
<form name="form">
<table id="table" border="1">
<%
int i=0;
while(rs.next()){
String d=rs.getString("visitedDate");
String sub1=d.substring(0,4);
String sub2=d.substring(5,7);
String sub3=d.substring(8,10);
System.out.println(sub1+" "+sub2+" "+sub3);
%>
<tr id=<%=rs.getString("id")%> class=c1 onclick='click(<%=i%>)' 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><td ><%=rs.getString("visitedDate")%></td></tr>
<%
i++;
}%>
</table>
</form>
</html>


May 26, 2010 at 1:16 PM


continue..

2)popup.jsp:

<%@page import="java.sql.*"%>
<%
String name=request.getParameter("name");
String dd=request.getParameter("dd");
Class.forName("com.mysql.jdbc.Driver").newInstance();
Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/register","root","root";);
String query = "select * from client where name='"+name+"' and visitedDate='"+dd+"'";
Statement st = con.createStatement();
ResultSet rs = st.executeQuery(query);

String nn="",add="",contact="",ide="";
while(rs.next()){
nn=rs.getString("name");
add=rs.getString("address");
contact=rs.getString("contactNo");
ide=rs.getString("id");
}
response.sendRedirect("tablepopup.jsp?id="+ide+"&&name="+nn+"&&contactNo="+contact+"&&address="+add);


%>

Thanks


Related Tutorials/Questions & Answers:
 

 

 

DMCA.com