日期:2014-05-18 浏览次数:20712 次
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> <title>Insert title here</title> </head> <body> <FORM METHOD=POST ACTION="uploadimage2.jsp"> 名称:<INPUT TYPE="text" NAME="name"><br> 图片:<INPUT TYPE="file" NAME="image"><br> <INPUT TYPE="submit" value="提交"> </FORM> </body> </html>
<%@ page contentType="text/html;charset=gb2312"%> <%@ page import="java.util.*"%> <%@ page import="java.text.*"%> <%@ page import="java.io.*"%> <%@ page import="com.sun.image.codec.jpeg.*"%> <%@ page import="java.awt.image.*"%> <%@ page import="java.awt.*"%> <% String name=request.getParameter("name"); name=new String(name.getBytes("ISO-8859-1")); String ima=request.getParameter("image"); try{ String path=request.getRealPath("/"); FileOutputStream ot=new FileOutputStream(path+name+".jpg"); FileInputStream in = new FileInputStream(ima); JPEGImageDecoder jpgCodec=JPEGCodec.createJPEGDecoder(in); BufferedImage image=jpgCodec.decodeAsBufferedImage(); JPEGImageEncoder encoder=JPEGCodec.createJPEGEncoder(ot); encoder.encode(image); in.close(); ot.close(); out.print("上传成功!<br>"); out.print("<IMG width=200 height=200 src='"+name+"'.jpg >"); } catch(Exception e) { System.out.print(e.toString()); } %>