Java web项目:花卉管理系统,阴影,个人想出的设计理解,hover伪类选择器【诗书画唱】






create table flowerDB(
id int primary key auto_increment,
name varchar(100) not null,
anothername varchar(100) not null,
property varchar(100) not null,
price double not null ,
production varchar(100) not null );
insert into flowerDB(
name,
anothername,
property,
price,
production
) values ("花卉名称1",'花卉别名1','科属1',1,'原产地1'),
("花卉名称2",'花卉别名2','科属2',2,'原产地2'),("花卉名称3",'花卉别名3','科属3',3,'原产地3');
--drop table flowerDB
--select * from flowerDB






package com.SSHC.bean;
public class flowerDB {
private Integer id;
private String name;
private String anothername;
private String property;
private Double price;
private String production;
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAnothername() {
return anothername;
}
public void setAnothername(String anothername) {
this.anothername = anothername;
}
public String getProperty() {
return property;
}
public void setProperty(String property) {
this.property = property;
}
public Double getPrice() {
return price;
}
public void setPrice(Double price) {
this.price = price;
}
public String getProduction() {
return production;
}
public void setProduction(String production) {
this.production = production;
}
}


package com.SSHC.controller;
import java.io.IOException;
import java.util.Date;
import java.util.regex.Pattern;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.SSHC.DAO.Dao;
import com.SSHC.bean.flowerDB;
/**
* Servlet implementation class addOKServlet
*/
@WebServlet("/AddServlet")
public class AddServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public AddServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest
* request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest
* request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest
request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
String name = request.getParameter("name");
String anothername= request.getParameter("anothername");
String property= request.getParameter("property");
String price = request.getParameter("price");
String production = request.getParameter("production");
System.out.println(name+" "+anothername+" "+property
+" "+property);
Double price2=0.0;
//*表示字符出现的次数是任意多次
//+和{1,}都表示字符出现的次数是1或者多次
//Boolean B = Pattern.matches("\\d{1,}.*\\d+", price);
if(price!= null && price.length() > 0
// &&B==true
) {
price2=Double.parseDouble(price);
}
flowerDB u = new flowerDB();
u.setName(name);
u.setAnothername(anothername);
u.setProperty(property);
u.setPrice(price2);
u.setProduction(production);
Dao ud = new Dao();
ud.add(u);
String S=null;
if(ud.count>0) {
S="添加成功!";
}else
{
S="添加失败!";
}
request.setAttribute("S", S);
request.getRequestDispatcher("FirstPageServletStart")
.forward(request, response);
}
}


package com.SSHC.controller;
import java.io.IOException;
import java.util.List;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.SSHC.DAO.Dao;
import com.SSHC.bean.flowerDB;
@WebServlet("/FirstPageServletStart")
public class FirstPageServletStart extends HttpServlet {
private static final long serialVersionUID = 1L;
public FirstPageServletStart() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request,
* HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
this.doPost(request, response);
}
protected void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
Dao gd = new Dao();
List<flowerDB>list = gd.selectAll();
StringBuilder html = new StringBuilder();
for(flowerDB g : list) {
Integer getId= g.getId();
String getName= g.getName();
String getAnothername= g.getAnothername();
String getProperty= g.getProperty();
Double getPrice=g.getPrice();
String getProduction= g.getProduction();
System.out.println(getId+" "+getName+" "+getProduction);
html.append("<tr>");
html.append("<td class='inp'>" + getId + "</td>");
html.append("<td class='inp'>" +getName+ "</td>");
html.append("<td class='inp'>" +getAnothername+ "</td>");
html.append("<td class='inp'>" + getProperty + "</td>");
html.append("<td class='inp'>" + getPrice + "</td>");
html.append("<td class='inp'>" + getProduction + "</td>");
html.append("</tr>");
}
request.setAttribute("html", html);
request.getRequestDispatcher("firstPage.jsp")
.forward(request, response);
}
}


