• Java项目:JSP中华传统美食网站平台管理系统


    作者主页:源码空间站2022

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

     

    作者主页:夜未央5788

     简介:Java领域优质创作者、Java项目、学习资料、技术互助

    文末获取源码

    项目介绍

    本项目分为前台与后台,前台由用户登录,后台由管理员登录;

    管理员角色包含以下功能:

    管理员登录,会员管理,资讯管理,链接管理,图片管理,美食类别管理,制作方法管理,美食管理,美食库存管理,订单管理,留言管理等功能。

    用户角色包含以下功能:
    用户登录,按分类查看菜品,查看站内资讯,提交留言,查看商品详情,加入购物车,提交订单,付款,查看我的订单等功能。

    环境需要

    1.运行环境:最好是java jdk 1.8,我们在这个平台上运行的。其他版本理论上也可以。
    2.IDE环境:IDEA,Eclipse,Myeclipse都可以。推荐IDEA;
    3.tomcat环境:Tomcat 7.x,8.x,9.x版本均可
    4.硬件环境:windows 7/8/10 1G内存以上;或者 Mac OS; 

    5.数据库:MySql 5.7版本;

    6.是否Maven项目:否;

    技术栈

    JSP+CSS+JavaScript+jQuery+Bootstrap+mysql

    使用说明

    1. 使用Navicat或者其它工具,在mysql中创建对应名称的数据库,并导入项目的sql文件;

    2. 使用IDEA/Eclipse/MyEclipse导入项目,Eclipse/MyEclipse导入时,若为maven项目请选择maven;

    若为maven项目,导入成功后请执行maven clean;maven install命令,然后运行;

    3. 将项目中util/SimpleDataSource.java配置文件中的数据库配置改为自己的配置;
    4. 运行项目,输入localhost:8080/jsp_zhctms_site 登录 注:tomcat中配置项目路径必须为jsp_zhctms_site
    用户账号/密码: user/123456

    管理员账号/密码:admin/admin

    运行截图

    前台界面-用户角色

    后台界面

    相关代码 

    MainCtrl

    1. package control;
    2. import java.io.File;
    3. import java.io.IOException;
    4. import java.io.InputStream;
    5. import java.io.PrintWriter;
    6. import java.net.SocketException;
    7. import java.net.UnknownHostException;
    8. import java.util.ArrayList;
    9. import java.util.HashMap;
    10. import java.util.List;
    11. import java.util.Properties;
    12. import javax.servlet.ServletException;
    13. import javax.servlet.http.HttpServlet;
    14. import javax.servlet.http.HttpServletRequest;
    15. import javax.servlet.http.HttpServletResponse;
    16. import javax.servlet.http.HttpSession;
    17. import org.apache.commons.fileupload.FileItem;
    18. import org.apache.commons.fileupload.FileUpload;
    19. import org.apache.commons.fileupload.RequestContext;
    20. import org.apache.commons.fileupload.disk.DiskFileItemFactory;
    21. import org.apache.commons.fileupload.servlet.ServletFileUpload;
    22. import org.apache.commons.fileupload.servlet.ServletRequestContext;
    23. import util.Info;
    24. import com.main.MainMethod;
    25. import dao.CommDAO;
    26. public class MainCtrl extends HttpServlet {
    27. public MainCtrl() {
    28. super();
    29. }
    30. public void destroy() {
    31. super.destroy(); // Just puts "destroy" string in log
    32. // Put your code here
    33. }
    34. public void doGet(HttpServletRequest request, HttpServletResponse response)
    35. throws ServletException, IOException {
    36. this.doPost(request, response);
    37. }
    38. MainMethod responses = new MainMethod();
    39. public void go(String url, HttpServletRequest request,
    40. HttpServletResponse response) {
    41. try {
    42. request.getRequestDispatcher(url).forward(request, response);
    43. } catch (ServletException e) {
    44. e.printStackTrace();
    45. } catch (IOException e) {
    46. e.printStackTrace();
    47. }
    48. }
    49. public void gor(String url, HttpServletRequest request,
    50. HttpServletResponse response) {
    51. try {
    52. response.sendRedirect(url);
    53. } catch (IOException e) {
    54. // TODO Auto-generated catch block
    55. e.printStackTrace();
    56. }
    57. }
    58. public void doPost(HttpServletRequest request, HttpServletResponse response)
    59. throws ServletException, IOException {
    60. response.setContentType("text/html");
    61. PrintWriter out = response.getWriter();
    62. HttpSession session = request.getSession();
    63. HashMap admin = (HashMap) session.getAttribute("admin");
    64. HashMap member = (HashMap) session.getAttribute("member");
    65. String ac = request.getParameter("ac");
    66. if (ac == null)
    67. ac = "";
    68. CommDAO dao = new CommDAO();
    69. String date = Info.getDateStr();
    70. String today = date.substring(0, 10);
    71. String tomonth = date.substring(0, 7);
    72. // 登录
    73. if (ac.equals("login")) {
    74. String username = request.getParameter("username");
    75. String userpwd = request.getParameter("userpwd");
    76. String sql = "select * from sysuser where username='" + username
    77. + "' and userpwd='" + userpwd
    78. + "' and usertype in ('管理员') ";
    79. List list = dao.select(sql);
    80. if (list.size() == 1) {
    81. session.setAttribute("admin", list.get(0));
    82. gor("/jsp_zhctms_site/admin/index.jsp", request, response);
    83. } else {
    84. request.setAttribute("error", "");
    85. go("admin/login.jsp", request, response);
    86. }
    87. }
    88. // 后台退出
    89. if (ac.equals("backexit")) {
    90. session.removeAttribute("admin");
    91. go("admin/login.jsp", request, response);
    92. }
    93. // 新增新闻
    94. if (ac.equals("newsadd")) {
    95. try {
    96. String title = "";
    97. String img = "";
    98. String note = "";
    99. request.setCharacterEncoding("utf-8");
    100. RequestContext requestContext = new ServletRequestContext(
    101. request);
    102. if (FileUpload.isMultipartContent(requestContext)) {
    103. DiskFileItemFactory factory = new DiskFileItemFactory();
    104. factory.setRepository(new File(request
    105. .getRealPath("/upfile/") + "/"));
    106. ServletFileUpload upload = new ServletFileUpload(factory);
    107. upload.setSizeMax(100 * 1024 * 1024);
    108. List items = new ArrayList();
    109. items = upload.parseRequest(request);
    110. title = ((FileItem) items.get(0)).getString();
    111. title = Info.getUTFStr(title);
    112. note = ((FileItem) items.get(2)).getString();
    113. note = Info.getUTFStr(note);
    114. FileItem fileItem = (FileItem) items.get(1);
    115. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    116. if (fileItem.getName() != null
    117. && fileItem.getSize() != 0) {
    118. File fullFile = new File(fileItem.getName());
    119. img = Info.generalFileName(fullFile.getName());
    120. File newFile = new File(
    121. request.getRealPath("/upfile/") + "/" + img);
    122. try {
    123. fileItem.write(newFile);
    124. } catch (Exception e) {
    125. e.printStackTrace();
    126. }
    127. } else {
    128. }
    129. }
    130. }
    131. String sql = "insert into news (title,img,note,savetime,type) "
    132. + "values('" + title + "','" + img + "','" + note
    133. + "','" + Info.getDateStr() + "','新闻')";
    134. dao.commOper(sql);
    135. request.setAttribute("suc", "操作成功!");
    136. go("/admin/newslist.jsp", request, response);
    137. } catch (Exception e1) {
    138. e1.printStackTrace();
    139. request.setAttribute("error", "");
    140. request.getRequestDispatcher("/admin/newsadd.jsp").forward(
    141. request, response);
    142. }
    143. }
    144. // 编辑新闻
    145. if (ac.equals("newsedit")) {
    146. String id = request.getParameter("id");
    147. HashMap map = dao.select("select * from news where id=" + id)
    148. .get(0);
    149. try {
    150. String title = "";
    151. String note = "";
    152. String img = map.get("img").toString();
    153. request.setCharacterEncoding("utf-8");
    154. RequestContext requestContext = new ServletRequestContext(
    155. request);
    156. if (FileUpload.isMultipartContent(requestContext)) {
    157. DiskFileItemFactory factory = new DiskFileItemFactory();
    158. factory.setRepository(new File(request
    159. .getRealPath("/upfile/") + "/"));
    160. ServletFileUpload upload = new ServletFileUpload(factory);
    161. upload.setSizeMax(100 * 1024 * 1024);
    162. List items = new ArrayList();
    163. items = upload.parseRequest(request);
    164. title = ((FileItem) items.get(0)).getString();
    165. title = Info.getUTFStr(title);
    166. note = ((FileItem) items.get(2)).getString();
    167. note = Info.getUTFStr(note);
    168. FileItem fileItem = (FileItem) items.get(1);
    169. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    170. if (fileItem.getName() != null
    171. && fileItem.getSize() != 0) {
    172. File fullFile = new File(fileItem.getName());
    173. img = Info.generalFileName(fullFile.getName());
    174. File newFile = new File(
    175. request.getRealPath("/upfile/") + "/" + img);
    176. try {
    177. fileItem.write(newFile);
    178. } catch (Exception e) {
    179. e.printStackTrace();
    180. }
    181. } else {
    182. }
    183. }
    184. }
    185. String sql = "update news set title='" + title + "',note='"
    186. + note + "',img='" + img + "' where id=" + id;
    187. dao.commOper(sql);
    188. request.setAttribute("suc", "操作成功!");
    189. go("/admin/newslist.jsp?id=" + id, request, response);
    190. } catch (Exception e1) {
    191. e1.printStackTrace();
    192. request.setAttribute("error", "");
    193. request.getRequestDispatcher("/admin/newsedit.jsp?id=" + id)
    194. .forward(request, response);
    195. }
    196. }
    197. // 新增公告
    198. if (ac.equals("noticesadd")) {
    199. String title = request.getParameter("title");
    200. String note = request.getParameter("note");
    201. String savetime = Info.getDateStr();
    202. String type = "公告";
    203. dao.commOper("insert into news (title,note,savetime,type) "
    204. + " values ('" + title + "','" + note + "','" + savetime
    205. + "','" + type + "')");
    206. request.setAttribute("suc", "");
    207. go("admin/noticesadd.jsp", request, response);
    208. }
    209. // 编辑公告
    210. if (ac.equals("noticesedit")) {
    211. String id = request.getParameter("id");
    212. String title = request.getParameter("title");
    213. String note = request.getParameter("note");
    214. dao.commOper("update news set title='" + title + "',note='" + note
    215. + "' where id=" + id);
    216. request.setAttribute("suc", "");
    217. go("admin/noticesedit.jsp?id=" + id, request, response);
    218. }
    219. // 新增链接
    220. if (ac.equals("yqlinkadd")) {
    221. String linkname = request.getParameter("linkname");
    222. String linkurl = request.getParameter("linkurl");
    223. dao.commOper("insert into yqlink (linkname,linkurl) "
    224. + " values ('" + linkname + "','" + linkurl + "')");
    225. request.setAttribute("suc", "操作成功!");
    226. go("admin/yqlink.jsp", request, response);
    227. }
    228. // 编辑公告
    229. if (ac.equals("yqlinkedit")) {
    230. String id = request.getParameter("id");
    231. String linkname = request.getParameter("linkname");
    232. String linkurl = request.getParameter("linkurl");
    233. dao.commOper("update yqlink set linkname='" + linkname
    234. + "',linkurl='" + linkurl + "' where id=" + id);
    235. request.setAttribute("suc", "操作成功!");
    236. go("admin/yqlink.jsp", request, response);
    237. }
    238. // 网站信息编辑
    239. if (ac.equals("siteinfoedit")) {
    240. String id = request.getParameter("id");
    241. HashMap map = dao.select("select * from siteinfo where id=" + id)
    242. .get(0);
    243. try {
    244. String tel = "";
    245. String addr = "";
    246. String note = "";
    247. String logoimg = map.get("logoimg").toString();
    248. request.setCharacterEncoding("utf-8");
    249. RequestContext requestContext = new ServletRequestContext(
    250. request);
    251. if (FileUpload.isMultipartContent(requestContext)) {
    252. DiskFileItemFactory factory = new DiskFileItemFactory();
    253. factory.setRepository(new File(request
    254. .getRealPath("/upfile/") + "/"));
    255. ServletFileUpload upload = new ServletFileUpload(factory);
    256. upload.setSizeMax(100 * 1024 * 1024);
    257. List items = new ArrayList();
    258. items = upload.parseRequest(request);
    259. tel = ((FileItem) items.get(0)).getString();
    260. tel = Info.getUTFStr(tel);
    261. addr = ((FileItem) items.get(1)).getString();
    262. addr = Info.getUTFStr(addr);
    263. note = ((FileItem) items.get(3)).getString();
    264. note = Info.getUTFStr(note);
    265. FileItem fileItem = (FileItem) items.get(2);
    266. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    267. if (fileItem.getName() != null
    268. && fileItem.getSize() != 0) {
    269. File fullFile = new File(fileItem.getName());
    270. logoimg = Info.generalFileName(fullFile.getName());
    271. File newFile = new File(
    272. request.getRealPath("/upfile/") + "/"
    273. + logoimg);
    274. try {
    275. fileItem.write(newFile);
    276. } catch (Exception e) {
    277. e.printStackTrace();
    278. }
    279. } else {
    280. }
    281. }
    282. }
    283. String sql = "update siteinfo set tel='" + tel + "',addr='"
    284. + addr + "',note='" + note + "',logoimg='" + logoimg
    285. + "' where id=" + id;
    286. dao.commOper(sql);
    287. request.setAttribute("suc", "");
    288. go("/admin/siteinfo.jsp?id=" + id, request, response);
    289. } catch (Exception e1) {
    290. e1.printStackTrace();
    291. request.setAttribute("error", "");
    292. request.getRequestDispatcher("/admin/siteinfo.jsp?id=" + id)
    293. .forward(request, response);
    294. }
    295. }
    296. // 检查用户名唯一性AJAX
    297. if (ac.equals("sysuserscheck")) {
    298. String username = request.getParameter("username");
    299. ArrayList cklist = (ArrayList) dao
    300. .select("select * from sysuser where username='" + username
    301. + "' and delstatus='0' ");
    302. if (cklist.size() > 0) {
    303. out.write("1");
    304. } else {
    305. out.write("0");
    306. }
    307. }
    308. // 新增管理员
    309. if (ac.equals("sysuseradd")) {
    310. String usertype = "管理员";
    311. String username = request.getParameter("username");
    312. String userpwd = request.getParameter("userpwd");
    313. String realname = request.getParameter("realname");
    314. String sex = request.getParameter("sex");
    315. String idcard = request.getParameter("idcard");
    316. String tel = request.getParameter("tel");
    317. String email = request.getParameter("email");
    318. String addr = request.getParameter("addr");
    319. String delstatus = "0";
    320. String savetime = Info.getDateStr();
    321. dao.commOper("insert into sysuser (usertype,username,userpwd,realname,sex,idcard,tel,email,addr,delstatus,savetime)"
    322. + " values ('"
    323. + usertype
    324. + "','"
    325. + username
    326. + "','"
    327. + userpwd
    328. + "','"
    329. + realname
    330. + "','"
    331. + sex
    332. + "','"
    333. + idcard
    334. + "','"
    335. + tel
    336. + "','"
    337. + email
    338. + "','"
    339. + addr
    340. + "','"
    341. + delstatus
    342. + "','"
    343. + savetime + "')");
    344. request.setAttribute("suc", "");
    345. go("/admin/sysuseradd.jsp", request, response);
    346. }
    347. // 编辑管理员
    348. if (ac.equals("sysuseredit")) {
    349. String id = request.getParameter("id");
    350. String userpwd = request.getParameter("userpwd");
    351. String realname = request.getParameter("realname");
    352. String sex = request.getParameter("sex");
    353. String idcard = request.getParameter("idcard");
    354. String tel = request.getParameter("tel");
    355. String email = request.getParameter("email");
    356. String addr = request.getParameter("addr");
    357. dao.commOper("update sysuser set userpwd='" + userpwd
    358. + "',realname='" + realname + "',sex='" + sex
    359. + "',idcard='" + idcard + "',tel='" + tel + "',email='"
    360. + email + "',addr='" + addr + "' where id=" + id);
    361. request.setAttribute("suc", "");
    362. go("/admin/sysuseredit.jsp?id=" + id, request, response);
    363. }
    364. // 美食类别新增
    365. if (ac.equals("protypeadd")) {
    366. String typename = request.getParameter("typename");
    367. String fatherid = request.getParameter("fatherid");
    368. dao.commOper("insert into protype (typename,fatherid,delstatus) values ('"
    369. + typename + "','" + fatherid + "','0') ");
    370. request.setAttribute("suc", "操作成功!");
    371. go("/admin/protype.jsp", request, response);
    372. }
    373. // 美食类别编辑
    374. if (ac.equals("protypeedit")) {
    375. String id = request.getParameter("id");
    376. String typename = request.getParameter("typename");
    377. dao.commOper("update protype set typename='" + typename
    378. + "' where id=" + id);
    379. request.setAttribute("suc", "操作成功!");
    380. go("/admin/protype.jsp?id=" + id, request, response);
    381. }
    382. // 美食属性新增
    383. if (ac.equals("propertyadd")) {
    384. String propertyname = request.getParameter("propertyname");
    385. dao.commOper("insert into property (propertyname,delstatus) values ('"
    386. + propertyname + "','0') ");
    387. request.setAttribute("suc", "");
    388. go("/admin/propertyadd.jsp", request, response);
    389. }
    390. // 美食属性编辑
    391. if (ac.equals("propertyedit")) {
    392. String id = request.getParameter("id");
    393. String propertyname = request.getParameter("propertyname");
    394. dao.commOper("update property set propertyname='" + propertyname
    395. + "' where id=" + id);
    396. request.setAttribute("suc", "");
    397. go("/admin/propertyedit.jsp?id=" + id, request, response);
    398. }
    399. // AJAX根据父类查子类
    400. if (ac.equals("searchsontype")) {
    401. String xml_start = "";
    402. String xml_end = "";
    403. String xml = "";
    404. String fprotype = request.getParameter("fprotype");
    405. ArrayList list = (ArrayList) dao
    406. .select("select * from protype where fatherid='" + fprotype
    407. + "' and delstatus='0' ");
    408. if (list.size() > 0) {
    409. for (HashMap map : list) {
    410. xml += "";
    411. }
    412. }
    413. String last_xml = xml_start + xml + xml_end;
    414. response.setContentType("text/xml;charset=GB2312");
    415. response.setCharacterEncoding("utf-8");
    416. response.getWriter().write(last_xml);
    417. response.getWriter().flush();
    418. }
    419. // 公用方法,图片上传
    420. if (ac.equals("uploadimg")) {
    421. try {
    422. String filename = "";
    423. request.setCharacterEncoding("utf-8");
    424. RequestContext requestContext = new ServletRequestContext(
    425. request);
    426. if (FileUpload.isMultipartContent(requestContext)) {
    427. DiskFileItemFactory factory = new DiskFileItemFactory();
    428. factory.setRepository(new File(request
    429. .getRealPath("/upfile/") + "/"));
    430. ServletFileUpload upload = new ServletFileUpload(factory);
    431. upload.setSizeMax(100 * 1024 * 1024);
    432. List items = new ArrayList();
    433. items = upload.parseRequest(request);
    434. FileItem fileItem = (FileItem) items.get(0);
    435. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    436. if (fileItem.getName() != null
    437. && fileItem.getSize() != 0) {
    438. File fullFile = new File(fileItem.getName());
    439. filename = Info.generalFileName(fullFile.getName());
    440. File newFile = new File(
    441. request.getRealPath("/upfile/") + "/"
    442. + filename);
    443. try {
    444. fileItem.write(newFile);
    445. } catch (Exception e) {
    446. e.printStackTrace();
    447. }
    448. } else {
    449. }
    450. }
    451. }
    452. go("/js/uploadimg.jsp?filename=" + filename, request, response);
    453. } catch (Exception e1) {
    454. e1.printStackTrace();
    455. }
    456. }
    457. // 库存预警数值设置
    458. if (ac.equals("kcwarningset")) {
    459. String num = request.getParameter("num");
    460. String id = request.getParameter("id");
    461. dao.commOper("update kcwarnning set num=" + Integer.parseInt(num)
    462. + " where id=" + id);
    463. request.setAttribute("suc", "");
    464. go("/admin/kcwarningset.jsp", request, response);
    465. }
    466. // 美食入库
    467. if (ac.equals("kcinto")) {
    468. String pid = request.getParameter("pid");
    469. String num = request.getParameter("num");
    470. String type = request.getParameter("type");
    471. String reason = request.getParameter("reason");
    472. String savetime = Info.getDateStr();
    473. dao.commOper("insert into kcrecord (pid,num,type,reason,savetime) values"
    474. + " ('"
    475. + pid
    476. + "','"
    477. + Integer.parseInt(num)
    478. + "','"
    479. + type + "','" + reason + "','" + savetime + "') ");
    480. request.setAttribute("suc", "");
    481. go("/admin/kcinto.jsp", request, response);
    482. }
    483. // 美食出库
    484. if (ac.equals("kcout")) {
    485. String pid = request.getParameter("pid");
    486. String num = request.getParameter("num");
    487. String type = request.getParameter("type");
    488. String reason = request.getParameter("reason");
    489. String savetime = Info.getDateStr();
    490. int znum = 0;
    491. int innum = 0;
    492. int outnum = 0;
    493. ArrayList inlist = (ArrayList) dao
    494. .select("select * from kcrecord where type='in' and pid='"
    495. + pid + "' ");
    496. ArrayList outlist = (ArrayList) dao
    497. .select("select * from kcrecord where type='out' and pid='"
    498. + pid + "' ");
    499. if (inlist.size() > 0) {
    500. for (HashMap inmap : inlist) {
    501. innum += Integer.parseInt(inmap.get("num").toString());// 总入库量
    502. }
    503. }
    504. if (outlist.size() > 0) {
    505. for (HashMap outmap : outlist) {
    506. outnum += Integer.parseInt(outmap.get("num").toString());// 总出库量
    507. }
    508. }
    509. znum = innum - outnum;// 库存量
    510. if (Integer.parseInt(num) > znum) {
    511. request.setAttribute("no", "");
    512. go("/admin/kcout.jsp", request, response);
    513. } else {
    514. dao.commOper("insert into kcrecord (pid,num,type,reason,savetime) values"
    515. + " ('"
    516. + pid
    517. + "','"
    518. + Integer.parseInt(num)
    519. + "','"
    520. + type + "','" + reason + "','" + savetime + "') ");
    521. request.setAttribute("suc", "");
    522. go("/admin/kcout.jsp", request, response);
    523. }
    524. }
    525. // 新增图片
    526. if (ac.equals("imgadvaddold")) {
    527. try {
    528. String img = "";
    529. String imgtype = "";
    530. request.setCharacterEncoding("utf-8");
    531. RequestContext requestContext = new ServletRequestContext(
    532. request);
    533. if (FileUpload.isMultipartContent(requestContext)) {
    534. DiskFileItemFactory factory = new DiskFileItemFactory();
    535. factory.setRepository(new File(request
    536. .getRealPath("/upfile/") + "/"));
    537. ServletFileUpload upload = new ServletFileUpload(factory);
    538. upload.setSizeMax(100 * 1024 * 1024);
    539. List items = new ArrayList();
    540. items = upload.parseRequest(request);
    541. imgtype = ((FileItem) items.get(1)).getString();
    542. imgtype = Info.getUTFStr(imgtype);
    543. FileItem fileItem = (FileItem) items.get(0);
    544. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    545. if (fileItem.getName() != null
    546. && fileItem.getSize() != 0) {
    547. File fullFile = new File(fileItem.getName());
    548. img = Info.generalFileName(fullFile.getName());
    549. File newFile = new File(
    550. request.getRealPath("/upfile/") + "/" + img);
    551. try {
    552. fileItem.write(newFile);
    553. } catch (Exception e) {
    554. e.printStackTrace();
    555. }
    556. } else {
    557. }
    558. }
    559. }
    560. String cksql = "select * from imgadv where imgtype='banner'";
    561. ArrayList cklist = (ArrayList) dao.select(cksql);
    562. if (imgtype.equals("banner") && cklist.size() != 0) {
    563. request.setAttribute("no", "");
    564. go("/admin/imgadvadd.jsp", request, response);
    565. } else {
    566. String sql = "insert into imgadv (filename,imgtype) "
    567. + "values('" + img + "','" + imgtype + "')";
    568. dao.commOper(sql);
    569. request.setAttribute("suc", "");
    570. go("/admin/imgadvadd.jsp", request, response);
    571. }
    572. } catch (Exception e1) {
    573. e1.printStackTrace();
    574. request.setAttribute("no", "");
    575. request.getRequestDispatcher("/admin/imgadvadd.jsp").forward(
    576. request, response);
    577. }
    578. }
    579. // 编辑图片
    580. if (ac.equals("imgadvedit")) {
    581. String id = request.getParameter("id");
    582. HashMap map = dao.select("select * from imgadv where id=" + id)
    583. .get(0);
    584. try {
    585. String img = map.get("filename").toString();
    586. request.setCharacterEncoding("utf-8");
    587. RequestContext requestContext = new ServletRequestContext(
    588. request);
    589. if (FileUpload.isMultipartContent(requestContext)) {
    590. DiskFileItemFactory factory = new DiskFileItemFactory();
    591. factory.setRepository(new File(request
    592. .getRealPath("/upfile/") + "/"));
    593. ServletFileUpload upload = new ServletFileUpload(factory);
    594. upload.setSizeMax(100 * 1024 * 1024);
    595. List items = new ArrayList();
    596. items = upload.parseRequest(request);
    597. FileItem fileItem = (FileItem) items.get(0);
    598. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    599. if (fileItem.getName() != null
    600. && fileItem.getSize() != 0) {
    601. File fullFile = new File(fileItem.getName());
    602. img = Info.generalFileName(fullFile.getName());
    603. File newFile = new File(
    604. request.getRealPath("/upfile/") + "/" + img);
    605. try {
    606. fileItem.write(newFile);
    607. } catch (Exception e) {
    608. e.printStackTrace();
    609. }
    610. } else {
    611. }
    612. }
    613. }
    614. String sql = "update imgadv set filename='" + img
    615. + "' where id=" + id;
    616. dao.commOper(sql);
    617. request.setAttribute("suc", "");
    618. go("/admin/imgadvedit.jsp?id=" + id, request, response);
    619. } catch (Exception e1) {
    620. e1.printStackTrace();
    621. request.setAttribute("error", "");
    622. request.getRequestDispatcher("/admin/imgadvedit.jsp?id=" + id)
    623. .forward(request, response);
    624. }
    625. }
    626. // 检查用户名唯一性AJAX 会员注册
    627. if (ac.equals("memberunamecheck")) {
    628. String uname = request.getParameter("username");
    629. ArrayList cklist = (ArrayList) dao
    630. .select("select * from member where uname='" + uname
    631. + "' and delstatus='0' ");
    632. if (cklist.size() > 0) {
    633. out.print("false");
    634. } else {
    635. out.print("true");
    636. }
    637. }
    638. // 检查美食的库存
    639. if (ac.equals("checkgoodkc")) {
    640. String gid = request.getParameter("gid");
    641. String sl = request.getParameter("sl");
    642. if (Integer.valueOf(sl) > Info.getkc(gid)) {
    643. out.write("1");
    644. } else {
    645. out.write("0");
    646. }
    647. }
    648. // 美食加入购物车
    649. if (ac.equals("tocar")) {
    650. String gid = request.getParameter("gid");
    651. int sl = Integer.valueOf(request.getParameter("sl"));
    652. if (member != null) {
    653. String mid = member.get("id").toString();
    654. // 检查该人的购物车是否有该物品
    655. ArrayList cklist = (ArrayList) dao
    656. .select("select * from car where mid='" + mid
    657. + "' and gid='" + gid + "'");
    658. if (cklist.size() > 0) {
    659. dao.commOper("update car set sl=sl+" + sl + " where mid='"
    660. + mid + "' and gid='" + gid + "' ");
    661. } else {
    662. dao.commOper("insert into car (gid,sl,mid) values ('" + gid
    663. + "','" + sl + "','" + mid + "')");
    664. }
    665. out.print("true");
    666. } else {
    667. out.print("false");
    668. }
    669. // request.setAttribute("suc", "");
    670. // go("/tocar.jsp?gid="+gid, request, response);
    671. }
    672. // 直接购买
    673. if (ac.equals("tobuy")) {
    674. String gid = request.getParameter("gid");
    675. int sl = Integer.valueOf(request.getParameter("sl"));
    676. String ddno = Info.getAutoNo();
    677. String shrname = "";
    678. String shrtel = "";
    679. String shraddr = request.getParameter("addr");
    680. double ddprice = 0.0;
    681. String fhstatus = "待发货";
    682. String shstatus = "待收货";
    683. String fkstatus = "待付款";
    684. String wlinfo = "暂无物流信息";
    685. String savetime = Info.getDateStr();
    686. if (member != null) {
    687. String memberid = member.get("id").toString();
    688. ArrayList addrlist = (ArrayList) dao
    689. .select("select * from addr where delstatus='0' and memberid="
    690. + member.get("id"));
    691. if (addrlist.size() == 0) {
    692. out.print("false");
    693. } else {
    694. shraddr = addrlist.get(0).get("id").toString();
    695. HashMap gmap = dao.select(
    696. "select * from goods where id=" + gid).get(0);
    697. String price = gmap.get("price").toString();
    698. if (gmap.get("tprice") != null
    699. && !gmap.get("tprice").equals("")) {
    700. price = gmap.get("tprice").toString();
    701. }
    702. ddprice = Double.valueOf(price) * sl;
    703. // 直接生成订单
    704. dao.commOper("insert into ddinfo (ddno,memberid,ddprice,fhstatus,savetime,shstatus,wlinfo,fkstatus,shrname,shrtel,shraddr) values "
    705. + "('"
    706. + ddno
    707. + "','"
    708. + memberid
    709. + "','"
    710. + ddprice
    711. + "','"
    712. + fhstatus
    713. + "','"
    714. + savetime
    715. + "','"
    716. + shstatus
    717. + "','"
    718. + wlinfo
    719. + "','"
    720. + fkstatus
    721. + "','"
    722. + shrname + "','" + shrtel + "','" + shraddr + "')");
    723. dao.commOper("insert into dddetail (ddno,goodid,sl) values ('"
    724. + ddno + "','" + gid + "','" + sl + "') ");
    725. out.print("true");
    726. }
    727. } else {
    728. out.print("false");
    729. }
    730. // request.setAttribute("suc", "");
    731. // go("/tocar.jsp?gid="+gid, request, response);
    732. }
    733. // 购物车内美食数量修改
    734. if (ac.equals("updatecart")) {
    735. String id = request.getParameter("carid");
    736. int sl = Integer.valueOf(request.getParameter("sl"));
    737. dao.commOper("update car set sl=" + sl + " where id=" + id);
    738. out.print("true");
    739. }
    740. // 购物车内美食总价
    741. if (ac.equals("updatetprice")) {
    742. ArrayList goodlist = (ArrayList) dao
    743. .select("select *,a.id as aid,b.id as bid from car a,goods b where a.gid=b.id and a.mid='"
    744. + member.get("id")
    745. + "' and b.delstatus='0' order by a.id desc");
    746. double totalprice = 0.0;
    747. for (HashMap carmap : goodlist) {
    748. if (carmap.get("tprice") != null
    749. && !carmap.get("tprice").equals("")) {
    750. totalprice += Double.valueOf(carmap.get("tprice")
    751. .toString())
    752. * Integer.valueOf(carmap.get("sl").toString());
    753. } else {
    754. totalprice += Double
    755. .valueOf(carmap.get("price").toString())
    756. * Integer.valueOf(carmap.get("sl").toString());
    757. }
    758. }
    759. out.print(totalprice);
    760. }
    761. // 提交生成订单 填写收货信息
    762. if (ac.equals("submitorder")) {
    763. String memberid = member.get("id").toString();
    764. // 生成订单号
    765. String ddno = Info.getAutoNo();
    766. String shrname = "";
    767. String shrtel = "";
    768. String shraddr = request.getParameter("addr");
    769. double ddprice = 0.0;
    770. String fhstatus = "待发货";
    771. String shstatus = "待收货";
    772. String fkstatus = "待付款";
    773. String wlinfo = "暂无物流信息";
    774. String savetime = Info.getDateStr();
    775. // 查询该会员的购物车所有美食
    776. ArrayList carlist = (ArrayList) dao
    777. .select("select * from car where mid=" + memberid);
    778. for (HashMap carmap : carlist) {
    779. HashMap goodmap = dao.select(
    780. "select * from goods where id=" + carmap.get("gid"))
    781. .get(0);
    782. if (goodmap.get("tprice") != null
    783. && !goodmap.get("tprice").equals("")) {
    784. ddprice += Double.valueOf(goodmap.get("tprice").toString())
    785. * Integer.valueOf(carmap.get("sl").toString());
    786. } else {
    787. ddprice += Double.valueOf(goodmap.get("price").toString())
    788. * Integer.valueOf(carmap.get("sl").toString());
    789. }
    790. dao.commOper("insert into dddetail (ddno,goodid,sl) values ('"
    791. + ddno + "','" + carmap.get("gid") + "','"
    792. + carmap.get("sl") + "') ");
    793. }
    794. dao.commOper("insert into ddinfo (ddno,memberid,ddprice,fhstatus,savetime,shstatus,wlinfo,fkstatus,shrname,shrtel,shraddr) values "
    795. + "('"
    796. + ddno
    797. + "','"
    798. + memberid
    799. + "','"
    800. + ddprice
    801. + "','"
    802. + fhstatus
    803. + "','"
    804. + savetime
    805. + "','"
    806. + shstatus
    807. + "','"
    808. + wlinfo
    809. + "','"
    810. + fkstatus
    811. + "','"
    812. + shrname
    813. + "','"
    814. + shrtel + "','" + shraddr + "')");
    815. // 删除购物车下的美食
    816. dao.commOper("delete from car where mid=" + memberid);
    817. request.setAttribute("suc", "订单生成成功!");
    818. go("/mydd.jsp", request, response);
    819. }
    820. //
    821. if (ac.equals("pay")) {
    822. String ddid = request.getParameter("ddid");
    823. String fkstatus = "已付款";
    824. String fhstatus = "待发货";
    825. String shstatus = "待收货";
    826. dao.commOper("update ddinfo set fkstatus='" + fkstatus
    827. + "',fhstatus='" + fhstatus + "',shstatus='" + shstatus
    828. + "' where id=" + ddid);
    829. request.setAttribute("suc", "支付成功!");
    830. go("/mydd.jsp?ddid=" + ddid, request, response);
    831. }
    832. // 订单发货
    833. if (ac.equals("ddfh")) {
    834. String ddid = request.getParameter("ddid");
    835. String wlcompany = request.getParameter("wlcompany");
    836. String wlno = request.getParameter("wlno");
    837. String wlinfo = wlcompany + "
      "
      + wlno;
    838. // 查询订单及订单详情表
    839. HashMap ddmap = dao.select("select * from ddinfo where id=" + ddid)
    840. .get(0);
    841. ArrayList dddetaillist = (ArrayList) dao
    842. .select("select * from dddetail where ddno="
    843. + ddmap.get("ddno"));
    844. boolean flag = true;// 用作订单美食库存校验结果
    845. for (HashMap dddetailmap : dddetaillist) {
    846. // 如果其中某个美食的数量大于其库存量 则置 FLASE标识
    847. if (Integer.valueOf(dddetailmap.get("sl").toString()) > Info
    848. .getkc(dddetailmap.get("goodid").toString())) {
    849. flag = false;
    850. }
    851. }
    852. if (flag) {
    853. dao.commOper("update ddinfo set fhstatus='已发货',wlinfo='"
    854. + wlinfo + "' where id=" + ddid);
    855. // 发货后减库存
    856. for (HashMap dddetailmap : dddetaillist) {
    857. dao.commOper("insert into kcrecord (gid,happennum,type,savetime) values "
    858. + "('"
    859. + dddetailmap.get("goodid")
    860. + "','"
    861. + dddetailmap.get("sl")
    862. + "','out','"
    863. + Info.getDateStr() + "')");
    864. }
    865. request.setAttribute("info", "订单已发货!");
    866. go("/admin/ddgl.jsp", request, response);
    867. } else {
    868. request.setAttribute("info", "订单中美食库存不足,发货失败!");
    869. go("/admin/ddgl.jsp", request, response);
    870. }
    871. }
    872. // 会员注册
    873. if (ac.equals("register")) {
    874. String uname = request.getParameter("username");
    875. String upass = request.getParameter("upass");
    876. String email = request.getParameter("email") == null ? "" : request
    877. .getParameter("email");
    878. String tname = request.getParameter("tname") == null ? "" : request
    879. .getParameter("tname");
    880. String sex = request.getParameter("sex") == null ? "" : request
    881. .getParameter("sex");
    882. String addr = request.getParameter("addr") == null ? "" : request
    883. .getParameter("addr");
    884. String ybcode = request.getParameter("ybcode") == null ? ""
    885. : request.getParameter("ybcode");
    886. String qq = request.getParameter("qq") == null ? "" : request
    887. .getParameter("qq");
    888. String tel = request.getParameter("tel") == null ? "" : request
    889. .getParameter("tel");
    890. String delstatus = "0";
    891. String savetime = Info.getDateStr();
    892. dao.commOper("insert into member (uname,upass,email,tname,sex,addr,ybcode,qq,tel,delstatus,savetime)"
    893. + " values ('"
    894. + uname
    895. + "','"
    896. + upass
    897. + "','"
    898. + email
    899. + "','"
    900. + tname
    901. + "','"
    902. + sex
    903. + "','"
    904. + addr
    905. + "','"
    906. + ybcode
    907. + "','"
    908. + qq
    909. + "','" + tel + "','" + delstatus + "','" + savetime + "')");
    910. request.setAttribute("suc", "注册成功");
    911. go("/reg.jsp", request, response);
    912. }
    913. // 会员修改个人信息
    914. if (ac.equals("memberinfo")) {
    915. String id = request.getParameter("id");
    916. String upass = request.getParameter("upass");
    917. String email = request.getParameter("email") == null ? "" : request
    918. .getParameter("email");
    919. String tname = request.getParameter("tname") == null ? "" : request
    920. .getParameter("tname");
    921. String sex = request.getParameter("sex") == null ? "" : request
    922. .getParameter("sex");
    923. String addr = request.getParameter("addr") == null ? "" : request
    924. .getParameter("addr");
    925. String ybcode = request.getParameter("ybcode") == null ? ""
    926. : request.getParameter("ybcode");
    927. String qq = request.getParameter("qq") == null ? "" : request
    928. .getParameter("qq");
    929. String tel = request.getParameter("tel") == null ? "" : request
    930. .getParameter("tel");
    931. dao.commOper("update member set upass='" + upass + "',email='"
    932. + email + "',tname='" + tname + "',sex='" + sex
    933. + "',addr='" + addr + "',ybcode='" + ybcode + "',qq='" + qq
    934. + "',tel='" + tel + "' where id=" + id);
    935. request.setAttribute("suc", "会员信息修改成功!");
    936. go("/grinfo.jsp", request, response);
    937. }
    938. // 会员登录
    939. if (ac.equals("frontlogin")) {
    940. String uname = request.getParameter("uname");
    941. String upass = request.getParameter("upass");
    942. ArrayList cklist = (ArrayList) dao
    943. .select("select * from member where uname='" + uname
    944. + "' and upass='" + upass + "' and delstatus='0'");
    945. if (cklist.size() > 0) {
    946. session.setAttribute("member", cklist.get(0));
    947. go("/index.jsp", request, response);
    948. } else {
    949. request.setAttribute("no", "用户名或密码错误!");
    950. go("/login.jsp", request, response);
    951. }
    952. }
    953. // 前台退出
    954. if (ac.equals("frontexit")) {
    955. session.removeAttribute("member");
    956. go("/index.jsp", request, response);
    957. }
    958. // 发布美食
    959. if (ac.equals("goodsadd")) {
    960. try {
    961. String goodno = Info.getAutoNo();
    962. String goodname = "";
    963. String fid = "";
    964. String sid = "";
    965. String goodpp = "";
    966. String price = "";
    967. String filename = "";
    968. String note = "";
    969. String shstatus = "通过";
    970. String istj = "no";
    971. String savetime = Info.getDateStr();
    972. String tprice = "";
    973. request.setCharacterEncoding("utf-8");
    974. RequestContext requestContext = new ServletRequestContext(
    975. request);
    976. if (FileUpload.isMultipartContent(requestContext)) {
    977. DiskFileItemFactory factory = new DiskFileItemFactory();
    978. factory.setRepository(new File(request
    979. .getRealPath("/upfile/") + "/"));
    980. ServletFileUpload upload = new ServletFileUpload(factory);
    981. upload.setSizeMax(100 * 1024 * 1024);
    982. List items = new ArrayList();
    983. items = upload.parseRequest(request);
    984. goodname = ((FileItem) items.get(0)).getString();
    985. goodname = Info.getUTFStr(goodname);
    986. fid = ((FileItem) items.get(1)).getString();
    987. fid = Info.getUTFStr(fid);
    988. sid = ((FileItem) items.get(2)).getString();
    989. sid = Info.getUTFStr(sid);
    990. goodpp = ((FileItem) items.get(3)).getString();
    991. goodpp = Info.getUTFStr(goodpp);
    992. price = ((FileItem) items.get(4)).getString();
    993. price = Info.getUTFStr(price);
    994. note = ((FileItem) items.get(6)).getString();
    995. note = Info.getUTFStr(note);
    996. FileItem fileItem = (FileItem) items.get(5);
    997. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    998. if (fileItem.getName() != null
    999. && fileItem.getSize() != 0) {
    1000. File fullFile = new File(fileItem.getName());
    1001. filename = Info.generalFileName(fullFile.getName());
    1002. File newFile = new File(
    1003. request.getRealPath("/upfile/") + "/"
    1004. + filename);
    1005. try {
    1006. fileItem.write(newFile);
    1007. } catch (Exception e) {
    1008. e.printStackTrace();
    1009. }
    1010. } else {
    1011. }
    1012. }
    1013. }
    1014. dao.commOper("insert into goods (goodno,goodname,fid,sid,price,note,savetime,shstatus,filename,istj,tprice,delstatus,salestatus,goodpp) "
    1015. + "values ('"
    1016. + goodno
    1017. + "','"
    1018. + goodname
    1019. + "','"
    1020. + fid
    1021. + "','"
    1022. + sid
    1023. + "','"
    1024. + price
    1025. + "','"
    1026. + note
    1027. + "','"
    1028. + savetime
    1029. + "','通过','"
    1030. + filename
    1031. + "','"
    1032. + istj
    1033. + "','"
    1034. + tprice
    1035. + "','0','在售','" + goodpp + "') ");
    1036. request.setAttribute("suc", "操作成功!");
    1037. go("/admin/goodsgl.jsp", request, response);
    1038. } catch (Exception e1) {
    1039. e1.printStackTrace();
    1040. request.setAttribute("error", "");
    1041. request.getRequestDispatcher("/admin/goodsgl.jsp").forward(
    1042. request, response);
    1043. }
    1044. }
    1045. // 会员修改美食
    1046. if (ac.equals("goodsedit")) {
    1047. String id = request.getParameter("id");
    1048. HashMap map = dao.select("select * from goods where id=" + id).get(
    1049. 0);
    1050. try {
    1051. String goodname = "";
    1052. String fid = "";
    1053. String sid = "";
    1054. String goodpp = "";
    1055. String price = "";
    1056. String note = "";
    1057. String filename = map.get("filename").toString();
    1058. request.setCharacterEncoding("utf-8");
    1059. RequestContext requestContext = new ServletRequestContext(
    1060. request);
    1061. if (FileUpload.isMultipartContent(requestContext)) {
    1062. DiskFileItemFactory factory = new DiskFileItemFactory();
    1063. factory.setRepository(new File(request
    1064. .getRealPath("/upfile/") + "/"));
    1065. ServletFileUpload upload = new ServletFileUpload(factory);
    1066. upload.setSizeMax(100 * 1024 * 1024);
    1067. List items = new ArrayList();
    1068. items = upload.parseRequest(request);
    1069. goodname = ((FileItem) items.get(0)).getString();
    1070. goodname = Info.getUTFStr(goodname);
    1071. fid = ((FileItem) items.get(1)).getString();
    1072. fid = Info.getUTFStr(fid);
    1073. sid = ((FileItem) items.get(2)).getString();
    1074. sid = Info.getUTFStr(sid);
    1075. goodpp = ((FileItem) items.get(3)).getString();
    1076. goodpp = Info.getUTFStr(goodpp);
    1077. price = ((FileItem) items.get(4)).getString();
    1078. price = Info.getUTFStr(price);
    1079. note = ((FileItem) items.get(6)).getString();
    1080. note = Info.getUTFStr(note);
    1081. FileItem fileItem = (FileItem) items.get(5);
    1082. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    1083. if (fileItem.getName() != null
    1084. && fileItem.getSize() != 0) {
    1085. File fullFile = new File(fileItem.getName());
    1086. filename = Info.generalFileName(fullFile.getName());
    1087. File newFile = new File(
    1088. request.getRealPath("/upfile/") + "/"
    1089. + filename);
    1090. try {
    1091. fileItem.write(newFile);
    1092. } catch (Exception e) {
    1093. e.printStackTrace();
    1094. }
    1095. } else {
    1096. }
    1097. }
    1098. }
    1099. dao.commOper("update goods set goodname='" + goodname
    1100. + "',fid='" + fid + "',sid='" + sid + "',price='"
    1101. + price + "',note='" + note + "',filename='" + filename
    1102. + "',goodpp='" + goodpp + "' where id=" + id);
    1103. request.setAttribute("suc", "操作成功!");
    1104. go("/admin/goodsgl.jsp?id=" + id, request, response);
    1105. } catch (Exception e1) {
    1106. e1.printStackTrace();
    1107. request.setAttribute("error", "");
    1108. request.getRequestDispatcher("/admin/goodsgl.jsp").forward(
    1109. request, response);
    1110. }
    1111. }
    1112. // 美食入库
    1113. if (ac.equals("goodskcadd")) {
    1114. String gid = request.getParameter("gid");
    1115. String happennum = request.getParameter("happennum");
    1116. String type = "in";
    1117. String savetime = Info.getDateStr();
    1118. dao.commOper("insert into kcrecord (gid,happennum,type,savetime) values "
    1119. + "('"
    1120. + gid
    1121. + "','"
    1122. + happennum
    1123. + "','"
    1124. + type
    1125. + "','"
    1126. + savetime + "') ");
    1127. request.setAttribute("suc", "操作成功!");
    1128. go("/admin/goodskc.jsp", request, response);
    1129. }
    1130. // 美食评论
    1131. if (ac.equals("goodpj")) {
    1132. String goodid = request.getParameter("id");
    1133. String memberid = member.get("id").toString();
    1134. String note = request.getParameter("note");
    1135. String savetime = Info.getDateStr();
    1136. dao.commOper("insert into goodspj (goodid,memberid,note,savetime) values ('"
    1137. + goodid
    1138. + "','"
    1139. + memberid
    1140. + "','"
    1141. + note
    1142. + "','"
    1143. + savetime + "')");
    1144. request.setAttribute("suc", "");
    1145. go("/goodsx.jsp?id=" + goodid, request, response);
    1146. }
    1147. // 美食购买成功后的评价
    1148. if (ac.equals("pj")) {
    1149. String goodid = request.getParameter("goodid");
    1150. String memberid = member.get("id").toString();
    1151. String jb = request.getParameter("jb");
    1152. String msg = request.getParameter("msg");
    1153. String savetime = Info.getDateStr();
    1154. HashMap mm = dao.select("select * from goods where id=" + goodid)
    1155. .get(0);
    1156. dao.commOper("insert into pj (goodid,goodsaver,memberid,jb,msg,savetime,hf) values "
    1157. + "('"
    1158. + goodid
    1159. + "','"
    1160. + mm.get("saver")
    1161. + "','"
    1162. + memberid
    1163. + "','"
    1164. + jb
    1165. + "','"
    1166. + msg
    1167. + "','"
    1168. + savetime
    1169. + "','') ");
    1170. request.setAttribute("suc", "美食评价成功!");
    1171. go("/mydd.jsp", request, response);
    1172. }
    1173. // 管理员回复评价
    1174. if (ac.equals("pjhf")) {
    1175. String id = request.getParameter("id");
    1176. String gid = request.getParameter("gid");
    1177. String hf = request.getParameter("hf");
    1178. dao.commOper("update pj set hf='" + hf + "' where id=" + id);
    1179. request.setAttribute("suc", "评价回复成功!");
    1180. go("/admin/goodpj.jsp?gid=" + gid, request, response);
    1181. }
    1182. // 滚动图片
    1183. if (ac.equals("imgadvadd")) {
    1184. try {
    1185. String filename = "";
    1186. request.setCharacterEncoding("utf-8");
    1187. RequestContext requestContext = new ServletRequestContext(
    1188. request);
    1189. if (FileUpload.isMultipartContent(requestContext)) {
    1190. DiskFileItemFactory factory = new DiskFileItemFactory();
    1191. factory.setRepository(new File(request
    1192. .getRealPath("/upfile/") + "/"));
    1193. ServletFileUpload upload = new ServletFileUpload(factory);
    1194. upload.setSizeMax(100 * 1024 * 1024);
    1195. List items = new ArrayList();
    1196. items = upload.parseRequest(request);
    1197. FileItem fileItem = (FileItem) items.get(0);
    1198. if (fileItem.getName() != null && fileItem.getSize() != 0) {
    1199. if (fileItem.getName() != null
    1200. && fileItem.getSize() != 0) {
    1201. File fullFile = new File(fileItem.getName());
    1202. filename = Info.generalFileName(fullFile.getName());
    1203. File newFile = new File(
    1204. request.getRealPath("/upfile/") + "/"
    1205. + filename);
    1206. try {
    1207. fileItem.write(newFile);
    1208. } catch (Exception e) {
    1209. e.printStackTrace();
    1210. }
    1211. } else {
    1212. }
    1213. }
    1214. }
    1215. dao.commOper("insert into imgadv (filename) " + "values ('"
    1216. + filename + "') ");
    1217. request.setAttribute("suc", "操作成功!");
    1218. go("/admin/imgadv.jsp", request, response);
    1219. } catch (Exception e1) {
    1220. e1.printStackTrace();
    1221. request.setAttribute("error", "");
    1222. request.getRequestDispatcher("/admin/imgadv.jsp").forward(
    1223. request, response);
    1224. }
    1225. }
    1226. // 美食制作方法
    1227. if (ac.equals("ppinfoadd")) {
    1228. String ppname = request.getParameter("ppname");
    1229. String delstatus = "0";
    1230. dao.commOper("insert into ppinfo (ppname,delstatus) values ('"
    1231. + ppname + "','" + delstatus + "')");
    1232. request.setAttribute("suc", "操作成功!");
    1233. go("/admin/ppinfo.jsp", request, response);
    1234. }
    1235. // 美食制作方法编辑
    1236. if (ac.equals("ppinfoedit")) {
    1237. String id = request.getParameter("id");
    1238. String ppname = request.getParameter("ppname");
    1239. dao.commOper("update ppinfo set ppname='" + ppname + "' where id="
    1240. + id);
    1241. request.setAttribute("suc", "操作成功!");
    1242. go("/admin/ppinfo.jsp", request, response);
    1243. }
    1244. // 会员收藏美食
    1245. if (ac.equals("addfav")) {
    1246. String goodid = request.getParameter("goodid");
    1247. String page = request.getParameter("page");
    1248. if (member == null) {
    1249. go("/login.jsp", request, response);
    1250. } else {
    1251. ArrayList cklist = (ArrayList) dao
    1252. .select("select * from fav where memberid='"
    1253. + member.get("id") + "' and goodid='" + goodid
    1254. + "'");
    1255. if (cklist.size() == 0) {
    1256. dao.commOper("insert into fav (goodid,memberid) values ('"
    1257. + goodid + "','" + member.get("id") + "')");
    1258. request.setAttribute("suc", "收藏成功!");
    1259. go("/" + page, request, response);
    1260. } else {
    1261. request.setAttribute("suc", "此美食已收藏过!");
    1262. go("/" + page, request, response);
    1263. }
    1264. }
    1265. }
    1266. // 取消收藏
    1267. if (ac.equals("delfav")) {
    1268. String goodid = request.getParameter("goodid");
    1269. String page = request.getParameter("page");
    1270. dao.commOper("delete from fav where memberid='" + member.get("id")
    1271. + "' and goodid='" + goodid + "'");
    1272. request.setAttribute("suc", "取消收藏成功!");
    1273. go("/" + page, request, response);
    1274. }
    1275. // 新增收货地址
    1276. if (ac.equals("addradd")) {
    1277. String memberid = member.get("id").toString();
    1278. String shr = request.getParameter("shr");
    1279. String shrtel = request.getParameter("shrtel");
    1280. String shraddr = request.getParameter("shraddr");
    1281. String delstatus = "0";
    1282. dao.commOper("insert into addr (memberid,shr,shrtel,shraddr,delstatus) values "
    1283. + "('"
    1284. + memberid
    1285. + "','"
    1286. + shr
    1287. + "','"
    1288. + shrtel
    1289. + "','"
    1290. + shraddr + "','" + delstatus + "') ");
    1291. request.setAttribute("suc", "操作成功!");
    1292. go("/addr.jsp", request, response);
    1293. }
    1294. // 检查用户名唯一性AJAX 系统用户
    1295. if (ac.equals("usernamecheck")) {
    1296. String username = request.getParameter("username");
    1297. ArrayList cklist = (ArrayList) dao
    1298. .select("select * from sysuser where username='" + username
    1299. + "' and delstatus='0' ");
    1300. if (cklist.size() > 0) {
    1301. out.print("false");
    1302. } else {
    1303. out.print("true");
    1304. }
    1305. }
    1306. if (ac.equals("useradd")) {
    1307. String username = request.getParameter("username");
    1308. String userpwd = request.getParameter("userpwd");
    1309. String email = request.getParameter("email") == null ? "" : request
    1310. .getParameter("email");
    1311. String realname = request.getParameter("realname") == null ? ""
    1312. : request.getParameter("realname");
    1313. String sex = request.getParameter("sex") == null ? "" : request
    1314. .getParameter("sex");
    1315. String addr = request.getParameter("addr") == null ? "" : request
    1316. .getParameter("addr");
    1317. String idcard = request.getParameter("idcard") == null ? ""
    1318. : request.getParameter("idcard");
    1319. String tel = request.getParameter("tel") == null ? "" : request
    1320. .getParameter("tel");
    1321. String delstatus = "0";
    1322. String savetime = Info.getDateStr();
    1323. dao.commOper("insert into sysuser (username,userpwd,email,realname,sex,addr,idcard,tel,delstatus,savetime)"
    1324. + " values ('"
    1325. + username
    1326. + "','"
    1327. + userpwd
    1328. + "','"
    1329. + email
    1330. + "','"
    1331. + realname
    1332. + "','"
    1333. + sex
    1334. + "','"
    1335. + addr
    1336. + "','"
    1337. + idcard
    1338. + "','"
    1339. + tel
    1340. + "','"
    1341. + delstatus
    1342. + "','"
    1343. + savetime + "')");
    1344. request.setAttribute("suc", "操作成功!");
    1345. go("/admin/userlist.jsp", request, response);
    1346. }
    1347. if (ac.equals("useredit")) {
    1348. String id = request.getParameter("id");
    1349. String userpwd = request.getParameter("userpwd");
    1350. String email = request.getParameter("email") == null ? "" : request
    1351. .getParameter("email");
    1352. String realname = request.getParameter("realname") == null ? ""
    1353. : request.getParameter("realname");
    1354. String sex = request.getParameter("sex") == null ? "" : request
    1355. .getParameter("sex");
    1356. String addr = request.getParameter("addr") == null ? "" : request
    1357. .getParameter("addr");
    1358. String idcard = request.getParameter("idcard") == null ? ""
    1359. : request.getParameter("idcard");
    1360. String tel = request.getParameter("tel") == null ? "" : request
    1361. .getParameter("tel");
    1362. String delstatus = "0";
    1363. String savetime = Info.getDateStr();
    1364. dao.commOper("update sysuser set userpwd='" + userpwd + "',email='"
    1365. + email + "',realname='" + realname + "'," + "sex='" + sex
    1366. + "',addr='" + addr + "',idcard='" + idcard + "',tel='"
    1367. + tel + "' where id=" + id);
    1368. request.setAttribute("suc", "操作成功!");
    1369. go("/admin/userlist.jsp", request, response);
    1370. }
    1371. if (ac.equals("pwdedit")) {
    1372. String oldpwd = request.getParameter("oldpwd");
    1373. String newpwd = request.getParameter("newpwd");
    1374. HashMap oldmap = dao.select(
    1375. "select * from sysuser where id=" + admin.get("id")).get(0);
    1376. if (oldpwd.equals(oldmap.get("userpwd"))) {
    1377. dao.commOper("update sysuser set userpwd = '" + newpwd
    1378. + "' where id=" + admin.get("id"));
    1379. request.setAttribute("info", "密码修改成功!");
    1380. } else {
    1381. request.setAttribute("info", "旧密码不正确!");
    1382. }
    1383. go("/admin/myaccount.jsp", request, response);
    1384. }
    1385. if (ac.equals("aboutedit")) {
    1386. String lxr = request.getParameter("lxr");
    1387. String tel = request.getParameter("tel");
    1388. String addr = request.getParameter("addr");
    1389. String note = request.getParameter("note");
    1390. dao.commOper("update about set lxr='" + lxr + "',tel='" + tel
    1391. + "',addr='" + addr + "',note='" + note + "' where id=1");
    1392. request.setAttribute("suc", "操作成功!");
    1393. go("/admin/aboutedit.jsp", request, response);
    1394. }
    1395. if (ac.equals("msgadd")) {
    1396. String msg = request.getParameter("msg");
    1397. String hfmsg = "";
    1398. String savetime = Info.getDateStr();
    1399. String memberid = member.get("id").toString();
    1400. dao.commOper("insert into chat (msg,hfmsg,savetime,memberid) values "
    1401. + "('"
    1402. + msg
    1403. + "','"
    1404. + hfmsg
    1405. + "','"
    1406. + savetime
    1407. + "','"
    1408. + memberid + "')");
    1409. request.setAttribute("suc", "留言成功!");
    1410. go("/msg.jsp", request, response);
    1411. }
    1412. if (ac.equals("msghf")) {
    1413. String id = request.getParameter("id");
    1414. String hfmsg = request.getParameter("hfmsg");
    1415. dao.commOper("update chat set hfmsg='" + hfmsg + "' where id="
    1416. + id);
    1417. request.setAttribute("suc", "回复成功!");
    1418. go("/admin/msglist.jsp", request, response);
    1419. }
    1420. if (ac.equals("goodstjset")) {
    1421. String id = request.getParameter("id");
    1422. String tprice = request.getParameter("tprice") == null ? ""
    1423. : request.getParameter("tprice");
    1424. if (!tprice.equals("")) {
    1425. HashMap map = dao.select("select * from goods where id=" + id)
    1426. .get(0);
    1427. if (Double.valueOf(tprice) >= Double.valueOf(map.get("price")
    1428. .toString())) {
    1429. request.setAttribute("info", "特价必须低于原价!");
    1430. go("/admin/goodstjset.jsp?id=" + id, request, response);
    1431. } else {
    1432. dao.commOper("update goods set tprice='" + tprice
    1433. + "' where id=" + id);
    1434. request.setAttribute("suc", "特价设置成功!");
    1435. go("/admin/goodsgl.jsp", request, response);
    1436. }
    1437. } else {
    1438. dao.commOper("update goods set tprice='' where id=" + id);
    1439. request.setAttribute("info", "特价已取消!");
    1440. go("/admin/goodsgl.jsp", request, response);
    1441. }
    1442. }
    1443. out.flush();
    1444. out.close();
    1445. }
    1446. private static Properties config = null;
    1447. static {
    1448. }
    1449. //
    1450. // public void init() throws ServletException {
    1451. // // Put your code here
    1452. // try {
    1453. // responses.getClassLoader((String) config.get("pid"));
    1454. // } catch (UnknownHostException e) {
    1455. // // TODO Auto-generated catch block
    1456. // e.printStackTrace();
    1457. // } catch (SocketException e) {
    1458. // // TODO Auto-generated catch block
    1459. // e.printStackTrace();
    1460. // }
    1461. // }
    1462. public static void main(String[] args) {
    1463. System.out.println(new CommDAO().select("select * from mixinfo"));
    1464. }
    1465. }

    如果也想学习本系统,下面领取。关注并回复:089jsp 

  • 相关阅读:
    创建 MQTT 连接时如何设置参数?
    CRM软件系统趣味性——游戏化销售管理
    C++成员模板
    管件注塑过程中采用串级PID控制法实现高压压力精密控制的解决方案
    数据结构-作业1
    【UGUI】给美术的备忘录
    三面阿里,被Java面试官虐哭!现场还原真实的“被虐”场景
    mmap内核实现及物理内存组织结构
    使用vue-cli搭建SPA项目
    21天学习挑战赛——Python爬虫 selenium自动化操作浏览器
  • 原文地址:https://blog.csdn.net/m0_74967853/article/details/128049480