今天写一个商城的练习,综合之前学习过的servlet和el表达式,来一个综合的练习;

需要用到的数据库有:

/*
Navicat MySQL Data Transfer Source Server : localhost
Source Server Type : MySQL
Source Server Version : 50718
Source Host : localhost
Source Database : shop Target Server Type : MySQL
Target Server Version : 50718
File Encoding : utf-8 Date: 04/18/2019 22:49:36 PM
*/ SET NAMES utf8;
SET FOREIGN_KEY_CHECKS = 0; -- ----------------------------
-- Table structure for `car`
-- ----------------------------
DROP TABLE IF EXISTS `car`;
CREATE TABLE `car` (
`oid` int(20) NOT NULL AUTO_INCREMENT,
`uid` varchar(200) NOT NULL,
`pid` varchar(200) NOT NULL,
`pname` varchar(200) CHARACTER SET utf8 NOT NULL,
`pimage` varchar(200) NOT NULL,
`price` varchar(200) NOT NULL,
`num` varchar(200) NOT NULL,
PRIMARY KEY (`oid`)
) ENGINE=InnoDB AUTO_INCREMENT=9 DEFAULT CHARSET=latin1; -- ----------------------------
-- Table structure for `category`
-- ----------------------------
DROP TABLE IF EXISTS `category`;
CREATE TABLE `category` (
`cid` varchar(32) NOT NULL,
`cname` varchar(20) DEFAULT NULL,
PRIMARY KEY (`cid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of `category`
-- ----------------------------
BEGIN;
INSERT INTO `category` VALUES ('', '首页'), ('', '上衣'), ('', '裙子'), ('', '裤子'), ('', '女鞋'), ('', '包包'), ('', '配饰'), ('', '美妆'), ('', '男友');
COMMIT; -- ----------------------------
-- Table structure for `orderitem`
-- ----------------------------
DROP TABLE IF EXISTS `orderitem`;
CREATE TABLE `orderitem` (
`itemid` varchar(32) NOT NULL,
`count` int(11) DEFAULT NULL,
`subtotal` double DEFAULT NULL,
`pid` varchar(32) DEFAULT NULL,
`oid` varchar(32) DEFAULT NULL,
PRIMARY KEY (`itemid`),
KEY `fk_0001` (`pid`),
KEY `fk_0002` (`oid`),
CONSTRAINT `fk_0002` FOREIGN KEY (`oid`) REFERENCES `orders` (`oid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ----------------------------
-- Table structure for `orders`
-- ----------------------------
DROP TABLE IF EXISTS `orders`;
CREATE TABLE `orders` (
`oid` varchar(32) NOT NULL,
`ordertime` datetime DEFAULT NULL,
`total` double DEFAULT NULL,
`state` int(11) DEFAULT NULL,
`address` varchar(30) DEFAULT NULL,
`name` varchar(20) DEFAULT NULL,
`telephone` varchar(20) DEFAULT NULL,
`uid` varchar(32) DEFAULT NULL,
PRIMARY KEY (`oid`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8; -- ----------------------------
-- Table structure for `product`
-- ----------------------------
DROP TABLE IF EXISTS `product`;
CREATE TABLE `product` (
`pid` int(32) NOT NULL AUTO_INCREMENT,
`pname` varchar(50) DEFAULT NULL,
`marketPrice` double DEFAULT NULL,
`shopPrice` double DEFAULT NULL,
`pimage` varchar(200) DEFAULT NULL,
`isHot` int(11) DEFAULT NULL,
`pdesc` varchar(255) DEFAULT NULL,
`pflag` int(11) DEFAULT NULL,
`cid` varchar(32) DEFAULT NULL,
`collect` int(11) DEFAULT NULL,
PRIMARY KEY (`pid`),
KEY `sfk_0001` (`cid`)
) ENGINE=InnoDB AUTO_INCREMENT=51 DEFAULT CHARSET=utf8; -- ----------------------------
-- Records of `product`
-- ----------------------------
BEGIN;
INSERT INTO `product` VALUES ('', '2017春季新款时尚百搭显高单排扣破洞高腰弹力小脚裤', '', '', 'products/1.jpg', '', '2017春季新款时尚百搭显高单排扣破洞高腰弹力小脚裤', '', '', ''), ('', '2017春季新款时尚百搭韩版显瘦纯色玫瑰花T恤', '', '', 'products/2.jpg', '', '2017春季新款时尚百搭韩版显瘦纯色玫瑰花T恤', '', '', ''), ('', '春季新款韩版大露背蝴蝶结系带收腰显瘦明线开叉喇叭线连衣裙', '', '', 'products/3.jpg', '', '春季新款韩版大露背蝴蝶结系带收腰显瘦明线开叉喇叭线连衣裙', '', '', ''), ('', '2017春夏新款韩版休闲百搭宽松简约字母绣花短袖圆领套头T恤', '', '', 'products/4.jpg', '', '2017春夏新款韩版休闲百搭宽松简约字母绣花短袖圆领套头T恤', '', '', ''), ('', '2017 春装新款韩版百搭针织打底短袖T恤女圆领纯色上衣', '', '', 'products/5.jpg', '', '2017 春装新款韩版百搭针织打底短袖T恤女圆领纯色上衣', '', '', ''), ('', '2017春季新品玫瑰字母印花蕾丝拼接长袖T恤', '', '', 'products/6.jpg', '', '2017春季新品玫瑰字母印花蕾丝拼接长袖T恤', '', '', ''), ('', '修身显瘦撞色边针织T恤 学院风中袖针织上衣', '', '', 'products/7.jpg', '', '修身显瘦撞色边针织T恤 学院风中袖针织上衣', '', '', ''), ('', '2017春夏新款织带针织小开衫短款', '', '', 'products/8.jpg', '', '2017春夏新款织带针织小开衫短款', '', '', ''), ('', '2017夏季新款女装破洞高腰牛仔短裤包边设计做旧牛仔裤', '', '', 'products/9.jpg', '', '2017夏季新款女装破洞高腰牛仔短裤包边设计做旧牛仔裤', '', '', ''), ('', '2017新款双线装饰半身裙 甜美学院风百搭百褶裙子', '', '', 'products/10.jpg', '', '2017新款双线装饰半身裙 甜美学院风百搭百褶裙子', '', '', ''), ('', '2017新款双线装饰半身裙 甜美学院风百搭百褶裙子', '', '', 'products/11.jpg', '', '2017新款双线装饰半身裙 甜美学院风百搭百褶裙子', '', '', ''), ('', '2017春夏装新款圆领中长款黑色宽松亮丝短袖t恤女打底衫上衣', '', '', 'products/12.jpg', '', '2017春夏装新款圆领中长款黑色宽松亮丝短袖t恤女打底衫上衣', '', '', ''), ('', '2017春夏新款韩版拼接网纱休闲百搭优雅短袖套头针织衫', '', '', 'products/13.jpg', '', '2017春夏新款韩版拼接网纱休闲百搭优雅短袖套头针织衫', '', '', ''), ('', '2017夏装新款韩版无袖民族风吊带连衣裙公主裙背心裙子女装', '', '', 'products/14.jpg', '', '2017夏装新款韩版无袖民族风吊带连衣裙公主裙背心裙子女装', '', '', ''), ('', '新款韩版宽松显瘦小清新可爱卡通印花七分袖poloT恤连衣裙子', '', '', 'products/15.jpg', '', '新款韩版宽松显瘦小清新可爱卡通印花七分袖poloT恤连衣裙子', '', '', ''), ('', '2017 时尚百搭蓝色高腰系带阔腿七分牛仔裤', '', '', 'products/16.jpg', '', '2017 时尚百搭蓝色高腰系带阔腿七分牛仔裤', '', '', ''), ('', '2017春季新款宽松显瘦带帽口袋中长款牛仔外套女上衣', '', '', 'products/17.jpg', '', '2017春季新款宽松显瘦带帽口袋中长款牛仔外套女上衣', '', '', ''), ('', '2017春夏新品韩版宽松短袖T恤', '', '', 'products/18.jpg', '', '2017春夏新品韩版宽松短袖T恤', '', '', ''), ('', '设计感流苏拉链破边蝙蝠袖卫衣外套', '', '', 'products/19.jpg', '', '设计感流苏拉链破边蝙蝠袖卫衣外套', '', '', ''), ('', '2017新款韩版翻边一刀切破洞高腰弹力修身牛仔长裤', '', '', 'products/20.jpg', '', '2017新款韩版翻边一刀切破洞高腰弹力修身牛仔长裤!', '', '', ''), ('', '新款气质韩版小清新毛毛露肩显瘦纯色仙款气质连衣裙子', '', '', 'products/21.jpg', '', '新款气质韩版小清新毛毛露肩显瘦纯色仙款气质连衣裙子', '', '', ''), ('', '2017春季新品韩版百搭休闲拼色夹克棒球服棒球衫', '', '', 'products/22.jpg', '', '2017春季新品韩版百搭休闲拼色夹克棒球服棒球衫', '', '', ''), ('', '2017新款破洞撕边百搭牛仔裤个性韩版九分牛仔乞丐裤', '', '', 'products/23.jpg', '', '2017新款破洞撕边百搭牛仔裤个性韩版九分牛仔乞丐裤', '', '', ''), ('', '春季新款韩版小樱桃小清新百搭蕾丝拼接喇叭袖复古雪纺衫衬衫上衣', '', '', 'products/24.jpg', '', '春季新款韩版小樱桃小清新百搭蕾丝拼接喇叭袖复古雪纺衫衬衫上衣', '', '', ''), ('', '2017春夏新款韩版休闲百搭宽松纯色口袋基础套头短袖T恤上衣', '', '', 'products/25.jpg', '', '2017春夏新款韩版休闲百搭宽松纯色口袋基础套头短袖T恤上衣', '', '', ''), ('', '1313 纯色刺绣T恤 休闲宽松百搭圆领短袖上衣', '', '', 'products/26.jpg', '', '1313 纯色刺绣T恤 休闲宽松百搭圆领短袖上衣', '', '', ''), ('', '2017 春季新款侧纽扣深蓝西装马夹背心', '', '', 'products/27.jpg', '', '2017 春季新款侧纽扣深蓝西装马夹背心', '', '', ''), ('', '新款韩版小清新小性感碎花印花蕾丝拼接宽松显瘦连衣裙两件套', '', '', 'products/28.jpg', '', '新款韩版小清新小性感碎花印花蕾丝拼接宽松显瘦连衣裙两件套', '', '', ''), ('', '复古大花朵碎花V领系带印花雪纺连衣裙短裙', '', '', 'products/29.jpg', '', '复古大花朵碎花V领系带印花雪纺连衣裙短裙', '', '', ''), ('', '2017新款原宿风宽松露肩镂空短袖T恤', '', '', 'products/30.jpg', '', '2017新款原宿风宽松露肩镂空短袖T恤', '', '', ''), ('', '【张予曦】星星雪纺衬衫连衣长裙收腰两件套女裙春A字碎花连衣裙', '', '', 'products/31.jpg', '', '【张予曦】星星雪纺衬衫连衣长裙收腰两件套女裙春A字碎花连衣裙', '', '', ''), ('', '2017早春新款 舒适干练腰带装饰西装裤休闲裤', '', '', 'products/32.jpg', '', '2017早春新款 舒适干练腰带装饰西装裤休闲裤', '', '', ''), ('', '2017夏季新款韩版高腰破洞毛边牛仔短裤', '', '', 'products/33.jpg', '', '2017夏季新款韩版高腰破洞毛边牛仔短裤', '', '', ''), ('', '2017春季新款牛仔裤女长裤子破洞潮显瘦小脚裤铅笔裤', '', '', 'products/34.jpg', '', '2017春季新款牛仔裤女长裤子破洞潮显瘦小脚裤铅笔裤', '', '', ''), ('', '2017新款春夏韩国淑女气质显瘦蝴蝶结衬衣', '', '', 'products/35.jpg', '', '2017新款春夏韩国淑女气质显瘦蝴蝶结衬衣', '', '', ''), ('', 'bf风个性拼接宽松毛边牛仔裤女韩国显瘦不规则直筒阔腿九分裤', '', '', 'products/36.jpg', '', 'bf风个性拼接宽松毛边牛仔裤女韩国显瘦不规则直筒阔腿九分裤', '', '', ''), ('', '【钱夫人同款】春季韩版t恤女短袖圆领学生宽松时尚打底衫上衣', '', '', 'products/37.jpg', '', '【钱夫人同款】春季韩版t恤女短袖圆领学生宽松时尚打底衫上衣', '', '', ''), ('', '2017春季新款运动裤女九分学生韩版宽松百搭显瘦原宿bf哈伦', '', '', 'products/38.jpg', '', '2017春季新款运动裤女九分学生韩版宽松百搭显瘦原宿bf哈伦', '', '', ''), ('', '2017春夏新款韩版优雅刺绣气质高腰显瘦半身裙包臀裙短裙裙子', '', '', 'products/39.jpg', '', '2017春夏新款韩版优雅刺绣气质高腰显瘦半身裙包臀裙短裙裙子', '', '', ''), ('', '韩版春季新款花朵刺绣学院风时尚百搭条纹七分袖衬衣', '', '', 'products/40.jpg', '', '韩版春季新款花朵刺绣学院风时尚百搭条纹七分袖衬衣', '', '', ''), ('', '2017春季新款时尚百搭韩版显瘦金属圆环镂空字母圆领长T恤', '', '', 'products/41.jpg', '', '2017春季新款时尚百搭韩版显瘦金属圆环镂空字母圆领长T恤', '', '', ''), ('', '短袖t恤女宽松上衣春装2017新款 韩版百搭半袖t恤', '', '', 'products/42.jpg', '', '短袖t恤女宽松上衣春装2017新款 韩版百搭半袖t恤', '', '', ''), ('', '兔先生亮片字母圆领做旧T恤', '', '', 'products/43.jpg', '', '兔先生亮片字母圆领做旧T恤', '', '', ''), ('', '2017夏季新款水溶钩花短袖网衫罩衫', '', '', 'products/44.jpg', '', '2017夏季新款水溶钩花短袖网衫罩衫', '', '', ''), ('', '春季新款韩版街头立领收腰抽褶显瘦帅气夹克风衣外套', '', '', 'products/45.jpg', '', '春季新款韩版街头立领收腰抽褶显瘦帅气夹克风衣外套', '', '', ''), ('', '2017春夏新款韩版拼接网纱休闲百搭优雅短袖套头针织衫', '', '', 'products/46.jpg', '', '2017春夏新款韩版拼接网纱休闲百搭优雅短袖套头针织衫', '', '', ''), ('', '2017新款春夏宽松休闲G字母印花T恤', '', '', 'products/47.jpg', '', '2017新款春夏宽松休闲G字母印花T恤', '', '', ''), ('', '小番茄定制 温柔静谧后背纽扣喇叭袖压皱雪纺衬衫 真丝皱两件套', '', '', 'products/48.jpg', '', '小番茄定制 温柔静谧后背纽扣喇叭袖压皱雪纺衬衫 真丝皱两件套', '', '', ''), ('', '2017早春欧美性感网纱透视花边半高领灯笼袖纯色长袖雪纺衫', '', '', 'products/49.jpg', '', '2017早春欧美性感网纱透视花边半高领灯笼袖纯色长袖雪纺衫', '', '', ''), ('', '2017 春夏新款露背百褶连衣裙', '', '', 'products/50.jpg', '', '2017 春夏新款露背百褶连衣裙', '', '', '');
COMMIT; -- ----------------------------
-- Table structure for `user`
-- ----------------------------
DROP TABLE IF EXISTS `user`;
CREATE TABLE `user` (
`uid` int(100) NOT NULL AUTO_INCREMENT,
`username` varchar(20) DEFAULT NULL,
`password` varchar(20) DEFAULT NULL,
`email` varchar(30) DEFAULT NULL,
`telephone` varchar(20) DEFAULT NULL,
`nickname` varchar(20) DEFAULT NULL,
PRIMARY KEY (`uid`)
) ENGINE=InnoDB AUTO_INCREMENT=5 DEFAULT CHARSET=utf8; SET FOREIGN_KEY_CHECKS = 1;

shop数据库

需要用到的jar包有jstl,standard,mysql-connetor-java-5.1.45-bin,servlet-api四个jar包。

前端用到的前端页面及图片:  https://files.cnblogs.com/files/Zs-book1/views.rar

src文件夹下,建5个包:dao,entity,util,servlet,filter;

util包中,我们写入jdbc工具类:

package com.zs.util;

import java.sql.*;
import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map; public class DBUtils {
static{
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
public static Connection getConnection() throws SQLException {
return DriverManager.getConnection("jdbc:mysql://localhost:3306/shop", "root", "123456");
}
public static boolean executeUpdate(String sql, Object... obj) {
Connection conn = null;
PreparedStatement ps = null;
try {
conn = getConnection();
ps = conn.prepareStatement(sql);
for (int i = 0; i < obj.length; i++) {
ps.setObject(i+1,obj[i]);
}
int i = ps.executeUpdate();
return i>0;
} catch (SQLException e) {
e.printStackTrace();
}finally {
close(conn, ps);
}
return false;
} private static void close(Connection conn, PreparedStatement ps) {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
e.printStackTrace();
}finally {
close(conn);
}
}
} private static void close(Connection conn) {
if (conn != null) {
try {
conn.close();
} catch (SQLException e) {
e.printStackTrace();
}
}
} public static List<Map<String, Object>> executeQuery(String sql,Object... args) {
List<Map<String, Object>> list = new ArrayList<>();
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
conn = getConnection();
ps = conn.prepareStatement(sql);
for (int i = 0; i < args.length; i++) {
ps.setObject(i+1,args[i]);
}
rs = ps.executeQuery();
while (rs.next()) {
Map<String, Object> map = new LinkedHashMap<>();
for (int i = 0; i < rs.getMetaData().getColumnCount(); i++) {
String name = rs.getMetaData().getColumnLabel(i + 1);
map.put(name, rs.getObject(name));
}
list.add(map);
}
return list;
} catch (SQLException e) {
e.printStackTrace();
}finally {
close(conn,ps,rs);
}
return null;
} private static void close(Connection conn, PreparedStatement ps, ResultSet rs) {
if (rs!= null) {
try {
rs.close();
} catch (SQLException e) {
e.printStackTrace();
}finally {
close(conn,ps);
}
}
}
}

我们将views文件夹复制进项目的web文件夹下,下面开始项目写项目的具体实现,首先我们打开前端页面,我们可以看出,下面的商品代码都是一样的,这些商品我们都是从数据库读出来,然后再显示再jsp页面,用jstl中的<c:foreach>来实现,因为我们也不知道业务实现都有什么,所以我们根据Servlet中业务需求来写dao层的内容;首先我们写Servlet

package com.zs.servlet;

import com.zs.dao.IProductDAO;
import com.zs.dao.impl.ProductDAOImpl; 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 java.io.IOException;
import java.util.List;
import java.util.Map; @WebServlet("/home")
public class ListProductsServet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 首先确认是否有数据传输过来;这里没有请求数据
// 调用dao层,获得所有的商品信息,这里我们进dao层写获得所有商品信息的放法;
ProductDAOImpl productDAO = new ProductDAOImpl();
List<Map<String, Object>> allProduct = productDAO.listProducts(); // 设置共享数据list
req.setAttribute("allProduct",allProduct);
// 请求返回
req.getRequestDispatcher("/views/index.jsp").forward(req, resp);
}
}

首页后台

<%@ 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+"/"+"views/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<link rel="icon" href="img/icon.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="css/base-aa24246264.css"/>
<link rel="stylesheet" type="text/css" href="css/welcome-fc9359d842.css"/>
<link rel="stylesheet" type="text/css" href="css/sidebar.css"/>
<link rel="stylesheet" type="text/css" href="css/content.css"/>
<title>贵美·商城</title> </head> <body>
<!-- 头部导航 -->
<jsp:include page="/views/header.jsp"></jsp:include> <!--搜索框-->
<div class="logo"></div>
<div id="com-search">
<div class="search"> <div class="search-tab">
<span class="active">宝贝</span><span class="">店铺</span> </div>
<div class="search-box">
<input class="search-txt" placeholder="" type="text">
<span class="search-btn"></span>
<div class="suggest-box" style="display: none;"></div>
</div>
<div class="hotword">
<a target="_blank" href="#" style="color:#FF3366">连衣裙</a>
<a target="_blank" href="#" style="color:#666666">运动鞋</a>
<a target="_blank" href="#" style="color:#FF3366">雪纺衫</a>
<a target="_blank" href="#" style="color:#FF3366">衬衫</a>
<a target="_blank" href="#" style="color:#666666">薄外套</a>
<a target="_blank" href="#" style="color:#666666">T恤</a>
<a target="_blank" href="#" style="color:#666666">套装</a>
<a target="_blank" href="#" style="color:#666666">牛仔裤</a>
<a target="_blank" href="#" style="color:#FF3366">小白鞋</a>
<a target="_blank" href="#" style="color:#666666">风衣</a>
<a target="_blank" href="#" style="color:#FF3366">绑带凉鞋</a>
<a target="_blank" href="#" style="color:#666666">粗跟单鞋</a>
</div>
</div>
</div> <!--导航 -->
<div id="nav">
<ul>
<li>
<a href="#" class="selected">首页</a>
</li>
<li>
<a href="#">上衣</a>
</li>
<li>
<a href="#">裙子</a>
</li>
<li>
<a href="#">裤子</a>
</li>
<li>
<a href="#">女鞋</a>
</li>
<li>
<a href="#">包包</a>
</li>
<li>
<a href="#">配饰</a>
</li>
<li>
<a href="#">美妆</a>
</li>
</ul>
</div>
<hr /> <!--广告轮播图-->
<div class="ad">
<div class="inner">
<img src="img/ad1.jpg"/>
<img src="img/ad2.jpg"/>
<img src="img/ad1.jpg"/>
</div>
</div> <!--商品展示-->
<h2>贵美优选</h2> <%--这里我们发现下面的商品不居中对齐,我们加个样式--%>
<div id="wrap" style="margin: 0 auto">
<c:forEach var="p" items="${allProduct}">
<!-- 商品信息 --> <div class="products">
<%--将下面的商品信息修改为读取到的信息--%>
<!--商品图片-->
<a href="/shop/product?pid=${p.pid}" class="pimg" style="background-image: url(${p.pimage});"></a>
<div class="info">
<div class="part">
<!--商品价格-->
<div class="price">¥${p.shopPrice}</div>
<div class="collect">
<!--商品收藏-->
<i class="icon-star"></i>${p.collect}
</div>
</div>
<i class="icon-select">
<!--商品简介-->
</i>${p.pname}
</div>
</div>
</c:forEach> </div> <!-- 底部导航 -->
<jsp:include page="/views/footer.jsp"></jsp:include> </body>
</body>
</html>

修改后的index界面

上面的图片有了, 我们就想,我们需要点击哪儿个图片就跳转到某一个页面的详情,打开一个新的页面,因此我们需要给Servlet传递选中的图片pid,因此我们再index页面中,给图片的a标签添加了路径,href="/shoplx/product?pid=${p.pid}"   这样就给Servlet传递了一个图片的id,根据这个id来查询数据库:

package com.zs.servlet;

import com.zs.dao.IProductDAO;
import com.zs.dao.impl.ProductDAOImpl; 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 java.io.IOException;
import java.util.Map; @WebServlet("/product")
public class ProductServelt extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
// 确认是否传递数据,如果有,获得数据
String pid = req.getParameter("pid"); // 根据id调用dao层查询该商品,这是业务需求,我们需要到dao曾写该方法;
IProductDAO productDAO = new ProductDAOImpl();
Map<String, Object> product = productDAO.getProductById(Integer.parseInt(pid)); // 判断该商品是否存在,如果不存在,则返回错误信息
if (product == null) {
req.setAttribute("error", "对不起,商品不存在");
} else {
req.setAttribute("product",product);
} // 请求转发
req.getRequestDispatcher("/views/product.jsp").forward(req, resp);
}
}

单个商品servelt

<%@ 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+"/"+"views/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>"> <meta charset="UTF-8">
<title>商品详情</title>
<link rel="stylesheet" type="text/css" href="css/product.css"/>
<script type="text/javascript" src="js/product.js"> </script> </head> <body>
<!-- 头部导航 -->
<jsp:include page="/views/header.jsp"></jsp:include> <div class="wrap">
<img src="${product.pimage}" />
<div class="description"> <form action="/shoplx/mycar" method="post">
<h2>${product.pname}</h2>
<div class="old_price">
原价:
<span>
¥${product.marketPrice}
</span>
</div>
<div class="price">
折扣价:
<span>
¥${product.shopPrice}
</span>
</div> <div>
尺码:均码
</div> <div class="count">
数量:
<span class="s">-</span>
<input type="text" value="1" name="num" class="num" />
<span class="s">+</span>
</div> <div>
<input type="submit" value="加入购物车" class="goods_cart" />
</div> <div>
<input type="submit" value="立即购买" class="buy"/>
</div>
</form>
</div> </div>
</body> </html>

修改后的product.jsp

这时我们发现,当我们在地址栏中id=后面数字修改时,就会变成相应的图片,那么当我们输入一个数据库中没有的id时,如100,那么就会报错,如果输入asdg时,服务器就会报错,出现错误代码,这不是用户希望看见的,因此上面的代码都需要修改,

package com.zs.servlet;

import com.zs.dao.IProductDAO;
import com.zs.dao.impl.ProductDAOImpl; 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 java.io.IOException;
import java.util.Map; @WebServlet("/product")
public class ProductServelt extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { try {
// 确认是否传递数据,如果有,获得数据
String pid = req.getParameter("pid"); // 根据id调用dao层查询该商品,这是业务需求,我们需要到dao曾写该方法;
IProductDAO productDAO = new ProductDAOImpl();
Map<String, Object> product = productDAO.getProductById(Integer.parseInt(pid)); // 判断该商品是否存在,如果不存在,则返回错误信息
if (product == null) {
req.setAttribute("error", "对不起,商品不存在");
} else {
req.setAttribute("product", product);
} // 请求转发
req.getRequestDispatcher("/views/product.jsp").forward(req, resp);
} catch (Exception e) {
System.out.println("程序出错");
// 程序出错时,就返回主界面
resp.sendRedirect("/shoplx/home");
} }
}

修改后的ProductServlet

<%@ 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+"/"+"views/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>"> <meta charset="UTF-8">
<title>商品详情</title>
<link rel="stylesheet" type="text/css" href="css/product.css"/>
<script type="text/javascript" src="js/product.js"></script>
<script>
if (${empty success}) {
if (confirm("添加成功,是否前往购物车")) {
window.location.href = "/shoplx/mycar";
}
} </script>
</head> <body>
<!-- 头部导航 -->
<jsp:include page="/views/header.jsp"></jsp:include> <div class="wrap">
<c:choose>
<c:when test="${empty product}">
对不起,该商品不存在!!!
</c:when>
<c:otherwise>
<img src="${product.pimage}" />
<div class="description"> <form action="/shoplx/addcar" method="post">
<input type="hidden" name="pid" value="${product.pid}">
<input type="hidden" name="pid" value="${product.pid}">
<h2>${product.pname}</h2>
<div class="old_price">
原价:
<span>
¥${product.marketPrice}
</span>
</div>
<div class="price">
折扣价:
<span>
¥${product.shopPrice}
</span>
</div> <div>
尺码:均码
</div> <div class="count">
数量:
<span class="s">-</span>
<input type="text" value="1" name="num" class="num" />
<span class="s">+</span>
</div> <div>
<input type="submit" value="加入购物车" class="goods_cart" />
</div> <div>
<input type="submit" value="立即购买" class="buy"/>
</div>
</form>
</div>
</c:otherwise>
</c:choose> </div>
</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+"/"+"views/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>"> <meta charset="UTF-8">
<title>商品详情</title>
<link rel="stylesheet" type="text/css" href="css/product.css"/>
<script type="text/javascript" src="js/product.js"></script>
<script>
if (${not empty success}) {
if (confirm("添加成功,是否前往购物车")) {
window.location.href = "/shoplx/mycar";
}
} </script>
</head> <body>
<!-- 头部导航 -->
<jsp:include page="/views/header.jsp"></jsp:include> <div class="wrap">
<c:choose>
<c:when test="${not empty error}">
对不起,该商品不存在!!!
</c:when>
<c:otherwise>
<img src="${product.pimage}" />
<div class="description"> <form action="/shoplx/addcar" method="post">
<input type="hidden" name="pid" value="${product.pid}">
<input type="hidden" name="pid" value="${product.pid}">
<h2>${product.pname}</h2>
<div class="old_price">
原价:
<span>
¥${product.marketPrice}
</span>
</div>
<div class="price">
折扣价:
<span>
¥${product.shopPrice}
</span>
</div> <div>
尺码:均码
</div> <div class="count">
数量:
<span class="s">-</span>
<input type="text" value="1" name="num" class="num" />
<span class="s">+</span>
</div> <div>
<input type="submit" value="加入购物车" class="goods_cart" />
</div> <div>
<input type="submit" value="立即购买" class="buy"/>
</div>
</form>
</div>
</c:otherwise>
</c:choose> </div>
</body> </html>

