⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 indexaction.java

📁 &#61553 网站前台 商品销售排行
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package mrgf.action;

import java.util.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import mrgf.form.*;
import mrgf.other.*;
import mrgf.hibernate.*;

public class IndexAction extends Action {
    public ActionForward execute(ActionMapping mapping, ActionForm form,
                                 HttpServletRequest request,
                                 HttpServletResponse response) {
        IndexForm indexForm = (IndexForm) form;
        String p = mapping.getParameter();
        String forward = "";
        //站头超连接
        if (p.equals("index")) {
            forward = "index";
        }
        if (p.equals("taxis")) {
            forward = "taxis";
        }
        //新品
        if (p.equals("new_merchandise")) {
            HttpSession session = request.getSession();
            List fatherSorts = (List) session.getAttribute("fatherSorts");
            MerchandiseSort fatherSort = (MerchandiseSort) fatherSorts.get(0);
            Iterator it = fatherSort.getSonSorts().iterator();
            MerchandiseSort sonSort = (MerchandiseSort) it.next();
            String hql = "from MerchandiseInfo where type='n'";
            Hibernate hn = new Hibernate();
            List merchandises = hn.query(hql);
            request.setAttribute("merchandises", merchandises);
            forward = "new_merchandise";
        }
        //特价品
        if (p.equals("special_offer")) {
            HttpSession session = request.getSession();
            List fatherSorts = (List) session.getAttribute("fatherSorts");
            MerchandiseSort fatherSort = (MerchandiseSort) fatherSorts.get(0);
            Iterator it = fatherSort.getSonSorts().iterator();
            MerchandiseSort sonSort = (MerchandiseSort) it.next();
            String hql = "from MerchandiseInfo where type='t'";
            Hibernate hn = new Hibernate();
            List merchandises = hn.query(hql);
            request.setAttribute("merchandises", merchandises);
            forward = "special_offer";
        }
        //查看定单信息
        if (p.equals("see_order_for_goods")) {
            HttpSession session = request.getSession();
            String username = (String) session.getAttribute("username");
            if (username == null) {
                request.setAttribute("clueOn", "请登录后再执行此操作,谢谢!!!");
                forward = "clue_on";
            } else {
                String hql = "from OrderInfo where username='" + username +
                             "' order by id desc";
                Hibernate hn = new Hibernate();
                List orders = (List) hn.query(hql);
                request.setAttribute("orders", orders);
                forward = "see_order_for_goods";
            }
        }
        //搜索定单
        if (p.equals("search_order_for_goods")) {
            HttpSession session = request.getSession();
            String username = (String) session.getAttribute("username");
            String hql = "from OrderInfo where username='" + username + "'";
            String orderId = indexForm.getOrderId();
            if (orderId.length() == 14) { // 依据订单编号搜索
                hql = hql + " and id='" + orderId + "'";
            } else { // 依据其他两项搜索
                String day = indexForm.getDay();
                if (day.length() > 0) { // 在输入日的情况下依据日期搜索
                    String year = indexForm.getYear();
                    String month = indexForm.getMonth();
                    Calendar now = Calendar.getInstance();
                    if (year.length() < 4) { // 判断用户是否输入年
                        year = now.get(Calendar.YEAR) + "";
                    }
                    if (month.length() == 0) { // 判断用户是否输入月
                        month = (now.get(Calendar.MONTH) + 1) + "";
                    }
                    String date = year + "-" + month + "-" + day;
                    hql = hql + " and dates='" + date + "'";
                }
                String consignment = indexForm.getConsignment();
                if (consignment.length() > 0) { // 依据发货情况搜索
                    hql = hql + " and consignment='" + consignment + "'";
                }
            }
            hql = hql + " order by id";
            Hibernate hn = new Hibernate();
            List orders = hn.query(hql);
            request.setAttribute("orders", orders);
            forward = "see_order_for_goods";
        }
        //查看定单信息
        if (p.equals("see_order_info")) {
            String orderId = (String) request.getParameter("orderId");
            String hql = "from OrderInfo where id='" + orderId + "'";
            Hibernate hn = new Hibernate();
            OrderInfo order = (OrderInfo) hn.queryOne(hql);
            request.setAttribute("order", order);
            forward = "see_order_info";
        }
        //查看购物车
        if (p.equals("shopping_cart")) {
            HttpSession session = request.getSession();
            String username = (String) session.getAttribute("username");
            if (username == null) {
                request.setAttribute("clueOn", "请登录后再执行此操作,谢谢!!!");
                forward = "clue_on";
            } else {
                forward = "shopping_cart";
            }
        }
        //修改注册信息
        if (p.equals("update_data")) {
            HttpSession session = request.getSession();
            String username = (String) session.getAttribute("username");
            if (username == null) {
                request.setAttribute("clueOn", "请登录后再执行此操作,谢谢!!!");
                forward = "clue_on";
            } else {
                forward = "update_data";
            }
        }
        if (p.equals("update_submit")) {
            SpecialMethod sm = new SpecialMethod();
            String username = sm.toChinese(indexForm.getUsername());
            String hql = "from UserInfo where username='" + username + "'";
            Hibernate hn = new Hibernate();
            UserInfo info = (UserInfo) hn.queryOne(hql);
            String password = indexForm.getPassword();
            String pwdSure = indexForm.getPwdSure();
            if (password.length() > 0) { // 当填写新密码时执行该操作
                if (password.equals(pwdSure)) { // 判断两次输入的密码是否相同
                    info.setPassword(password);
                    info.setProblem(sm.toChinese(indexForm.getPwdQuestion()));
                    info.setSolution(sm.toChinese(indexForm.getPwdAnswer()));
                } else { // 如果不相同返回提示信息
                    request.setAttribute("errors", "password");
                }
            }
            info.setPhone(indexForm.getPhone());
            info.setTel(indexForm.getTel());
            info.setQq(indexForm.getQq());
            info.setEmail(indexForm.getEmail());
            info.setNativePlace(sm.toChinese(indexForm.getNativePlace()));
            info.setAddress(sm.toChinese(indexForm.getAddress()));
            info.setPostCard(indexForm.getPostCard());
            hn.update(info);
            forward = "update_data";
        }

        //登录
        if (p.equals("land")) {
            String hql = "from UserInfo where username='" +
                         indexForm.getUsername() + "'";
            Hibernate hn = new Hibernate();
            UserInfo info = (UserInfo) hn.queryOne(hql);
            if (info != null) {
                if (info.getState().equals("正常")) {
                    if (info.getPassword().equals(indexForm.getPassword())) {
                        HttpSession session = request.getSession();
                        session.setAttribute("username", indexForm.getUsername());
                    } else {
                        request.setAttribute("landClueOn", "用户名或密码错误!");
                    }
                } else {
                    request.setAttribute("landClueOn", "该用户已经被冻结!");
                }
            } else {
                request.setAttribute("landClueOn", "用户名或密码错误!");
            }
            String pageInLand = indexForm.getPageInLand();
            int i = pageInLand.indexOf(".");
            pageInLand = pageInLand.substring(1, i);
            forward = pageInLand;
        }
        //退出登录
        if (p.equals("exitLand")) {
            HttpSession session = request.getSession();
            session.invalidate(); //清空session中的所有内容
            forward = "index";
        }
        //转入注册页
        if (p.equals("login")) {
            forward = "login";
        }
        //提交注册信息

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -