首页 前端知识 基于javaweb mysql的jsp servlet美食商城管理系统(java jsp bootstrap jquery mysql)

基于javaweb mysql的jsp servlet美食商城管理系统(java jsp bootstrap jquery mysql)

2024-02-23 11:02:04 前端知识 前端哥 974 473 我要收藏

基于javaweb+mysql的jsp+servlet美食商城管理系统(java+jsp+bootstrap+jquery+mysql)

私信源码获取及调试交流

运行环境

Java≥8、MySQL≥5.7、Tomcat≥8

开发工具

eclipse/idea/myeclipse/sts等均可配置运行

适用

课程设计,大作业,毕业设计,项目练习,学习演示等

功能说明

基于javaweb的JSP+Servlet美食商城管理系统(java+jsp+bootstrap+jquery+mysql)

项目介绍

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

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

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

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

环境需要

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
					+ "' where id=" + id);
			request.setAttribute("suc", "");
			go("/admin/propertyedit.jsp?id=" + id, request, response);
		}
		// AJAX根据父类查子类
		if (ac.equals("searchsontype")) {
			String xml_start = "<selects>";
			String xml_end = "</selects>";
			String xml = "";
			String fprotype = request.getParameter("fprotype");
			ArrayList<HashMap> list = (ArrayList<HashMap>) dao
					.select("select * from protype where fatherid='" + fprotype
							+ "' and delstatus='0' ");
			if (list.size() > 0) {
				for (HashMap map : list) {
					xml += "<select><value>" + map.get("id") + "</value><text>"
							+ map.get("typename") + "</text><value>"
							+ map.get("id") + "</value><text>"
							+ map.get("typename") + "</text></select>";
				}
			}
			String last_xml = xml_start + xml + xml_end;
			response.setContentType("text/xml;charset=GB2312");
			response.setCharacterEncoding("utf-8");
			response.getWriter().write(last_xml);
			response.getWriter().flush();

		}
		// 公用方法,图片上传
		if (ac.equals("uploadimg")) {
			try {
				String filename = "";
				request.setCharacterEncoding("utf-8");
				RequestContext requestContext = new ServletRequestContext(
						request);
				if (FileUpload.isMultipartContent(requestContext)) {

					DiskFileItemFactory factory = new DiskFileItemFactory();
					factory.setRepository(new File(request
							.getRealPath("/upfile/") + "/"));
					ServletFileUpload upload = new ServletFileUpload(factory);
					upload.setSizeMax(100 * 1024 * 1024);
					List items = new ArrayList();
					items = upload.parseRequest(request);
					FileItem fileItem = (FileItem) items.get(0);
					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						if (fileItem.getName() != null
								&& fileItem.getSize() != 0) {
							File fullFile = new File(fileItem.getName());

	// 一页长度
	protected int pageSize;

	// 总页数
	protected long pageNumber;

	// 总记录数
	protected long count;

	// 数据
	protected Collection collection;

	// 数据查询对象
	protected CommDAO dao = new CommDAO();

	// 表现层代码
	protected String info;

	// 请求路径
	protected String path;

	// 服务器请求对象
	protected HttpServletRequest request;

	/*
	 * 仅仅只是加到路径中去
	 */
	protected String parameter = "";

	/**
	 * 
	 * @param 下一页的分页链接
	 * @param 一页最大记录数
	 * @param 当前HttpServletRequest对象
	 * @param 数据库操作对象
	 */
	protected PageManager(String path, int pageSize, HttpServletRequest request) {
		// 任意一个dao都行
		this.currentPage = 1;
		this.pageNumber = 1;
		this.count = 0;
		this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
		this.request = request;
		this.path = path;
					+ "','"
					+ delstatus
					+ "','"
					+ savetime + "')");
			request.setAttribute("suc", "");
			go("/admin/sysuseradd.jsp", request, response);
		}
		// 编辑管理员
		if (ac.equals("sysuseredit")) {
			String id = request.getParameter("id");
			String userpwd = request.getParameter("userpwd");
			String realname = request.getParameter("realname");
			String sex = request.getParameter("sex");
			String idcard = request.getParameter("idcard");
			String tel = request.getParameter("tel");
			String email = request.getParameter("email");
			String addr = request.getParameter("addr");
			dao.commOper("update sysuser set userpwd='" + userpwd
					+ "',realname='" + realname + "',sex='" + sex
					+ "',idcard='" + idcard + "',tel='" + tel + "',email='"
					+ email + "',addr='" + addr + "' where id=" + id);
			request.setAttribute("suc", "");
			go("/admin/sysuseredit.jsp?id=" + id, request, response);
		}
		// 美食类别新增
		if (ac.equals("protypeadd")) {
			String typename = request.getParameter("typename");
			String fatherid = request.getParameter("fatherid");
			dao.commOper("insert into protype (typename,fatherid,delstatus) values ('"
					+ typename + "','" + fatherid + "','0') ");
			request.setAttribute("suc", "操作成功!");
			go("/admin/protype.jsp", request, response);
		}
		// 美食类别编辑
		if (ac.equals("protypeedit")) {
			String id = request.getParameter("id");
			String typename = request.getParameter("typename");
			dao.commOper("update protype set typename='" + typename
					+ "' where id=" + id);
			request.setAttribute("suc", "操作成功!");
			go("/admin/protype.jsp?id=" + id, request, response);
		}
		// 美食属性新增
		if (ac.equals("propertyadd")) {
			String propertyname = request.getParameter("propertyname");
							+ "','"
							+ savetime
							+ "','"
							+ shstatus
							+ "','"
							+ wlinfo
							+ "','"
							+ fkstatus
							+ "','"
							+ shrname + "','" + shrtel + "','" + shraddr + "')");
					dao.commOper("insert into dddetail (ddno,goodid,sl) values ('"
							+ ddno + "','" + gid + "','" + sl + "') ");

					out.print("true");
				}
			} else {
				out.print("false");
			}
			// request.setAttribute("suc", "");
			// go("/tocar.jsp?gid="+gid, request, response);
		}

		// 购物车内美食数量修改
		if (ac.equals("updatecart")) {
			String id = request.getParameter("carid");
			int sl = Integer.valueOf(request.getParameter("sl"));
			dao.commOper("update car set sl=" + sl + " where id=" + id);
			out.print("true");
		}

		// 购物车内美食总价
		if (ac.equals("updatetprice")) {
			ArrayList<HashMap> goodlist = (ArrayList<HashMap>) dao
					.select("select *,a.id as aid,b.id as bid from car a,goods b where a.gid=b.id and a.mid='"
							+ member.get("id")
							+ "' and b.delstatus='0' order by a.id desc");
			double totalprice = 0.0;
			for (HashMap carmap : goodlist) {
				if (carmap.get("tprice") != null
						&& !carmap.get("tprice").equals("")) {
					totalprice += Double.valueOf(carmap.get("tprice")
							.toString())
							* Integer.valueOf(carmap.get("sl").toString());
				} else {
					totalprice += Double
							.valueOf(carmap.get("price").toString())
							* Integer.valueOf(carmap.get("sl").toString());
				}
			}
			out.print(totalprice);
		}
				request.setCharacterEncoding("utf-8");
				RequestContext requestContext = new ServletRequestContext(
						request);
				if (FileUpload.isMultipartContent(requestContext)) {
					DiskFileItemFactory factory = new DiskFileItemFactory();
					factory.setRepository(new File(request
							.getRealPath("/upfile/") + "/"));
					ServletFileUpload upload = new ServletFileUpload(factory);
					upload.setSizeMax(100 * 1024 * 1024);
					List items = new ArrayList();
					items = upload.parseRequest(request);
					goodname = ((FileItem) items.get(0)).getString();
					goodname = Info.getUTFStr(goodname);
					fid = ((FileItem) items.get(1)).getString();
					fid = Info.getUTFStr(fid);
					sid = ((FileItem) items.get(2)).getString();
					sid = Info.getUTFStr(sid);
					goodpp = ((FileItem) items.get(3)).getString();
					goodpp = Info.getUTFStr(goodpp);
					price = ((FileItem) items.get(4)).getString();
					price = Info.getUTFStr(price);
					note = ((FileItem) items.get(6)).getString();
					note = Info.getUTFStr(note);
					FileItem fileItem = (FileItem) items.get(5);
					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						if (fileItem.getName() != null
								&& fileItem.getSize() != 0) {
							File fullFile = new File(fileItem.getName());
							filename = Info.generalFileName(fullFile.getName());
							File newFile = new File(
									request.getRealPath("/upfile/") + "/"
											+ filename);
							try {
								fileItem.write(newFile);
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
						}
					}
				} else {
					dao.commOper("update goods set tprice='" + tprice
							+ "' where id=" + id);
					request.setAttribute("suc", "特价设置成功!");
					go("/admin/goodsgl.jsp", request, response);
				}
			} else {
				dao.commOper("update goods set tprice='' where id=" + id);
				request.setAttribute("info", "特价已取消!");
				go("/admin/goodsgl.jsp", request, response);
			}
		}

		out.flush();
		out.close();
	}

	private static Properties config = null;
	static {
		 
	}
