Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- I have two buttons one on click set color to red and other set color to green.
- I want to set that value in database which button is clicked.
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- </head>
- <body>
- </br>
- <h3> Please select your location </h3>
- <table border="1" width="50%" height="500" align="center" >
- <tbody>
- <tr>
- <td bgcolor='' align="center" >
- <jsp:useBean id="bean" scope="session" class="org.functions" />
- <input type="submit" value="Park Here" color='<jsp:setProperty name="bean" property="color" value="red" />' name="en" onclick="this.parentNode.style.backgroundColor='red'" />
- <input type="submit" value="Cancel" color='<jsp:setProperty name="bean" property="color" value="green" />' name="en" onclick="this.parentNode.style.backgroundColor='green'" />
- </td>
- <tr>
- <form action="hello.jsp">
- <td colspan="2" align="center">
- <input type="submit" value="Ok" style="width:100px" />
- </td>
- </form>
- </tr>
- </tbody>
- </table>
- </body>
- </html>
- <%--
- Document : hello
- Created on : Jun 19, 2016, 5:49:58 PM
- Author : Abdul Rehman Ubaid
- --%>
- <%@page contentType="text/html" pageEncoding="UTF-8"%>
- <!DOCTYPE html>
- <html>
- <head>
- <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
- <title>JSP Page</title>
- </head>
- <body>
- <h1 align="center">This is hello.jsp </h1>
- <jsp:useBean id="mybean" scope="session" class="org.Second" />
- <jsp:setProperty name="mybean" property="name" />
- <jsp:setProperty name="mybean" property="mail" />
- <jsp:useBean id="bean" scope="session" class="org.functions" />
- <%
- // Second scnd = new Second();
- int a= mybean.storevalue();
- int b= bean.storeColor();
- %>
- <jsp:setProperty name="bean" property="color" />
- <jsp:setProperty name="bean" property="id" />
- <table border="1" align="center">
- <thead>
- <tr>
- <td>From Values</td>
- </tr>
- </thead>
- </table>
- <form action="ExampleDate.jsp" method="get">
- Start Date
- <input type="date" name="date" id="d" >
- Start Date
- <input type="time" name="time" >
- <br></br>
- <input type="submit" value="hmmm" name="vxc" />
- </form>
- </body>
- </html>
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package org;
- import java.sql.Connection;
- import java.sql.DriverManager;
- import java.sql.PreparedStatement;
- import java.sql.SQLException;
- /**
- *
- * @author Abdul Rehman Ubaid
- */
- public class functions {
- private String color;
- private String id;
- /**
- * @return the color
- */
- public String getColor() {
- return color;
- }
- /**
- * @param color the color to set
- */
- public void setColor(String color) {
- this.color = color;
- }
- /**
- * @return the id
- */
- public String getId() {
- return id;
- }
- /**
- * @param id the id to set
- */
- public void setId(String id) {
- this.id = id;
- }
- public int storeColor() throws ClassNotFoundException, SQLException{
- Class.forName("org.apache.derby.jdbc.ClientDriver");
- String url = "jdbc:derby://localhost:1527/sample;create=true; user=app; password=app";
- Connection con = DriverManager.getConnection(url);
- PreparedStatement ps = con.prepareStatement("INSERT INTO COLORTABLE(en, id) VALUES(?, ?)");
- ps.setString(1, color);
- ps.setString(2, id);
- int a = ps.executeUpdate();
- if(a==1){
- return a;
- }else{
- return a;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement