package servlet;
import entiy.TUser;
import entiy.User;
import org.apache.commons.beanutils.BeanUtils;
import service.TUserService;
import service.imp.TUserServiceImp;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.List;
import java.util.Map;
@WebServlet("/UserServlet")
public class UserServlet extends BaseServlet {
TUserService ts = new TUserServiceImp();
/**
* 处理登录
*
* @param request
* @param response
*/
public void login(HttpServletRequest request, HttpServletResponse response) throws Exception {
//获取用户登录输入的信息
Map<String, String[]> map = request.getParameterMap();
//调用service
TUser tUser = new TUser();
BeanUtils.populate(tUser, map);
// System.out.println(tUser);
TUser user = ts.login(tUser);
if (user == null) {
response.getWriter().println(0);
}
//判断是否有这个用户
//普通用户
else if (tUser.getUserPwd().equals(user.getUserPwd())&& "Y".equals(user.getUserStatus())&&user.getUserRole().equals("A")) {
//存储当前用户对象
request.getSession().setAttribute("user", user);
response.getWriter().println(1);
} else if(!user.getUserStatus().equals("Y")){
response.getWriter().println(2);
} else if(tUser.getUserPwd().equals(user.getUserPwd())&&"U".equals(user.getUserRole())){
request.getSession().setAttribute("user", user);
response.getWriter().println(3);
}else {
response.getWriter().println(0);
}
}
/**
* 处理注册
*/
public void register(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, IOException {
//获取用户登录输入的信息
Map<String, String[]> map = request.getParameterMap();
//参数对象化封装
TUser tUser = new TUser();
BeanUtils.populate(tUser, map);
// System.out.println(tUser);
//检验usertel是否被占用
TUser login = ts.login(tUser);
if (login != null && tUser.getUserTel().equals(login.getUserTel())) {
//手机号码被占用
response.getWriter().println(0);
} else {
//执行注册
ts.register(tUser);
//自动登录
request.getSession().setAttribute("user", ts.login(tUser));
//信号
response.getWriter().println(1);
}
}
/**
* 退出用户
*/
public void out(HttpServletRequest request, HttpServletResponse response) throws IOException {
request.getSession().removeAttribute("user");
response.sendRedirect("main.jsp");
}
/**
* 修改用户的姓名/性别
*/
public void updateUserNameandUserSex(HttpServletRequest request, HttpServletResponse response) throws InvocationTargetException, IllegalAccessException, IOException {
//获取用户登录输入的信息
Map<String, String[]> map = request.getParameterMap();
//参数对象化封装
TUser tUser = new TUser();
BeanUtils.populate(tUser, map);
// System.out.println(tUser);
//获取id
tUser.setUserId(((TUser) request.getSession().getAttribute("user")).getUserId());
//获取tel
tUser.setUserTel(((TUser) request.getSession().getAttribute("user")).getUserTel());
int i = ts.updateUserNameandSex(tUser);
// System.out.println(i);
if (i == 0) {
response.getWriter().println(0);
} else {
request.getSession().setAttribute("user", tUser);
response.getWriter().println(1);
}
}
/**
* 密码校验
*/
public void updateUserPassword(HttpServletRequest request, HttpServletResponse response) throws IOException {
String oldpassword = request.getParameter("oldpassword");
String newpassword = request.getParameter("newpassword");
String code = request.getParameter("code");
System.out.println(oldpassword);
TUser tUser = (TUser) request.getSession().getAttribute("user");
System.out.println(tUser);
// 判断验证码
if (!request.getSession().getAttribute("code").equals(code)) {
response.getWriter().println(0);
//判断旧密码是否存在
} else if (!oldpassword.equals(tUser.getUserPwd())) {
response.getWriter().println(1);
} else {
//调用service层执行修改密码
TUser user = (TUser) request.getSession().getAttribute("user");
tUser.setUserPwd(newpassword);
System.out.println(tUser);
ts.updateUserPassword(tUser);
request.getSession().setAttribute("user", tUser);
//清理session
request.getSession().removeAttribute("user");
//提示修改成功信号
response.getWriter().println(2);
}
}
/**
* 用户管理分页和多条件查询
*/
public void selectAll(HttpServletRequest request, HttpServletResponse response) throws IOException, InvocationTargetException, IllegalAccessException, ServletException {
//默认页码号
int nowPage = 1;
//如果有分页请求
if (request.getParameter("nowPage") != null) {
nowPage = Integer.parseInt(request.getParameter("nowPage"));
}
//搜索条件
Map<String, String[]> map = request.getParameterMap();
//参数对象化封装
User u = new User();
BeanUtils.populate(u, map);
//每页的数据量
int pageSize = 3;
//获取所有
List<User> users = ts.All(u, 0, 0);
//总数据量
int total = users.size();
//需要的页码
int pages = total % pageSize == 0 ? total / pageSize : total / pageSize + 1;
//当前页码展示的数据
users = ts.All(u, nowPage, pageSize);
//搜索的条件
request.setAttribute("u", u);
//当前页码号
request.setAttribute("nowPage", nowPage);
//总页码
request.setAttribute("pages", pages);
//当前页码需要展示数据
request.setAttribute("users", users);
request.getRequestDispatcher("user_list.jsp").forward(request, response);
}
/**
* 修改用户状态
*/
public void updateUserStatus(HttpServletRequest request, HttpServletResponse response) throws IOException, InvocationTargetException, IllegalAccessException {
String id = request.getParameter("id");
String type = request.getParameter("type");
if ("Y".equals(type)) {
type = "N";
int i = ts.updateUserStatus(type, id);
response.getWriter().println(1);
}else {
type = "Y";
int i = ts.updateUserStatus(type, id);
response.getWriter().println(1);
}
}
}
没有合适的资源?快使用搜索试试~ 我知道了~
温馨提示
在当今信息化社会的深度演进中,电子商务以其无与伦比的便利性和高效性,正在全球范围内引发一场商业模式和消费习惯的深刻变革。由于信息技术的迅猛发展和全球互联网的普及已经深深地重塑了人们的生活方式与商业模式。电子商务作为一种新型的商业模式,借助于互联网的广阔平台,突破了传统零售业在时空上的限制,极大地拓宽了交易的可能性,实现了消费者、商家乃至整个产业链条的价值共创。 随着移动互联网技术的日新月异,智能手机、平板电脑等移动设备成为人们日常生活中不可或缺的一部分,移动支付、社交媒体购物、直播带货等新型消费模式逐渐兴起,进一步推动了在线购物市场的繁荣与发展。据统计数据显示,全球电子商务市场规模逐年攀升,用户数量持续增长,这无疑为在线商城的发展提供了深厚且广阔的市场土壤。 与此同时,大数据、云计算、人工智能等前沿科技力量正在赋予在线商城前所未有的活力与可能。基于大数据分析的个性化推荐系统能够精准地洞察用户需求,提供定制化的商品信息和服务体验;云计算技术则保证了商城后台数据处理能力和系统的稳定运行;人工智能的应用,如智能客服、智能搜索等功能,则提升了服务效率,优化了用户体验。
资源推荐
资源详情
资源评论
收起资源包目录
基于servlet+jsp的在线商城.zip (844个子文件)
OderServlet.class 6KB
OderServlet.class 6KB
OderServlet.class 6KB
UserServlet.class 5KB
UserServlet.class 5KB
UserServlet.class 5KB
CategoryServlet.class 4KB
CategoryServlet.class 4KB
CategoryServlet.class 4KB
ProductServlet.class 4KB
ProductServlet.class 4KB
ProductServlet.class 4KB
AddressServlet.class 4KB
AddressServlet.class 4KB
AddressServlet.class 4KB
TUserDaoImp.class 4KB
TUserDaoImp.class 4KB
TUserDaoImp.class 4KB
Order.class 4KB
Order.class 4KB
Order.class 4KB
ProductDaoImp.class 4KB
ProductDaoImp.class 4KB
ProductDaoImp.class 4KB
OrderDaoImpl.class 4KB
OrderDaoImpl.class 4KB
OrderDaoImpl.class 4KB
User.class 3KB
User.class 3KB
User.class 3KB
CartServlet.class 3KB
CartServlet.class 3KB
CartServlet.class 3KB
TAddressDaoImp.class 3KB
TAddressDaoImp.class 3KB
TAddressDaoImp.class 3KB
CodeImgUtil.class 3KB
CodeImgUtil.class 3KB
CodeImgUtil.class 3KB
CartDaoImpl.class 3KB
CartDaoImpl.class 3KB
CartDaoImpl.class 3KB
UploadServlet.class 3KB
UploadServlet.class 3KB
UploadServlet.class 3KB
MenuServlet.class 3KB
MenuServlet.class 3KB
MenuServlet.class 3KB
TCategoryDaoImp.class 3KB
OrderDetailsServiceImp.class 3KB
TCategoryDaoImp.class 3KB
OrderDetailsServiceImp.class 3KB
TCategoryDaoImp.class 3KB
OrderDetailsServiceImp.class 3KB
Product.class 3KB
Product.class 3KB
Product.class 3KB
TUser.class 2KB
TUser.class 2KB
TUser.class 2KB
OrderDetails.class 2KB
OrderDetails.class 2KB
OrderDetails.class 2KB
OrderDetailsDaoImp.class 2KB
OrderDetailsDaoImp.class 2KB
OrderDetailsDaoImp.class 2KB
TAddress.class 2KB
TAddress.class 2KB
TAddress.class 2KB
CodeImgServlet.class 2KB
CodeImgServlet.class 2KB
CodeImgServlet.class 2KB
BaseServlet.class 2KB
BaseServlet.class 2KB
BaseServlet.class 2KB
DataSourceUtil.class 2KB
DataSourceUtil.class 2KB
DataSourceUtil.class 2KB
OrderDetailsDaoImp$1.class 2KB
OrderDetailsDaoImp$1.class 2KB
OrderDetailsDaoImp$1.class 2KB
Cart.class 2KB
Cart.class 2KB
Cart.class 2KB
TUserServiceImp.class 1KB
TUserServiceImp.class 1KB
TUserServiceImp.class 1KB
OrderDaoImpl$1.class 1KB
OrderDaoImpl$1.class 1KB
OrderDaoImpl$1.class 1KB
TAddressServiceImp.class 1KB
TAddressServiceImp.class 1KB
TAddressServiceImp.class 1KB
TOrderDetails.class 1KB
TOrderDetails.class 1KB
TOrderDetails.class 1KB
CartServiceImpl.class 1KB
CartServiceImpl.class 1KB
CartServiceImpl.class 1KB
CartProduct.class 1KB
共 844 条
- 1
- 2
- 3
- 4
- 5
- 6
- 9
资源评论
枫.
- 粉丝: 39
- 资源: 6
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功