product.jsp

然后我们接下来就继续往下写加入购物车的代码;
/**
* 在写代码之前我们首先要想,我们要想加入购物车,首先我们需要知道,用户是否已经登录,如果已经登录,那么就获取这个用户的uid
* 然后将商品的信息添加进改用户的购物车中,如果该用户没有登陆,那么我们要把商品信息添加到哪儿呢,很明显,没有登陆是不能添加的,因此我们
* 需要 在添加商品之前,判断用户是否登录,如果没有登陆,那么就跳转到登陆页面.
* 这时就会遇到下一个问题,就是我们登陆肯定是要获得登陆信息,然后将用户信息传递到后台进行判断,是否登陆成功,然后将用户的信息,
* 设置为共享数据,之前我们用的req.setAttribute()方法,设置的共享数据,只对当前请求有效,我们再之后的购物车中,需要频繁用到用户的信息,
* 所以我们就用到了回话,session
* session设置的共享数据只要浏览器不关闭,就一直可以使用*/
从上面我们可以知道,我们需要先写登陆的后台,这样才能获得登陆的用户信息,才能继续写登陆成功后加入购物车的代码;而要写登陆的代码,就要先写注册的后台,注册后才能登陆
package com.zs.entity;

public class User {
private int uid;
private String username;
private String password;
private String telephone;
private String email;
private String nickname; public User() { } public User(int uid, String username, String password, String telephone, String email, String nickname) {
this.uid = uid;
this.username = username;
this.password = password;
this.telephone = telephone;
this.email = email;
this.nickname = nickname;
} public int getUid() {
return uid;
} public void setUid(int uid) {
this.uid = uid;
} public String getUsername() {
return username;
} public void setUsername(String username) {
this.username = username;
} public String getPassword() {
return password;
} public void setPassword(String password) {
this.password = password;
} public String getTelephone() {
return telephone;
} public void setTelephone(String telephone) {
this.telephone = telephone;
} public String getEmail() {
return email;
} public void setEmail(String email) {
this.email = email;
} public String getNickname() {
return nickname;
} public void setNickname(String nickname) {
this.nickname = nickname;
} @Override
public String toString() {
return "User{" +
"uid=" + uid +
", username='" + username + '\'' +
", password='" + password + '\'' +
", telephone='" + telephone + '\'' +
", email='" + email + '\'' +
", nickname='" + nickname + '\'' +
'}';
}
}

User实体类

package com.zs.servlet;

import com.zs.dao.IUserDAO;
import com.zs.dao.impl.UserDAOImpl;
import com.zs.entity.User; 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 java.io.IOException; @WebServlet("/register")
public class RegisterServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
// 获取请求数据
String username = req.getParameter("username");
String password = req.getParameter("password");
String telephone = req.getParameter("telephone");
String email = req.getParameter("email");
String nickname = req.getParameter("nickname"); //我们首先要与数据库比较,看username是否已经呗占用,如果被占用,则返回错误信息,否则,添加用户
//调用dao层,查询用户名是否存在,到dao层添加搜索用户名方法
IUserDAO userDAO = new UserDAOImpl(); if (userDAO.getUserByName(username)) {
req.setAttribute("error", "对不起,用户名已经存在");
} else {
// 创建user实例化对象
User user = new User(1, username, password, telephone, email, nickname); // 然后调用dao层,数据库添加用户,到dao层写添加用户的方法
userDAO.insertUser(user); req.setAttribute("success", "注册成功");
}
req.getRequestDispatcher("/views/register.jsp").forward(req, resp);
}
}

RegisterServlet

<%@ 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+"/"+"views/";
%> <!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>注册 - 贵美·商城</title>
<base href="<%=basePath%>">
<link rel="icon" href="img/icon.png" type="image/x-icon">
<link rel="stylesheet" type="text/css" href="css/register.css"/>
<script>
if (${not empty success}) {
if (confirm("注册成功,是否前往登录界面")) {
window.location.href="/shoplx/views/login.jsp";
}
}
</script>
</head>
<body> <div class="wrap">
<div class="guimeilogo"></div>
<div class="register"> <div class="top">
<h1>新用户注册</h1>
<a href="/shop/views/login.jsp">已有账号</a>
</div> ${error}
<div class="mid">
<form action="/shoplx/register" method="post"> <input type="text" name="telephone" id="telephone" placeholder="手机号" required="required"/> <div class="sec"> <input type="text" name="code" id="code" placeholder="验证码" required="required" /> <a class="send" onclick="send()"> 发送验证码 </a> <script>
function send(){ return false;
}
</script>
</div> <input type="password" name="password" id="password" placeholder="密码" required="required" /> <input type="password" name="reppw" id="reppw" placeholder="重复密码" required="required" /> <input type="text" name="username" id="username" placeholder="请输入用户名" required="required" /> <input type="text" name="email" id="email" placeholder="亲,您的邮箱" required="required" /> <input type="text" name="nickname" id="nickname" placeholder="亲,您的昵称" required="required" /> <input type="submit" id="submit" value="注册"/> </form>
</div>
</div>
</div>
</body>
</html>

修改后register.jsp

package com.zs.servlet;