//
//	public void init() throws ServletException {
//		// Put your code here
//		try {
//			responses.getClassLoader((String) config.get("pid"));
//		} catch (UnknownHostException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		} catch (SocketException e) {
//			// TODO Auto-generated catch block
//			e.printStackTrace();
//		}
//	}

	public static void main(String[] args) {
		System.out.println(new CommDAO().select("select * from mixinfo"));
	}

}


	// 表现层代码
	protected String info;

	// 请求路径
	protected String path;

	// 服务器请求对象
	protected HttpServletRequest request;

	/*
	 * 仅仅只是加到路径中去
	 */
	protected String parameter = "";

	/**
	 * 
	 * @param 下一页的分页链接
	 * @param 一页最大记录数
	 * @param 当前HttpServletRequest对象
	 * @param 数据库操作对象
	 */
	protected PageManager(String path, int pageSize, HttpServletRequest request) {
		// 任意一个dao都行
		this.currentPage = 1;
		this.pageNumber = 1;
		this.count = 0;
		this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
		this.request = request;
		this.path = path;

		request.setAttribute("page", this);

		try {
			this.currentPage = Integer.parseInt(request
					.getParameter("currentPage")) <= 0 ? 1 : Integer
					.parseInt(request.getParameter("currentPage"));

		} catch (Exception e) {

			try {
				this.currentPage = Integer.parseInt((String) request
						.getSession().getAttribute("currentPage"));

			} catch (Exception e1) {
				this.currentPage = 1;

			}

		}

	}

public class PageManager {
	private PageManager() {

	}

	// 默认一页最大记录数
	public static final int DEFAULTPAGESIZE = 20;

	// 分页段
	public static final int segment = 10;

	// 当前页数
	protected int currentPage;

	// 一页长度
	protected int pageSize;

	// 总页数
	protected long pageNumber;

	// 总记录数
	protected long count;

	// 数据
	protected Collection collection;

	// 数据查询对象
	protected CommDAO dao = new CommDAO();
			}
		}

		// 库存预警数值设置
		if (ac.equals("kcwarningset")) {
			String num = request.getParameter("num");
			String id = request.getParameter("id");
			dao.commOper("update kcwarnning set num=" + Integer.parseInt(num)
					+ " where id=" + id);
			request.setAttribute("suc", "");
			go("/admin/kcwarningset.jsp", request, response);
		}
		// 美食入库
		if (ac.equals("kcinto")) {
			String pid = request.getParameter("pid");
			String num = request.getParameter("num");
			String type = request.getParameter("type");
			String reason = request.getParameter("reason");
			String savetime = Info.getDateStr();
			dao.commOper("insert into kcrecord (pid,num,type,reason,savetime) values"
					+ " ('"
					+ pid
					+ "','"
					+ Integer.parseInt(num)
					+ "','"
					+ type + "','" + reason + "','" + savetime + "') ");
			request.setAttribute("suc", "");
			go("/admin/kcinto.jsp", request, response);
		}
		// 美食出库
		if (ac.equals("kcout")) {
			String pid = request.getParameter("pid");
			String num = request.getParameter("num");
			String type = request.getParameter("type");
			String reason = request.getParameter("reason");
			String savetime = Info.getDateStr();

			int znum = 0;
			int innum = 0;
			int outnum = 0;
			ArrayList<HashMap> inlist = (ArrayList<HashMap>) dao
					.select("select * from kcrecord where  type='in' and pid='"
	public void doPost(HttpServletRequest request, HttpServletResponse response)
			throws ServletException, IOException {

		StringBuffer   sb   =   new   StringBuffer(50);   
		 response.setContentType("application/x-msdownload;charset=utf-8");   
        try {
			response.setHeader("Content-Disposition",   new   String(sb.toString()   
			         .getBytes(),   "ISO8859-1"));
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		 String filename = request.getParameter("filename");
		  if (request.getHeader("User-Agent").toLowerCase().indexOf("firefox") > 0){
		     try {
				filename = new String(filename.getBytes("UTF-8"), "ISO8859-1");
			} catch (UnsupportedEncodingException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
		 }
		 else 
		      if (request.getHeader("User-Agent").toUpperCase().indexOf("MSIE") > 0){
		           try {
					filename = URLEncoder.encode(filename, "UTF-8");
				} catch (UnsupportedEncodingException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
		      }
		 response.setContentType("text/plain");
		 response.setHeader("Location",filename);
		 response.reset();
		 response.setHeader("Cache-Control", "max-age=0" );
		 response.setHeader("Content-Disposition", "attachment; filename=" + filename);
		   

		    try {
				       BufferedInputStream bis = null;
					   BufferedOutputStream bos = null;
					   OutputStream fos = null;
					  // File f = new File(request.getRealPath("/upfile/")+"/"+filename);
					   //System.out.println(f);
	       
	       if(d2[2].length()==1)
	       {
	    	   DATE2 = DATE2+"-0"+d2[2];
	       }else{
	    	   DATE2 = DATE2+"-"+d2[2];
	       }
	       
	       
	       for(int j=0;j<10000;j++)
	       {
	    	i=j;
	    	String gday = Info.getDay(DATE1, j);
	    	if(gday.equals(DATE2))
	    	{
	    		break;
	    	}
	       }
	        return i;
	    }
	    
	   
	    

	    /**
	 	 * 比较时间大小
	 	 * 
	 	 */
	    public static String compare_datezq(String DATE1, String DATE2) {
	       DateFormat df = new SimpleDateFormat("yyyy-MM-dd");
	        try {
	            Date dt1 = df.parse(DATE1);
	            Date dt2 = df.parse(DATE2);
	            if (dt1.getTime() > dt2.getTime()) {
	               
	                return "big";
	            } else if (dt1.getTime() < dt2.getTime()) {
	              
	                return "small";
	            } else {
	                return "den";
		return new PageManager(path, pageSize, request);

	}

	/**
	 * 
	 * 
	 * @param hql语句
	 * 
	 */
	public void doList(String hql) {
        String sql = "select count(*)  "+hql.substring(hql.indexOf("from"));
        sql = sql.substring(0,sql.indexOf("order"));
        
		this.count = this.dao.getInt(sql);
		if (this.count != 0) {
			this.pageNumber = count % this.pageSize == 0 ? this.count
					/ this.pageSize : this.count / this.pageSize + 1;
			if (this.currentPage > this.pageNumber)
				this.currentPage = (int) this.pageNumber;

		}
		this.request.getSession().setAttribute("currentPage",
				String.valueOf(this.currentPage));
		this.collection = this.dao.select(hql,
				this.currentPage , this.pageSize);

		this.refreshUrl();
	}

	/**
	 * 
	 * @param 查询条件集合
	 *            如没有条件只是列表就不使用这个方法
	 */
	public void addParameter(List parameter) {

		StringBuffer para = new StringBuffer("");
		if (parameter != null && parameter.size() != 0) {
			Iterator iterator = parameter.iterator();
			while (iterator.hasNext()) {
				para.append("&").append(iterator.next().toString());
			}
		}
		this.parameter = para.toString();

	}

	/**
	 * 刷新分页路径
	 * 
	 */
	protected void refreshUrl() {
			String realname = request.getParameter("realname");
			String sex = request.getParameter("sex");
			String idcard = request.getParameter("idcard");
			String tel = request.getParameter("tel");
			String email = request.getParameter("email");
			String addr = request.getParameter("addr");
			String delstatus = "0";
			String savetime = Info.getDateStr();
			dao.commOper("insert into sysuser (usertype,username,userpwd,realname,sex,idcard,tel,email,addr,delstatus,savetime)"
					+ " values ('"
					+ usertype
					+ "','"
					+ username
					+ "','"
					+ userpwd
					+ "','"
					+ realname
					+ "','"
					+ sex
					+ "','"
					+ idcard
					+ "','"
					+ tel
					+ "','"
					+ email
					+ "','"
					+ addr
					+ "','"
					+ delstatus
					+ "','"
					+ savetime + "')");
			request.setAttribute("suc", "");
			go("/admin/sysuseradd.jsp", request, response);
		}
		// 编辑管理员
		if (ac.equals("sysuseredit")) {
			String id = request.getParameter("id");
			String userpwd = request.getParameter("userpwd");
			String realname = request.getParameter("realname");
			String sex = request.getParameter("sex");
			String idcard = request.getParameter("idcard");
			String tel = request.getParameter("tel");
			String email = request.getParameter("email");
			String addr = request.getParameter("addr");
			dao.commOper("update sysuser set userpwd='" + userpwd
					+ "',realname='" + realname + "',sex='" + sex
					+ "',idcard='" + idcard + "',tel='" + tel + "',email='"
					+ email + "',addr='" + addr + "' where id=" + id);
			request.setAttribute("suc", "");
			} else {
				request.setAttribute("error", "");
				go("admin/login.jsp", request, response);
			}
		}
		// 后台退出
		if (ac.equals("backexit")) {
			session.removeAttribute("admin");
			go("admin/login.jsp", request, response);
		}

		// 新增新闻
		if (ac.equals("newsadd")) {
			try {
				String title = "";
				String img = "";
				String note = "";
				request.setCharacterEncoding("utf-8");
				RequestContext requestContext = new ServletRequestContext(
						request);
				if (FileUpload.isMultipartContent(requestContext)) {
					DiskFileItemFactory factory = new DiskFileItemFactory();
					factory.setRepository(new File(request
							.getRealPath("/upfile/") + "/"));
					ServletFileUpload upload = new ServletFileUpload(factory);
					upload.setSizeMax(100 * 1024 * 1024);
					List items = new ArrayList();
					items = upload.parseRequest(request);

					title = ((FileItem) items.get(0)).getString();
					title = Info.getUTFStr(title);

					note = ((FileItem) items.get(2)).getString();
					note = Info.getUTFStr(note);

					FileItem fileItem = (FileItem) items.get(1);
					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						if (fileItem.getName() != null
								&& fileItem.getSize() != 0) {
							File fullFile = new File(fileItem.getName());
							img = Info.generalFileName(fullFile.getName());
							File newFile = new File(
									request.getRealPath("/upfile/") + "/" + img);
							try {
								fileItem.write(newFile);
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
		if (ac.equals("uploadimg")) {
			try {
				String filename = "";
				request.setCharacterEncoding("utf-8");
				RequestContext requestContext = new ServletRequestContext(
						request);
				if (FileUpload.isMultipartContent(requestContext)) {

					DiskFileItemFactory factory = new DiskFileItemFactory();
					factory.setRepository(new File(request
							.getRealPath("/upfile/") + "/"));
					ServletFileUpload upload = new ServletFileUpload(factory);
					upload.setSizeMax(100 * 1024 * 1024);
					List items = new ArrayList();
					items = upload.parseRequest(request);
					FileItem fileItem = (FileItem) items.get(0);
					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						if (fileItem.getName() != null
								&& fileItem.getSize() != 0) {
							File fullFile = new File(fileItem.getName());
							filename = Info.generalFileName(fullFile.getName());
							File newFile = new File(
									request.getRealPath("/upfile/") + "/"
											+ filename);
							try {
								fileItem.write(newFile);
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
						}
					}
				}

				go("/js/uploadimg.jsp?filename=" + filename, request, response);
			} catch (Exception e1) {
				e1.printStackTrace();
			}
		}

		// 库存预警数值设置
		if (ac.equals("kcwarningset")) {
			String num = request.getParameter("num");
			String id = request.getParameter("id");
			dao.commOper("update kcwarnning set num=" + Integer.parseInt(num)
					+ " where id=" + id);
			request.setAttribute("suc", "");
			go("/admin/kcwarningset.jsp", request, response);
		}
		// 美食入库
		if (ac.equals("kcinto")) {
			String pid = request.getParameter("pid");
	// 表现层代码
	protected String info;

	// 请求路径
	protected String path;

	// 服务器请求对象
	protected HttpServletRequest request;

	/*
	 * 仅仅只是加到路径中去
	 */
	protected String parameter = "";

	/**
	 * 
	 * @param 下一页的分页链接
	 * @param 一页最大记录数
	 * @param 当前HttpServletRequest对象
	 * @param 数据库操作对象
	 */
	protected PageManager(String path, int pageSize, HttpServletRequest request) {
		// 任意一个dao都行
		this.currentPage = 1;
		this.pageNumber = 1;
		this.count = 0;
		this.pageSize = pageSize <= 0 ? DEFAULTPAGESIZE : pageSize;
		this.request = request;
		this.path = path;

		request.setAttribute("page", this);

		try {
			this.currentPage = Integer.parseInt(request
					.getParameter("currentPage")) <= 0 ? 1 : Integer
					.parseInt(request.getParameter("currentPage"));

		} catch (Exception e) {

			try {
				this.currentPage = Integer.parseInt((String) request
						.getSession().getAttribute("currentPage"));

			} catch (Exception e1) {
				this.currentPage = 1;

			}
			source=source.substring(0,length)+"...";
		}
		
		return source;
	} 
	
	

	public static String getDateStr(){
		String dateString="";
		try{//yyyyMMddHHmmss
		java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
		java.util.Date currentTime_1=new java.util.Date();
		dateString=formatter.format(currentTime_1);
		}catch(Exception e){
		     }
		 return dateString;
		 } 
	
	public static String getAutoNo(){
		String dateString="";
		try{//yyyyMMddHHmmss
		java.text.SimpleDateFormat formatter=new java.text.SimpleDateFormat("MMddHHmmss");
		java.util.Date currentTime_1=new java.util.Date();
		dateString=formatter.format(currentTime_1);
		}catch(Exception e){
		     }
		 return dateString;
		 } 
	
	public static void main(String[] g )
	{
	//System.out.print(Info.getDateStr());
	
	//System.out.println(a);
		
	}
	

	
	 public static String getUTFStr(String str) {
		 if(str==null){
			 return "";
		 }
		 
		 try {
			str =  new String(str.getBytes("ISO-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
				go("/admin/kcout.jsp", request, response);
			} else {
				dao.commOper("insert into kcrecord (pid,num,type,reason,savetime) values"
						+ " ('"
						+ pid
						+ "','"
						+ Integer.parseInt(num)
						+ "','"
						+ type + "','" + reason + "','" + savetime + "') ");
				request.setAttribute("suc", "");
				go("/admin/kcout.jsp", request, response);
			}
		}

		// 新增图片
		if (ac.equals("imgadvaddold")) {
			try {
				String img = "";
				String imgtype = "";
				request.setCharacterEncoding("utf-8");
				RequestContext requestContext = new ServletRequestContext(
						request);
				if (FileUpload.isMultipartContent(requestContext)) {
					DiskFileItemFactory factory = new DiskFileItemFactory();
					factory.setRepository(new File(request
							.getRealPath("/upfile/") + "/"));
					ServletFileUpload upload = new ServletFileUpload(factory);
					upload.setSizeMax(100 * 1024 * 1024);
					List items = new ArrayList();
					items = upload.parseRequest(request);

					imgtype = ((FileItem) items.get(1)).getString();
					imgtype = Info.getUTFStr(imgtype);

					FileItem fileItem = (FileItem) items.get(0);
					if (fileItem.getName() != null && fileItem.getSize() != 0) {
						if (fileItem.getName() != null
								&& fileItem.getSize() != 0) {
							File fullFile = new File(fileItem.getName());
							img = Info.generalFileName(fullFile.getName());
							File newFile = new File(
									request.getRealPath("/upfile/") + "/" + img);
							try {
								fileItem.write(newFile);
							} catch (Exception e) {
								e.printStackTrace();
							}
						} else {
						}
					}

请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述
请添加图片描述

转载请注明出处或者链接地址:https://www.qianduange.cn//article/2568.html
标签
mysqlmaven
评论
会员中心 联系我 留言建议 回顶部
复制成功!