|
|
| JSP |
Expert:Ragavendran.R
Respected sir/Madam, I am R.Ragavendran. I am In a very very urgent need of a program. Actually I have done it 50% and for the rest, I need your kind help.The Requirement is as follows: 1) My HTML Page must consist of a combo box or list box which includes all the employee iD's present in the database. The ID present in the List box, when clicked, must fit into the Employee ID text Box automatically along with the detail of employee name for which I have provided another text box when query operation is submitted. Here is the code: FindEmployee.html: <HTML> <BODY BGCOLOR="LIGHTYELLOW"> <FORM METHOD="POST" ACTION="process.jsp"> <H3> <P ALIGN="CENTER"> <FONT SIZE=6> EMPLOYEE DETAILS </FONT> </P> </H3> </BR> </BR> <BR> <BR> <TABLE CELLSPACING=5 CELLPADDING=5 BGCOLOR="LIGHTBLUE" COLSPAN=2 ROWSPAN=2 ALIGN="CENTER"> <TR> <TD> <FONT SIZE=5> Enter Employee ID </TD> <TD> <INPUT TYPE="TEXT" NAME="id"> </FONT> </TD> </TR> <TR> <TD> <FONT SIZE=5> Enter Employee Name </TD> <TD><INPUT TYPE="TEXT" NAME="name"> </FONT> </TD> </TR> <TR> <TD> <FONT SIZE=5> Enter New Name (For UPDATE only) </TD> <TD><INPUT TYPE="TEXT" NAME="nname"> </FONT> </TD> </TR> <TR> <FONT SIZE=6> <B> <TD><INPUT TYPE="RADIO" NAME="r1" VALUE="add" >Insert </TD> </TR> <TR> <TD><INPUT TYPE="RADIO" NAME="r1" VALUE="del" >Delete </TD> </TR> <TR> <TD><INPUT TYPE="RADIO" NAME="r1" VALUE="mod" >Update </TD> </TR> <TR> <TD><INPUT TYPE="RADIO" NAME="r1" VALUE="query">Query </TD> </TR> </FONT> </B> <TR> <TD><INPUT TYPE="SUBMIT" VALUE="Submit"> <INPUT TYPE="RESET" VALUE="Reset"> </TD> </TR> </FORM> </BODY> </HTML>
Process.jsp: <%@ page language="java" %> <%@ page import="java.lang.*" %> <%@ page import="java.sql.*" %> <HTML> <BODY bgcolor="LIGHTYELLOW"> <FORM NAME="f1" ACTION="FindEmployee.html"> <% String str=request.getParameter("r1"); String sessionValue=""; try { if(str.equals("add")) { String name=request.getParameter("name"); String code=request.getParameter("id"); int EmpID=Integer.parseInt(code); String Inserted; try { String que="INSERT INTO employee (Emp_code,Emp_name) VALUES("+EmpID+",'"+name+"')"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Employee","",""); Statement stmt=null; stmt=con.createStatement(); int ins=stmt.executeUpdate(que); session.setAttribute("status","Inserted"); sessionValue=(String)session.getAttribute("status"); if(sessionValue.equals("Inserted")) { %> <script language="javascript"> alert("Insertion successful"); document.location="FindEmployee.html"; </script> <% } con.commit(); stmt.close(); con.close(); } catch(Exception e) { out.println(e.toString()); } } %> <% if(str.equals("del")) { String name=request.getParameter("name"); String code=request.getParameter("id"); int EmpID=Integer.parseInt(code); String Deleted; try { String rem="DELETE Emp_code,Emp_name FROM Employee where Emp_code=?"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Employee","",""); PreparedStatement stmt=null; stmt=con.prepareStatement(rem); stmt.setInt(1,EmpID); int erase=stmt.executeUpdate(); if(erase==0) { %> <script language="javascript"> alert("This Emp ID Not found"); document.location="FindEmployee.html"; </script> <% } if(erase==1) { %> <script language="javascript"> alert("Deletion Successful"); document.location="FindEmployee.html"; </script> <% } con.commit(); stmt.close(); con.close(); } catch(Exception e) { out.println(e.toString()); } } %> <% if(str.equals("mod")) { String rep=request.getParameter("nname"); String code=(String)request.getParameter("id"); int ID=Integer.parseInt(code); try { String rec="UPDATE Employee SET Emp_name='"+rep+"' where Emp_code='"+ID+"'"; Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); Connection con=DriverManager.getConnection("jdbc:odbc:Employee","",""); Statement stmt=null; stmt=con.createStatement(); int mod=stmt.executeUpdate(rec); if(mod==0) { %> <script language="javascript"> alert("This Emp ID Not found"); document.location="FindEmployee.html"; </script> <% } if(mod==1) { %> <script language="javascript"> alert("Record updated successfully"); document.location="FindEmployee.html"; </script> <% } con.commit(); stmt.close(); con.close(); } catch(Exception e) { out.println(e.toString()); } } } catch(NumberFormatException ne) { %> <script language="javascript"> alert("Please Enter a Valid ID"); document.location="FindEmployee.html"; </script> <% } catch(NullPointerException nu) { %> <script language="javascript"> alert("Invalid Request. Please Try Again."); document.location="FindEmployee.html"; </script> <% } %> I NEED THE CODING FOR QUERY HERE WHEN COMBO BOX IS CLICKED if(str.equals("query")) { YOUR CODE PLZ
Thank You/Regards, R.Ragavendran.. </FORM> </BODY> </HTML>
|
| Answers |
Dear Raghavendran, Your wrote the code in clumsy way. To fullfill your requirement , it is not possible to do like this. Tell me your requirements clearly. I will give you complete code which satisfies your requirements.
Onething i want to tell u regarding ur problem. It is not possible to dynamically populate the data in a html form. It must be jsp. Because, html is static where as jsp is dynamic.
|
| More Questions |
|
|
Post Answers
Ask Question
Facing Programming Problem?
|
|
|
|
|