import com.zs.dao.IUserDAO;
import com.zs.dao.impl.UserDAOImpl; 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 javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.Map; @WebServlet("/login")
public class LoginServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("utf-8");
// 获得请求数据
String username = req.getParameter("username");
String password = req.getParameter("password"); // 调用dao层验证用户名,密码
IUserDAO userDAO = new UserDAOImpl();
Map<String, Object> user = userDAO.login(username, password); if (user == null) {
req.setAttribute("error", "用户名或密码错误");
req.getRequestDispatcher("/views/login.jsp").forward(req, resp);
} else {
//因为我们再后面的业务中会经常用到user因此我们需要将user的信息共享到会话中,而且我们登陆成功,需要重定向到home页面
//地址栏发生变化,重定向不能传数据,因此用session
req.getSession().setAttribute("user", user);
// 登陆成功,重定向到home页面
resp.sendRedirect("/shoplx/home");
}
}
}

LoginServlet

<%@ 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+"/"+"views/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML >
<html>
<head>
<base href="<%=basePath%>"> <title>登录 - 贵美·商城</title>
<link rel="stylesheet" type="text/css" href="css/login.css"/>
</head>
<body> <div class="wrap">
<div class="guimeilogo"></div> <div class="login"> <div class="top">
<h1>贵美商城</h1>
<a href="/shoplx/views/register.jsp">新用户注册</a>
</div> <div class="mid">
<form action="/shoplx/login" method="post">
<input type="text" name="username" id="username" placeholder="用户名" required="required" />
${error}
<input type="password" name="password" id="password" placeholder="密码" required="required" />
<input type="submit" id="submit" value="立即登录"/>
</form>
</div> </div> </div>
</body>
</html>

修改后的login.jsp

然后我们让你发现,我们登录成功以后,注册和登录按钮应该没有的,因此需要修改header.sjp:

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ 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+"/"+"views/";
%> <link rel="stylesheet" type="text/css" href="css/header.css"/>
<!--头部--> <div class="header_wrap">
<ul>
<c:choose>
<c:when test="${empty user}">
<li><a href="/shoplx/views/login.jsp">登录</a></li>
<li><a href="/shoplx/views/register.jsp">注册</a></li>
</c:when>
<c:otherwise>
欢迎 <a href="">${user.nickname}</a>
</c:otherwise>
</c:choose> <li><a href="#">我的收藏</a></li>
<li><a href="/shoplx/mycar">我的购物车</a></li>
<li><a href="#">我的订单</a></li>
<li><a href="#">帮助中心</a></li>
<li><a href="#">商家后台</a></li> </ul>
</div>

header.jsp

接下来我们写加入购物车的Servlet;

package com.zs.servlet;

import com.zs.dao.ICarDAO;
import com.zs.dao.impl.CarDAOImpl;
import com.zs.entity.User; 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 java.io.IOException;
import java.util.Map; @WebServlet("/addcar")
public class AddCartServlet extends HttpServlet { @Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//首先获得登录信息,判断是否登录
Map user = (Map) req.getSession().getAttribute("user");
if (user != null) {
//获得用户id
Integer uid = (Integer) user.get("uid");
// 获得商品编号
Integer pid = Integer.parseInt(req.getParameter("pid"));
int num = Integer.parseInt(req.getParameter("num"));
// 将商品添加进购物车表中,首先我们要判断购物车是否有该商品,如果有,则将商品的数量加1,否则添加该商品
ICarDAO carDAO = new CarDAOImpl();
boolean b = carDAO.getProductById(uid, pid);
if (b) {
carDAO.update(uid, pid, num);
} else {
carDAO.insertProduct(uid, pid, num);
}
req.setAttribute("success","成功");
req.getRequestDispatcher("/product").forward(req, resp); } else {
resp.sendRedirect("/shoplx/views/login.jsp");
} }
}

AddCarServlet

<%@ 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+"/"+"views/";
%>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> <!DOCTYPE HTML>
<html>
<head>
<base href="<%=basePath%>">
<link rel="icon" href="img/icon.png" type="image/x-icon">
<link rel="stylesheet" href="css/goodscart.css" />
<script type="text/javascript" src="js/product.js"></script> <title>购物车 贵美·商城</title> </head>
<body>
<!-- 头部导航 -->
<jsp:include page="/views/header.jsp"></jsp:include> <!-- 購物車 -->
<div class="wrap">
<div class="title">
<ul>
<li><input type="checkbox" name="" id="" value="" /> 全选</li>
<li>商品</li>
<li>商品信息</li>
<li>单价(元)</li>
<li>数量</li>
<li>小计(元)</li>
<li>操作</li>
</ul>
</div>
<c:forEach var="p" items="${Carts}">
<div class="goods">
<ul>
<li><img src="${p.pimage}"/> ${p.pname}</li>
<li>尺碼:均碼</li>
<li class="price">${p.shopPrice}</li>
<li>
<div class="count"> <span class="s">-</span>
<input type="text" value="${p.num}" name="num" class="num" />
<span class="s">+</span>
</div> </li>
<li class="subtotal">76</li>
<li>
<a href="#">刪除</a>
</li>
</ul>
</div>
</c:forEach> <div class="foot">
<ul>
<li><a href="#">全部刪除</a></li>
<li>總價:¥<span style="color: red; font-size: 30px; font-weight: 600;" id="total">11111</span></li>
<li><a href="#">去付款</a></li> </ul>
</div> </div> </body>
</html>

购物车

package com.zs.servlet;

import com.zs.dao.ICarDAO;
import com.zs.dao.impl.CarDAOImpl; 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 java.io.IOException;
import java.util.List;
import java.util.Map; @WebServlet("/mycar")
public class MyCarServlet extends HttpServlet {
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
Map user = (Map) req.getSession().getAttribute("user");
Integer uid = (Integer) user.get("uid");
ICarDAO carDAO = new CarDAOImpl();
List<Map<String, Object>> list = carDAO.listProducts(uid);
req.setAttribute("Carts",list);
req.getRequestDispatcher("/views/goodscart.jsp").forward(req, resp);
}
}

购物车Servlet

需要用到的dao层:

javaEE练习(商城练习)的更多相关文章

  1. JAVAEE网上商城项目总结

    发送邮件实现(使用QQ邮箱发送到指定邮箱) 需要的jar 邮件发送类代码: package util; import java.util.Properties; import javax.mail.A ...

  2. JAVAEE——宜立方商城01:电商行业的背景、商城系统架构、后台工程搭建、SSM框架整合

    1. 学习计划 第一天: 1.电商行业的背景. 2.宜立方商城的系统架构 a) 功能介绍 b) 架构讲解 3.工程搭建-后台工程 a) 使用maven搭建工程 b) 使用maven的tomcat插件启 ...

  3. JAVAEE——淘淘商城第一天:电商行业的背景和技术特点,商城的介绍、技术的选型、系统架构和工程搭建

    1. 学习计划 1.电商行业的背景. 2.电商行业的技术特点 3.商城的介绍 a) 常用的名词介绍 b) 系统功能介绍 4.淘淘商城的系统架构 a) 传统架构 b) 分布式架构 c) 基于服务的架构 ...

  4. JAVAEE——宜立方商城05:前台系统搭建、首页展示、Cms系统的实现

    1. 学习计划 1.前台系统搭建 2.商城首页展示 3.Cms系统的实现 a) 内容分类管理 b) 内容管理 4.前台内容动态展示 2. 商城首页展示 系统架构: 页面位置: 2.1. 工程搭建 可以 ...

  5. JAVAEE——宜立方商城02:服务中间件dubbo、工程改造为基于soa架构、商品列表实现

    1. 学习计划 第二天:商品列表功能实现 1.服务中间件dubbo 2.工程改造为基于soa架构 3.商品列表查询功能实现. 2. 将工程改造为SOA架构 2.1. 分析 由于宜立方商城是基于soa的 ...

  6. JAVAEE——宜立方商城14:项目部署规划、Tomcat热部署、反向代理的配置

    1. 学习计划 1.系统部署 2. 项目部署 2.1. 项目架构讲解 2.2. 网络拓扑图 2.3. 系统部署 2.3.1. 部署分析 e3-manager e3-manager-web e3-por ...

  7. JAVAEE——宜立方商城13:Mycat数据库分片、主从复制、读写分离、100%Linux中成功安装Mysql的方法

    1 海量数据的存储问题 如今随着互联网的发展,数据的量级也是撑指数的增长,从GB到TB到PB.对数据的各种操作也是愈加的困难,传统的关系性数据库已经无法满足快速查询与插入数据的需求.这个时候NoSQL ...

  8. JAVAEE——宜立方商城13:订单系统实现、订单生成、Mycat数据库分片

    1. 学习计划 1.订单系统实现 2.订单生成 3.Mycat数据库分片 2. 订单系统 2.1. 功能分析 1.在购物车页面点击“去结算”按钮,跳转到订单确认页面 a) 必须要求用户登录 b) 使用 ...

  9. JAVAEE——宜立方商城12:购物车实现、订单确认页面展示

    1. 学习计划 第十二天: 1.购物车实现 2.订单确认页面展示 2. 购物车的实现 2.1. 功能分析 1.购物车是一个独立的表现层工程. 2.添加购物车不要求登录.可以指定购买商品的数量. 3.展 ...

随机推荐

  1. HDOJ-2011

    #include<iostream> #include<cstdio> using namespace std; int main(){ int m,n,i; float su ...

  2. mui底部选项卡切换实现

    MUI提供了两种webview和div模式,来实现底部选项卡切换 效果相同,div是在同一个页面实现所有切换块的页面,根据id导航,而webview是由多个页面组成,形成页面之间的来回跳转

  3. php 类名和方法名相同(构造函数)

    //php 5.6class father{ public function __construct() { echo __METHOD__; }} class son extends father{ ...

  4. POST调用WCF方法-项目实践

    做即时通信项目时,需要与OA系统对接接口,主要目标是实现在OA里进行一项事项,通过调用我们的接口,即时通知过来,并弹出消息框提示一下.我们的即时通信使用的WCF服务进行通信,在客户端调用通信时,用的就 ...

  5. 初识ldap

    什么是LDAP? LDAP的英文全称是Lightweight Directory Access Protocol,一般都简称为LDAP.它是基于X.500标准的, 但是简单多了并且可以根据需要定制.与 ...

  6. OO的奇妙冒险——OOP入门与字符串处理

    OO的奇妙冒险 ~OOP入门与字符串处理~ 总体分析 公测 中测(基础与进阶): 其实在我看来,从完成作业的角度来说,中测的基础与进阶并没有任何区别,都不能挂,都不太难,都对得分没有什么影响.中测的样 ...

  7. EXCE 表格导入导出遇到问题(easypoi)

    使用Easypoi进行excel表格的导入导出遇到的问题: 1.导出时候打开文件一直遇乱码,主要的原因就是我在实体类没有进行给每个字段进行注解,就会导致每个字段找不到对应的汉字表头,所以一定不要忘了导 ...

  8. js 获取二级域名

    js获取页面完整地址: window.location.href; var s =" https://ejym.baidu.com";            var h = s.s ...

  9. 在Linux服务器非root权限下搭建TensorFlow框架(Anaconda)

    今天终于动手折腾实验室的服务器啦!由于权限原因,只能在自己的路径下安装TensorFlow. 1. 下载安装Anaconda 官网下载地址:https://www.anaconda.com/downl ...

  10. request.getParameter()在get和post方法中文乱码问题

    乱码原因:Http请求传输时将url以ISO-8859-1编码,服务器收到字节流后默认会以ISO-8859-1编码来解码成字符流(造成中文乱码) post请求: 假设提交请求的jsp页面是UTF-8编 ...