Guest User

Untitled

a guest
Sep 8th, 2016
31
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  2. pageEncoding="ISO-8859-1"%>
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  4. <html>
  5. <head>
  6. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  7. <title>Author Details</title>
  8. </head>
  9. <body>
  10. <form method="post" action="http://localhost:8080/backend">
  11. Author ID : <input type="text" name="aid"/>
  12. <input type="submit" name="submit" id="submit"/>
  13. </form>
  14. </body>
  15. </html>
  16.  
  17. <%@ page language="java" contentType="text/html; charset=ISO-8859-1"
  18. pageEncoding="ISO-8859-1"%>
  19.  
  20. <jsp:useBean id="testbean" scope="request" class=testbean />
  21. <%
  22. int aid = Integer.parseInt(request.getParameter("aid"));
  23. %>
  24. <jsp:setProperty name="testbean" property="aid" value=""/>
  25. <jsp:setProperty name="testbean" property=""/>
  26.  
  27. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  28. <html>
  29. <head>
  30. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
  31. <title></title>
  32. </head>
  33. <body>
  34. Address : <jsp:setProperty property="aid" name="id"/><br>
  35. City : <jsp:setProperty property="aid" name="id"/>
  36. <br>
  37. State : ${state} <br>
  38. Zip : ${zip} <br>
  39.  
  40. </body>
  41. </html>
  42.  
  43.  
  44. import java.sql.*;
  45. public class testbean
  46. {
  47. private String address, city, state;
  48. private int id, zip;
  49. private ResultSet rs;
  50.  
  51. public String getAddress() {
  52. return address;
  53. }
  54. public void setAddress(String address) {
  55. this.address = address;
  56. }
  57. public String getCity() {
  58. return city;
  59. }
  60. public void setCity(String city) {
  61. this.city = city;
  62. }
  63. public String getState() {
  64. return state;
  65. }
  66. public void setState(String state) {
  67. this.state = state;
  68. }
  69. public int getId() {
  70. return id;
  71. }
  72. public void setId(int id) {
  73. this.id = id;
  74. }
  75. public int getZip() {
  76. return zip;
  77. }
  78. public void setZip(int zip) {
  79. this.zip = zip;
  80. }
  81.  
  82. public ResultSet getRs(){
  83. return rs;
  84. }
  85.  
  86. public void setRs(){
  87. try{
  88. Class.forName("com.mysql.jdbc.Driver");
  89. Connection con=DriverManager.getConnection("jdbc:mysql://localhost/TestProject?", "john", "root");
  90. PreparedStatement ps = con.prepareStatement("select * from author where aid=?");
  91. ps.setInt(1, id);
  92. ResultSet rs = ps.executeQuery();
  93. if(rs.next()){
  94. setId(rs.getInt(1));
  95. setAddress(rs.getString(2));
  96. setCity(rs.getString(3));
  97. setState(rs.getString(4));
  98. setZip(rs.getInt(5));
  99. }
  100. }
  101. catch(Exception ex){
  102. System.out.println(ex);
  103. }
  104. }
  105.  
  106. }
Add Comment
Please, Sign In to add comment