package com.SSHC.DAO;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;
import com.SSHC.bean.flowerDB;
import com.SSHC.utils.DBUtils;
public class Dao {
public List<flowerDB>selectAll(){
String sql = "select * from flowerDB";
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
List<flowerDB>list = new ArrayList<flowerDB>();
try {
conn = DBUtils.getConn();
pstm = conn.prepareStatement(sql);
rs = pstm.executeQuery();
while(rs.next()) {
Integer id = rs.getInt("id");
String name = rs.getString("name");
String anothername = rs.getString("anothername");
String property = rs.getString("property");
Double price = rs.getDouble("price");
String production= rs.getString("production");
System.out.println(name);
flowerDB g = new flowerDB();
g.setId(id);
g.setName(name);
g.setAnothername(anothername);
g.setProperty(property);
g.setPrice(price);
g.setProduction(production);
list.add(g);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return list;
}
public int count=0;
public Integer add(flowerDB u) {
String sql = "insert into flowerDB(name,"
+ "anothername,property,"
+ "price,production) values(?,?,?,?,?);";
Connection conn = null;
PreparedStatement pstm = null;
ResultSet rs = null;
try {
conn = DBUtils.getConn();
pstm = conn.prepareStatement(sql);
pstm.setObject(1,u.getName());
pstm.setObject(2,u.getAnothername());
pstm.setObject(3,u.getProperty());
pstm.setObject(4,u.getPrice());
pstm.setObject(5,u.getProduction());
count=pstm.executeUpdate();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}finally{
DBUtils.close(rs, pstm, conn);
}
return 0;
}
}


package com.SSHC.Filter;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
@WebFilter("/*")
public class CodeFilter implements Filter {
public CodeFilter() {
// TODO Auto-generated constructor stub
}
public void destroy() {
// TODO Auto-generated method stub
}
public void doFilter(ServletRequest request,
ServletResponse response, FilterChain chain)
throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here
request.setCharacterEncoding("utf-8");
chain.doFilter(request, response);
}
public void init(FilterConfig fConfig) throws ServletException {
// TODO Auto-generated method stub
}
}


package com.SSHC.utils;
import java.io.IOException;
import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.Properties;
public class DBUtils {
private static String driverName;
private static String url;
private static String userName;
private static String pwd;
static{
Properties prop = new Properties();
InputStream is = DBUtils.class.getClassLoader()
.getResourceAsStream("db.properties");
try {
prop.load(is);
driverName = prop.getProperty("dn");
url = prop.getProperty("url");
userName = prop.getProperty("un");
pwd = prop.getProperty("up");
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
public static Connection getConn(){
Connection conn = null;
try {
Class.forName(driverName);
conn = DriverManager.getConnection(url,userName,pwd);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return conn;
}
public static void close(ResultSet rs,PreparedStatement pstm
,Connection conn){
try {
if(rs != null) {
rs.close();
}
if(pstm != null) {
pstm.close();
}
if(conn != null) {
conn.close();
}
} catch(Exception e) {
e.printStackTrace();
}
}
}


dn=com.mysql.jdbc.Driver
url=jdbc:mysql://localhost:3306/firstjsp?useUnicode=true&characterEncoding=UTF-8
un=root
up=root



<%@ page language="java" contentType=
"text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()
+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base hreff="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
* {
font-size: 23px;
}
.inp {
box-shadow: 5px 5px 5px #888888;
border: 0px;
border-radius: 5px;
}
body{
background-image: url('img/1.jpg');
background-repeat: no-repeat;
background-size: 100%;
}
td{background-color: white}
</style>
<script type="text/javascript">
function cancel(){
window.location.hreff = 'add.jsp';
}
function doCheck(){
var name= document.getElementsByName('name')[0].value;
var anothername= document.getElementsByName('anothername')[0].value;
var property= document.getElementsByName('property')[0].value;
var price= document.getElementsByName('price')[0].value;
var production= document.getElementsByName('production')[0].value;
var reg = /.{1,}/;
var Vname= reg.test(name);
var Vanothername= reg.test(anothername);
var Vproperty=reg.test(property);
var Vprice= reg.test(price);
var Vproduction= reg.test(production);
if(!Vname) {
alert('请填写完整信息!第1框不能为空!');
return Vanothername;
}
if(!Vanothername) {
alert('请填写完整信息!第2框不能为空!');
return Vanothername;
}
if(!Vproperty) {
alert('请填写完整信息!第3框不能为空!');
return Vproperty;
}
if(!Vprice) {
alert('请填写完整信息!第4框不能为空!');
return Vprice;
}
if(!Vproduction) {
alert('请填写完整信息!第5框不能为空!');
return Vproduction;
}
}
</script>
</head>
<body>
<table style="width:100%;"cellspacing="0px" border="0px" >
<tr>
<td style="background-color:white;text-align:center;">花卉信息</td>
</tr>
<tr>
<td align="center">
<form action="AddServlet" method="post"
onsubmit="return doCheck();">
<table>
<tr>
<td>花卉名称::</td>
<td>
<input class="inp" type="text" name="name" />
</td>
</tr>
<tr>
<td>别名:</td>
<td><input class="inp" type="text" name="anothername" />
</tr>
<tr>
<td>科属:</td>
<td><input class="inp" type="text" name="property" /></td>
</tr>
<tr>
<td>价格(元/支):</td>
<td><input class="inp" type="text" name="price" /></td>
</tr>
<tr>
<td>原产地:</td>
<td><input class="inp" type="text" name="production" /></td>
</tr>
<tr>
<td colspan="2" align="center">
<input type="submit" value="添加" onclick='doCheck();' />
<input type="button" value="重置" onclick="cancel();" />
</td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>


<%@ page language="java" contentType="text/html;
charset=UTF-8" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()
+"://"+request.getServerName()
+":"+request.getServerPort()+path+"/";
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base hreff="<%=basePath%>">
<title></title>
<meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<style type="text/css">
* {
font-size: 23px;
}
a:hover
{
color:red;
text-decoration: none;
}
a{color:black;}
td{text-align: center;vertical-align: middle;}
.inp {
box-shadow: 5px 5px 5px #888888;
border: 0px;
border-radius: 5px;
}
body{
background-image: url('img/1.jpg');
background-repeat: no-repeat;
background-size: 100%;
}
td{background-color:white}
</style>
<script type="text/javascript">
function bk(){
window.location.href = 'add.jsp';
}
</script>
</head>
<body>
<table cellspacing="0px" border="0px" style="width:100%;" >
<tr>
<td style="background-color:white;
text-align:center;" class='inp'>花卉信息列表</td>
</tr>
<tr>
<td class='inp'><a hreff="javascript:bk()"
style="float:right; text-decoration: none;">增加花卉信息</a></td>
</tr>
<tr>
<td>
<table cellspacing="0px" border="0px" style="width:100%;">
<tr >
<th class='inp'>花卉编号</th>
<th class='inp'>花卉名称</th>
<th class='inp'>别名</th>
<th class='inp'>科属</th>
<th class='inp'>价格(元/支)</th>
<th class='inp'>原产地</th>
</tr>
${html }
</table>
</td>
</tr>
<tr>
<td> ${S }</td>
</tr>
</table>
</body>
</html>











