Advertisement
Guest User

Untitled

a guest
Oct 31st, 2016
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. I have two buttons one on click set color to red and other set color to green.
  2. I want to set that value in database which button is clicked.
  3.  
  4. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  5. <!DOCTYPE html>
  6. <html>
  7. <head>
  8. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  9. <title>JSP Page</title>
  10. </head>
  11. <body>
  12. </br>
  13. <h3> Please select your location </h3>
  14. <table border="1" width="50%" height="500" align="center" >
  15. <tbody>
  16. <tr>
  17. <td bgcolor='' align="center" >
  18. <jsp:useBean id="bean" scope="session" class="org.functions" />
  19. <input type="submit" value="Park Here" color='<jsp:setProperty name="bean" property="color" value="red" />' name="en" onclick="this.parentNode.style.backgroundColor='red'" />
  20. <input type="submit" value="Cancel" color='<jsp:setProperty name="bean" property="color" value="green" />' name="en" onclick="this.parentNode.style.backgroundColor='green'" />
  21.  
  22. </td>
  23. <tr>
  24. <form action="hello.jsp">
  25. <td colspan="2" align="center">
  26. <input type="submit" value="Ok" style="width:100px" />
  27. </td>
  28. </form>
  29. </tr>
  30.  
  31. </tbody>
  32. </table>
  33. </body>
  34. </html>
  35.  
  36. <%--
  37. Document : hello
  38. Created on : Jun 19, 2016, 5:49:58 PM
  39. Author : Abdul Rehman Ubaid
  40. --%>
  41.  
  42. <%@page contentType="text/html" pageEncoding="UTF-8"%>
  43. <!DOCTYPE html>
  44. <html>
  45. <head>
  46. <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  47. <title>JSP Page</title>
  48. </head>
  49. <body>
  50. <h1 align="center">This is hello.jsp </h1>
  51. <jsp:useBean id="mybean" scope="session" class="org.Second" />
  52.  
  53. <jsp:setProperty name="mybean" property="name" />
  54. <jsp:setProperty name="mybean" property="mail" />
  55. <jsp:useBean id="bean" scope="session" class="org.functions" />
  56.  
  57. <%
  58. // Second scnd = new Second();
  59. int a= mybean.storevalue();
  60. int b= bean.storeColor();
  61.  
  62.  
  63. %>
  64. <jsp:setProperty name="bean" property="color" />
  65. <jsp:setProperty name="bean" property="id" />
  66. <table border="1" align="center">
  67. <thead>
  68. <tr>
  69. <td>From Values</td>
  70. </tr>
  71. </thead>
  72. </table>
  73. <form action="ExampleDate.jsp" method="get">
  74.  
  75. Start Date
  76. <input type="date" name="date" id="d" >
  77.  
  78. Start Date
  79. <input type="time" name="time" >
  80. <br></br>
  81. <input type="submit" value="hmmm" name="vxc" />
  82. </form>
  83. </body>
  84.  
  85. </html>
  86.  
  87. /*
  88. * To change this license header, choose License Headers in Project Properties.
  89. * To change this template file, choose Tools | Templates
  90. * and open the template in the editor.
  91. */
  92. package org;
  93.  
  94. import java.sql.Connection;
  95. import java.sql.DriverManager;
  96. import java.sql.PreparedStatement;
  97. import java.sql.SQLException;
  98.  
  99. /**
  100. *
  101. * @author Abdul Rehman Ubaid
  102. */
  103. public class functions {
  104. private String color;
  105. private String id;
  106.  
  107. /**
  108. * @return the color
  109. */
  110.  
  111. public String getColor() {
  112. return color;
  113. }
  114.  
  115. /**
  116. * @param color the color to set
  117. */
  118. public void setColor(String color) {
  119. this.color = color;
  120. }
  121.  
  122. /**
  123. * @return the id
  124. */
  125. public String getId() {
  126. return id;
  127. }
  128.  
  129. /**
  130. * @param id the id to set
  131. */
  132. public void setId(String id) {
  133. this.id = id;
  134. }
  135.  
  136. public int storeColor() throws ClassNotFoundException, SQLException{
  137. Class.forName("org.apache.derby.jdbc.ClientDriver");
  138. String url = "jdbc:derby://localhost:1527/sample;create=true; user=app; password=app";
  139. Connection con = DriverManager.getConnection(url);
  140. PreparedStatement ps = con.prepareStatement("INSERT INTO COLORTABLE(en, id) VALUES(?, ?)");
  141. ps.setString(1, color);
  142. ps.setString(2, id);
  143. int a = ps.executeUpdate();
  144. if(a==1){
  145. return a;
  146. }else{
  147. return a;
  148. }
  149. }
  150.  
  151.  
  152. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement