<rt id="bn8ez"></rt>
<label id="bn8ez"></label>

  • <span id="bn8ez"></span>

    <label id="bn8ez"><meter id="bn8ez"></meter></label>

    悟心

    成功不是將來(lái)才有的,而是從決定去做的那一刻起,持續(xù)累積而成。 上人生的旅途罷。前途很遠(yuǎn),也很暗。然而不要怕。不怕的人的面前才有路。

      BlogJava :: 首頁(yè) :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理 ::
      93 隨筆 :: 1 文章 :: 103 評(píng)論 :: 0 Trackbacks
    1.負(fù)責(zé)處理圖處的bean:
    //---------------------------------------------------------------
    package bean;

    import javax.imageio.ImageIO;
    import javax.imageio.IIOException;
    import java.awt.image.BufferedImage;
    import java.awt.Image;
    import java.io.File;
    import java.awt.image.AffineTransformOp;
    import java.awt.geom.AffineTransform;

    public class convertImage {


    private String fileInput ;
    private String fileOutput ;

    public convertImage()
    {

    }
    public String getFileInput() {
    return fileInput;
    }
    public 
    void setFileInput(String fileInput) {
    this.fileInput = fileInput;
    }
    public String getFileOutput() {
    return fileOutput;
    }
    public 
    void setFileOutput(String fileOutput) {
    this.fileOutput = fileOutput;
    }

    public 
    void convert()
    {
    try {
    File fi 
    = new File(fileInput); //大圖文件
    File fo = new File(fileOutput); //將要轉(zhuǎn)換出的小圖文件
    int nw = 150//定義寬為150
    int nh = 100//定義高為100
    AffineTransform transform = new AffineTransform();
    BufferedImage bis 
    = ImageIO.read(fi);
    int w = bis.getWidth();
    int h = bis.getHeight();

    double sx = (double)nw/w;
    double sy = (double)nh/h ;
    //判斷是橫向圖形還是堅(jiān)向圖形
    if ( w > h ) //橫向圖形
    {
    if ( (int)(sx * h ) > nh ) //比較高不符合高度要求,就按高度比例
    {

     

    sx 
    = sy ;
    nw 
    = (int)(w*sx) ;
    }
    else
    {
    sy 
    = sx ;
    nh 
    = (int)( h*sy) ;
    }
    }
    else
    {
    if ( (int)(sy * w ) > nw ) 
    {
    sy 
    = sx ;
    nh 
    = (int)(h * sy ) ;
    }
    else
    {
    sx 
    = sy ;
    nw 
    = (int)(w*sx) ;
    }
    }

    transform.setToScale(sx,sy);
    AffineTransformOp ato 
    = new AffineTransformOp(transform,null);
    BufferedImage bid 
    = new BufferedImage(nw,nh,BufferedImage.TYPE_3BYTE_BGR);
    ato.filter(bis,bid);
    ImageIO.write(bid,
    "jpeg",fo);

    catch(Exception e) 
    {
    e.printStackTrace();
    }

    }

    2.上傳文件的upload.jsp
    --------------------------------------------------------------------
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>

    <title>My JSP 'upload.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
    <html:form action="/upload.do" enctype="multipart/form-data">
    <html:file property="theFileone"/>
    <html:submit/>
    </html:form>

    </body>
    </html>
    //------------------------------------------------------------------------
    3.顯示成功頁(yè)面

    //------------------------------------------------------------------------
    <%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
    <%@ page contentType="text/html;charset=GB2312" %>
    <%
    String path 
    = request.getContextPath();
    String basePath 
    = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
    %>

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <html>
    <head>
    <base href="<%=basePath%>">

    <title>My JSP 'display.jsp' starting page</title>

    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">

    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->
    </head>

    <body>
    上傳成功. 
    <br>
    </body>
    </html>
    //---------------------------------------------------------------------
    4.Action 
    //Created by MyEclipse Struts
    //
     XSL source (default): platform:/plugin/com.genuitec.eclipse.cross.easystruts.eclipse_4.1.1/xslt/JavaClass.xsl

    package com.mk.struts.action;

    import java.io.
    *;


    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;

    import org.apache.struts.action.Action;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionForward;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.upload.FormFile;

    import com.mk.struts.form.UploadForm;

    import bean.convertImage;

    /*
    * MyEclipse Struts
    * Creation date: 03-28-2006

    * XDoclet definition:
    * @struts.action validate="true"
    */
    public class UploadAction extends Action {

    // --------------------------------------------------------- Instance Variables

    // --------------------------------------------------------- Methods

    /*
    * Method execute
    * @param mapping
    * @param form
    * @param request
    * @param response
    * @return ActionForward
    */
    public ActionForward execute(
    ActionMapping mapping,
    ActionForm form,
    HttpServletRequest request,
    HttpServletResponse response) {

    // TODO Auto-generated method stub
    String encoding = request.getCharacterEncoding() ;
    if ( (encoding != null )&& (encoding.equalsIgnoreCase("uft-8")))
    {
    response.setContentType(
    "text/html;charset=gb2312") ; //如果沒有找定編碼,編碼格式設(shè)為gb2312 
    }

    UploadForm theForm 
    = (UploadForm) form ;
    FormFile fileone 
    = theForm.getTheFileone() ; //取得上傳的文件名

    try
    {
    //開始上傳文件
    String filePath = this.getServlet().getServletContext().getRealPath("/") ; //取得當(dāng)前路徑
    InputStream stream = fileone.getInputStream() ; //把文件讀入
    ByteArrayOutputStream baos = new ByteArrayOutputStream() ;

    /*
    * 建立一個(gè)上傳文件的輸出流如果是linux系統(tǒng)請(qǐng)把"\\" 換成 "/"
    */
    OutputStream bos 
    = new FileOutputStream(filePath + fileone.getFileName()) ;

    request.setAttribute(
    "fileName",filePath + "/" + fileone.getFileName() ) ;
    int bytesRead = 0 ;
    byte[] buffer = new byte[8192] ;
    while( (bytesRead = stream.read(buffer,0,8192) ) != -1 )
    {
    bos.write(buffer,
    0,bytesRead) ;
    }

    bos.close();
    stream.close() ; 

    //上傳文件完成
    String oldurl= filePath + fileone.getFileName() ;
    String newurl
    = filePath + "min_" + fileone.getFileName() ; //新的縮略圖保存地址

    convertImage convert 
    = new convertImage() ;
    convert.setFileInput(oldurl) ;
    convert.setFileOutput(newurl) ;
    convert.convert() ;

    }

    catch(Exception e)
    {
    System.err.print(e) ;
    }
    return mapping.findForward("display");
    }

    }
    來(lái)源:http://www.ideagrace.com/html/doc/2006/04/21/00776.html
    posted on 2010-08-29 16:11 艾波 閱讀(425) 評(píng)論(0)  編輯  收藏 所屬分類: Application
    主站蜘蛛池模板: 免费一级全黄少妇性色生活片 | caoporm碰最新免费公开视频| 亚洲综合色区中文字幕| 亚洲精品高清国产麻豆专区| 久久亚洲国产视频| 亚洲视频免费在线观看| 亚洲天天做日日做天天欢毛片| 亚洲国产精品一区二区第一页| 久久夜色精品国产亚洲AV动态图 | 一区二区三区亚洲视频| 日韩亚洲国产综合久久久| 男人的天堂亚洲一区二区三区 | 久久综合国产乱子伦精品免费| 免费久久人人爽人人爽av| 中文成人久久久久影院免费观看| 波霸在线精品视频免费观看| 色播在线永久免费视频网站| 大地资源中文在线观看免费版| 99视频在线精品免费| 国产91色综合久久免费| 成年轻人网站色免费看| 国产免费变态视频网址网站| 又爽又高潮的BB视频免费看| 国产精品亚洲美女久久久| 亚洲欧洲日产国码无码网站| 亚洲AV无码日韩AV无码导航| 亚洲欧洲视频在线观看| 亚洲免费在线视频播放| 极品色天使在线婷婷天堂亚洲| 尤物视频在线免费观看| 久久免费动漫品精老司机| 最近中文字幕免费2019| 免费黄色app网站| 亚洲午夜日韩高清一区| 亚洲综合自拍成人| 2020天堂在线亚洲精品专区| 阿v免费在线观看| 野花香高清视频在线观看免费| 91精品免费国产高清在线| 国产亚洲精品免费| 亚洲av无码专区国产乱码在线观看|