📄 indexaction.java
字号:
if (p.equals("loginSubmit")) {
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);
if (info == null) {
String password = indexForm.getPassword();
String pwdSure = indexForm.getPwdSure();
if (password.equals(pwdSure)) {
System.out.println("密码相同");
info = new UserInfo();
info.setUsername(username);
info.setPassword(password);
info.setProblem(sm.toChinese(indexForm.getPwdQuestion()));
info.setSolution(sm.toChinese(indexForm.getPwdAnswer()));
info.setName(sm.toChinese(indexForm.getName()));
info.setSex(indexForm.getSex());
info.setIdCard(indexForm.getIdCard());
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());
info.setLoginDate(new SpecialMethod().getDateWithYMD());
info.setState("正常");
hn.save(info);
HttpSession session = request.getSession();
session.setAttribute("username", username);
forward = "index";
} else {
//两次输入的密码不相同
request.setAttribute("errors", "password");
request.setAttribute("indexForm", indexForm);
forward = "login";
}
} else {
//用户名已存在
request.setAttribute("errors", "username");
request.setAttribute("indexForm", indexForm);
forward = "login";
}
}
//找回密码
if (p.equals("findPassword")) {
forward = "findPassword";
}
if (p.equals("findPasswordSubmit")) {
String pwdQuestion = indexForm.getPwdQuestion();
String pwdAnswer = indexForm.getPwdAnswer();
SpecialMethod sm = new SpecialMethod();
pwdQuestion = sm.toChinese(pwdQuestion);
pwdAnswer = sm.toChinese(pwdAnswer);
String hql = "from UserInfo where problem='" + pwdQuestion + "'";
Hibernate hn = new Hibernate();
UserInfo info = (UserInfo) hn.queryOne(hql);
if (info != null && info.getSolution().equals(pwdAnswer)) {
request.setAttribute("password", info.getPassword());
} else {
request.setAttribute("password", "false");
}
forward = "findPassword";
}
//商品搜索
if (p.equals("searchMerchandise")) {
String name = indexForm.getSearchMerchandiseName();
name = new mrgf.other.SpecialMethod().toChinese(name);
String hql = "from MerchandiseInfo where name like '%" + name +
"%'";
Hibernate hn = new Hibernate();
List merchandises = hn.query(hql);
request.setAttribute("merchandises", merchandises);
forward = "merchandise_search";
}
//商品类别超连接
if (p.equals("fatherSort")) {
String fatherId = request.getParameter("fatherId");
String requestPage = request.getParameter("requestPage");
int id = Integer.parseInt(fatherId);
HttpSession session = request.getSession();
List fatherSorts = (List) session.getAttribute("fatherSorts");
MerchandiseSort fatherSort = null;
for (int i = 0; i < fatherSorts.size(); i++) {
fatherSort = (MerchandiseSort) fatherSorts.get(i);
if (fatherSort.getId() == id) {
break;
}
}
Set sonSorts = fatherSort.getSonSorts();
session.setAttribute("sonSorts", sonSorts);
request.setAttribute("sonSorts", sonSorts);
Iterator it = sonSorts.iterator();
String sortIds = "";
while (it.hasNext()) {
MerchandiseSort sort = (MerchandiseSort) it.next();
sortIds = sortIds + "," + sort.getId();
}
sortIds = sortIds + ")";
sortIds = sortIds.replaceFirst(",", "(");
List merchandises = null;
if (requestPage.equals("/taxis.jsp")) {
id = Integer.parseInt(sortIds.substring(1, sortIds.indexOf(",")));
merchandises = this.getMerchandiseTaxisWithSort(id);
forward = "taxis";
} else {
Hibernate hn = new Hibernate();
if (requestPage.equals("/special_offer.jsp")) {
String hql =
"from MerchandiseInfo where type='t' and sortId in" +
sortIds;
merchandises = hn.query(hql);
forward = "special_offer";
} else {
String hql =
"from MerchandiseInfo where type='n' and sortId in" +
sortIds;
merchandises = hn.query(hql);
forward = "new_merchandise";
}
}
request.setAttribute("merchandises", merchandises);
}
if (p.equals("sonSort")) {
String fatherId = request.getParameter("fatherId");
String requestPage = request.getParameter("requestPage");
int id = Integer.parseInt(fatherId);
List merchandises = null;
if (requestPage.equals("/taxis.jsp")) {
merchandises = this.getMerchandiseTaxisWithSort(id);
forward = "taxis";
} else {
String hql = "from MerchandiseInfo where sortId='" + id + "'";
if (requestPage.equals("/special_offer.jsp")) {
hql = hql + " and type='t'";
forward = "special_offer";
} else {
hql = hql + " and type='n'";
forward = "new_merchandise";
}
Hibernate hn = new Hibernate();
merchandises = hn.query(hql);
}
request.setAttribute("sonSorts", "session");
request.setAttribute("merchandises", merchandises);
}
//查看所有新品
if (p.equals("all_new_merchandise")) {
String hql = "from MerchandiseInfo where type='n'";
List merchandises = new Hibernate().query(hql);
request.setAttribute("merchandises", merchandises);
forward = "new_merchandise";
}
//查看公告
if (p.equals("seeAffiche")) {
String afficheId = (String) request.getParameter("afficheId");
int id = Integer.parseInt(afficheId);
String hql = "from Affiche where id=" + id;
Hibernate hn = new Hibernate();
Affiche affiche = (Affiche) hn.queryOne(hql);
request.setAttribute("affiche", affiche);
forward = "seeAffiche";
}
return mapping.findForward(forward);
}
//获取商品分类排行信息
private List getMerchandiseTaxisWithSort(int sonSortId) {
String sql = "select merchandise_id from (select * from tb_sell_info where merchandise_id in (select id from tb_merchandise_info where sort_id=" +
sonSortId + ")) sortMerchandise group by sortMerchandise.merchandise_id order by sum(amount) desc";
Hibernate hn = new Hibernate();
List idTaxis = hn.queryWithSql(sql);
String sid = "";
int id = 0;
List merchandises = new ArrayList();
for (int i = 0; i < 8; i++) {
if (i < idTaxis.size()) {
sid = idTaxis.get(i).toString();
id = Integer.parseInt(sid);
String hql = "from MerchandiseInfo where id=" + id;
MerchandiseInfo info = (MerchandiseInfo) hn.query(hql).
get(0);
merchandises.add(info);
}
}
return merchandises;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -