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

📄 addthings_do.jsp

📁 宠物网站jsp
💻 JSP
字号:
<%@ page contentType="text/html;charset=GBK" pageEncoding="gb2312"  import ="java.util.*"%><%@ page import ="java.sql.*,cn.wy.Pet.Things,cn.wy.DBConnection,org.lxh.smart.Request,cn.wy.Pet.User" %><jsp:useBean id="up" scope="page" class="org.lxh.smart.SmartUpload"/><%                 HttpSession s = request.getSession();        User user = (User)s.getAttribute("user");        DBConnection dbc = null ;        String sql ="";        String msgStr = "";        String forUrl = "adminiindex.jsp";        String imgPath = "";        boolean isView = false ;        boolean isViewPrice =false ;        //是修改还是添加        int isUpdata = 0;        try {            up.initialize(pageContext) ;            up.upload() ;            Request req = up.getRequest();                            boolean flageShoping = true;                        //是修改还是添加            isUpdata = Integer.parseInt(req.getParameter("isUpdata"));             //取出单选按扭的值            String vstr[] = req.getParameterValues("isView");                 //如果第一个选重            if(vstr[0].equals("1"))                isView = true ;            String vpstr[] = req.getParameterValues("isViewPrice");            if (vpstr[0].equals("1"))                isViewPrice = true;            String ext = up.getFiles().getFile(0).getFileExt();            //指定图片路径            String PhotoPath = "";                        //确定是否选择了图片//System.out.println("isMissing:" + up.getFiles().getFile(0).isMissing());            //如果有文件            if (!up.getFiles().getFile(0).isMissing())            {                //是修改或者是以前没有图片的情况                if (isUpdata == 0 | req.getParameter("imgPath").length()<13)                    PhotoPath = "/upPetImages/"+ "Things" + String.valueOf(System.currentTimeMillis()) + "." + ext ;                else                    PhotoPath = "/upPetImages/"+  req.getParameter("imgPath");                    PhotoPath.replaceAll("\'","");                //判断文件大小最大1M,类型必须是图片类型                if (up.getFiles().getFile(0).getSize()<=1048576 & up.getFiles().getFile(0).getTypeMIME().equals("image"))                {                                    //验证成功,开始上传文件                    up.getFiles().getFile(0).saveAs(PhotoPath);                    System.out.println("文件上传成功");                    imgPath = "sttpath='" + PhotoPath + "'," ;                }else                {                    //文件不符合规定返回到上一个页面                     out.print("<script>alert('文件不合法,文件大小必须在1M以内,必须是图片(如 jpg,gif,png)')</script>");                    out.print("<script>history.go(-1)</script>");                    return ;                }            }            PreparedStatement ps = null ;            dbc = new DBConnection();            //开始提交表单信息                                   //如果是更新宠物的信息            if (req.getParameter("editThingId") != null & isUpdata == 1)            {                                sql = "update Things set stname=?," + imgPath + " stspprice=?,stsaleprice=?,sttdate=getdate(),uname=?,sttremark=?,isview=?,isviewprice=? where stthingsid=?";                ps = dbc.getCon().prepareStatement(sql);                ps.setString(1, req.getParameter("thName"));                ps.setFloat(2, Float.parseFloat(req.getParameter("spprice")));                ps.setFloat(3, Float.parseFloat(req.getParameter("spsellprice")));                ps.setString(4, "admin");                ps.setString(5, req.getParameter("thremark") + "");                ps.setBoolean(6, isView);                ps.setBoolean(7, isViewPrice);                ps.setInt(8,Integer.parseInt(req.getParameter("editThingId")));                ps.executeUpdate();                ps.close();                                    msgStr = "修改";                //取出该宠物所在的页                                forUrl = "petList.jsp?pageNo=" + req.getParameter("pageNo");                System.out.println("更新成功! ");            }            //否则就是添加宠物            else{                sql = "insert into Things(stname,sttpath,stspprice,stsaleprice,uname,sttremark,isview,isviewprice)values(?,?,?,?,?,?,?,?)";                ps = dbc.getCon().prepareStatement(sql);                ps.setString(1, req.getParameter("thName"));                ps.setString(2, PhotoPath);                ps.setFloat(3, Float.parseFloat(req.getParameter("spprice")));                ps.setFloat(4, Float.parseFloat(req.getParameter("spsellprice")));                ps.setString(5, user.getUName());//测试用                ps.setString(6, req.getParameter("thremark") + "");                ps.setBoolean(7, isView);                ps.setBoolean(8, isViewPrice);                ps.executeUpdate();                ps.close();                    msgStr = "添加" ;                System.out.println("东西添加成功!");                                forUrl = "addThings.jsp";            }        }catch(Exception e)        {            //添加失败,浏览器后退            out.print("<script>alert('表单信息错误,增加宠物用品失败,请检查您填写的信息无误。');history.go(-1)</script>");            e.printStackTrace();}        finally        {            if (dbc != null)                dbc.dbClose();        }        out.print("<script>alert('宠物用品" + msgStr + "成功!');history.go(-1)</script>");       %>

⌨️ 快捷键说明

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