首页>代码>jsp+Servlet+jcrop开发实现上传图片裁剪简单demo实例>/myupload/src/com/myupload/servlet/UploadImageServlet.java
package com.myupload.servlet; import java.awt.image.BufferedImage; import java.io.IOException; import javax.imageio.ImageIO; import javax.servlet.ServletConfig; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.jspsmart.upload.File; import com.jspsmart.upload.SmartUpload; import com.myupload.util.IPTimeStamp; public class UploadImageServlet extends HttpServlet { private static int S_width = 400; private static int S_height = 300; private ServletConfig config = null; private String FileName = null; private String sPath = "/initImage"; private String path = null; private java.io.File imageFile = null; private BufferedImage image = null; public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { SmartUpload mySmartUpload = new SmartUpload(); mySmartUpload.initialize(config, request, response); mySmartUpload.setMaxFileSize(2048 * 1024); mySmartUpload.setAllowedFilesList("jpg,gif,png,jpeg,bmp"); int width = S_width; int height = S_height; //PrintWriter out = response.getWriter(); try { mySmartUpload.upload(); File myFile = mySmartUpload.getFiles().getFile(0); if (!myFile.isMissing()) { IPTimeStamp its = new IPTimeStamp(request.getRemoteAddr()); FileName = its.getIPTimeRand(); String ext = myFile.getFileExt(); FileName = FileName + "." + ext; path = sPath + "/" + FileName; myFile.saveAs(sPath + "/" + FileName, mySmartUpload.SAVE_VIRTUAL); path = path.substring(1); System.out.println(request.getSession().getServletContext().getRealPath("/") + "========" + path); imageFile = new java.io.File(request.getSession().getServletContext().getRealPath("/") + path); image = ImageIO.read(imageFile); if(image.getWidth() < S_width) { width = image.getWidth(); } if(image.getHeight() < S_height) { height = image.getHeight(); } } response.sendRedirect("myupload.jsp?path=" + path + "&width=" + width + "&height=" + height); } catch (Exception e) { e.printStackTrace(); } } public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { this.doGet(request, response); } @Override public void init(ServletConfig config) throws ServletException { this.config = config; } }

7348449521111 LV1
2023年4月20日
zzh1 LV7
2022年11月8日
Mayoubin2001 LV21
2022年3月26日
松烟入墨2018 LV16
2020年7月13日
pharaohsprince LV1
2020年4月23日
KING QIN LV5
2020年3月3日
he88318799 LV16
2019年10月11日
cccnccc LV11
2019年6月4日
IanDiane666 LV1
2019年5月31日
仪万里 LV12
2019年5月9日

颜菜菜 LV2
2023年12月23日
WASDZZ LV13
2023年7月7日
7348449521111 LV1
2023年4月20日
itwgy001 LV2
2022年12月9日
softandroad
2022年11月7日
暂无贡献等级
zzh1 LV7
2022年11月5日
JohnAlex LV9
2022年4月21日
Mayoubin2001 LV21
2022年3月26日
12346678912334566
2022年1月8日
暂无贡献等级
zphhhh
2022年1月8日
暂无贡献等级