【发布时间】:2016-10-31 05:52:55
【问题描述】:
我有两个按钮:一个在点击时设置颜色为红色,另一个设置为绿色。
我想将该值存储在单击哪个按钮的数据库中。
之后,我想从数据库中获取此颜色,并希望使用<td bgcolor='' align="center" > 标签中的 get 属性在背景标签中设置。
我怎样才能轻松做到?
<!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 :
--%>
<%@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
*/
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;
}
}
}
【问题讨论】:
-
点击按钮触发java方法调用,因为jsp bean会有值,你可以使用那个bean属性将值发送到DAO
-
我是初学者,我想使用一些特定的功能,但我不知道该怎么做。
标签: javascript java html sql