锘??xml version="1.0" encoding="utf-8" standalone="yes"?>国产成人免费视频,欧美日本久久,欧美在线wwwhttp://www.aygfsteel.com/blueoxygen/category/3743.htmlBlue keywords,Green comment,Red breakpoint,my life is also colorfulzh-cnSat, 03 Mar 2007 09:22:44 GMTSat, 03 Mar 2007 09:22:44 GMT60[collection]struts download Actionhttp://www.aygfsteel.com/blueoxygen/archive/2005/12/07/22894.htmlBlueO2BlueO2Wed, 07 Dec 2005 09:21:00 GMThttp://www.aygfsteel.com/blueoxygen/archive/2005/12/07/22894.htmlhttp://www.aygfsteel.com/blueoxygen/comments/22894.htmlhttp://www.aygfsteel.com/blueoxygen/archive/2005/12/07/22894.html#Feedback0http://www.aygfsteel.com/blueoxygen/comments/commentRss/22894.htmlhttp://www.aygfsteel.com/blueoxygen/services/trackbacks/22894.html/*
* $Id: DownloadAction.java 164530 2005-04-25 03:11:07Z niallp $
*
* Copyright 2004-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
*      http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/



package org.apache.struts.actions;

import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;

import javax.servlet.ServletContext;
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;


/**
* This is an abstract base class that minimizes the amount of special coding
* that needs to be written to download a file. All that is required to use
* this class is to extend it and implement the <code>getStreamInfo()</code>
* method so that it returns the relevant information for the file (or other
* stream) to be downloaded. Optionally, the <code>getBufferSize()</code>
* method may be overridden to customize the size of the buffer used to
* transfer the file.
*
* @since Struts 1.2.6
*/

public abstract class DownloadAction extends Action {

    /**
     * If the <code>getBufferSize()</code> method is not overridden, this is
     * the buffer size that will be used to transfer the data to the servlet
     * output stream.
     */

    protected static final int DEFAULT_BUFFER_SIZE = 1024 * 4;

    /**
     * Returns the information on the file, or other stream, to be downloaded
     * by this action. This method must be implemented by an extending class.
     *
     * @param mapping  The ActionMapping used to select this instance.
     * @param form     The optional ActionForm bean for this request (if any).
     * @param request  The HTTP request we are processing.
     * @param response The HTTP response we are creating.
     *
     * @return The information for the file to be downloaded.
     *
     * @throws Exception if an exception occurs.
     */

    protected abstract StreamInfo getStreamInfo(ActionMapping mapping,
            ActionForm form, HttpServletRequest request,
            HttpServletResponse response)
            throws Exception;

    /**
     * Returns the size of the buffer to be used in transferring the data to
     * the servlet output stream. This method may be overridden by an extending
     * class in order to customize the buffer size.
     *
     * @return The size of the transfer buffer, in bytes.
     */

    protected int getBufferSize() {
        return DEFAULT_BUFFER_SIZE;
    }

    /**
     * Process the specified HTTP request, and create the corresponding HTTP
     * response (or forward to another web component that will create it).
     * Return an <code>ActionForward</code> instance describing where and how
     * control should be forwarded, or <code>null</code> if the response has
     * already been completed.
     *
     * @param mapping  The ActionMapping used to select this instance.
     * @param form     The optional ActionForm bean for this request (if any).
     * @param request  The HTTP request we are processing.
     * @param response The HTTP response we are creating.
     *
     * @throws Exception if an exception occurs.
     */

    public ActionForward execute(ActionMapping mapping, ActionForm form,
            HttpServletRequest request, HttpServletResponse response)
            throws Exception {

        StreamInfo info = getStreamInfo(mapping, form, request, response);
        String contentType = info.getContentType();
        InputStream stream = info.getInputStream();

        try {
            response.setContentType(contentType);
            copy(stream, response.getOutputStream());
        } finally {
            if (stream != null) {
                stream.close();
            }
        }

        // Tell Struts that we are done with the response.
        return null;
    }

    /**
     * Copy bytes from an <code>InputStream</code> to an
     * <code>OutputStream</code>.
     *
     * @param input  The <code>InputStream</code> to read from.
     * @param output The <code>OutputStream</code> to write to.
     *
     * @return the number of bytes copied
     *
     * @throws IOException In case of an I/O problem
     */

    public int copy(InputStream input, OutputStream output)
            throws IOException {
        byte[] buffer = new byte[getBufferSize()];
        int count = 0;
        int n = 0;
        while (-1 != (n = input.read(buffer))) {
            output.write(buffer, 0, n);
            count += n;
        }
        return count;
    }

    /**
     * The information on a file, or other stream, to be downloaded by the
     * <code>DownloadAction</code>.
     */

    public static interface StreamInfo {

        /**
         * Returns the content type of the stream to be downloaded.
         *
         * @return The content type of the stream.
         */

        public abstract String getContentType();

        /**
         * Returns an input stream on the content to be downloaded. This stream
         * will be closed by the <code>DownloadAction</code>.
         *
         * @return The input stream for the content to be downloaded.
         */

        public abstract InputStream getInputStream() throws IOException;
    }

    /**
     * A concrete implementation of the <code>StreamInfo</code> interface which
     * simplifies the downloading of a file from the disk.
     */

    public static class FileStreamInfo implements StreamInfo {

        /**
         * The content type for this stream.
         */

        private String contentType;

        /**
         * The file to be downloaded.
         */

        private File file;

        /**
         * Constructs an instance of this class, based on the supplied
         * parameters.
         *
         * @param contentType The content type of the file.
         * @param file        The file to be downloaded.
         */

        public FileStreamInfo(String contentType, File file) {
            this.contentType = contentType;
            this.file = file;
        }

        /**
         * Returns the content type of the stream to be downloaded.
         *
         * @return The content type of the stream.
         */

        public String getContentType() {
            return this.contentType;
        }

        /**
         * Returns an input stream on the file to be downloaded. This stream
         * will be closed by the <code>DownloadAction</code>.
         *
         * @return The input stream for the file to be downloaded.
         */

        public InputStream getInputStream() throws IOException {
            FileInputStream fis = new FileInputStream(file);
            BufferedInputStream bis = new BufferedInputStream(fis);
            return bis;
        }
    }

    /**
     * A concrete implementation of the <code>StreamInfo</code> interface which
     * simplifies the downloading of a web application resource.
     */

    public static class ResourceStreamInfo implements StreamInfo {

        /**
         * The content type for this stream.
         */

        private String contentType;

        /**
         * The servlet context for the resource to be downloaded.
         */

        private ServletContext context;

        /**
         * The path to the resource to be downloaded.
         */

        private String path;

        /**
         * Constructs an instance of this class, based on the supplied
         * parameters.
         *
         * @param contentType The content type of the file.
         * @param context     The servlet context for the resource.
         * @param path        The path to the resource to be downloaded.
         */

        public ResourceStreamInfo(String contentType, ServletContext context,
                String path) {
            this.contentType = contentType;
            this.context = context;
            this.path = path;
        }

        /**
         * Returns the content type of the stream to be downloaded.
         *
         * @return The content type of the stream.
         */

        public String getContentType() {
            return this.contentType;
        }

        /**
         * Returns an input stream on the resource to be downloaded. This stream
         * will be closed by the <code>DownloadAction</code>.
         *
         * @return The input stream for the resource to be downloaded.
         */

        public InputStream getInputStream() throws IOException {
            return context.getResourceAsStream(path);
        }
    }
}



BlueO2 2005-12-07 17:21 鍙戣〃璇勮
]]>
Struts ActionForm->BO杞崲鏂瑰紡鎬葷粨http://www.aygfsteel.com/blueoxygen/archive/2005/10/08/14989.htmlBlueO2BlueO2Sat, 08 Oct 2005 07:40:00 GMThttp://www.aygfsteel.com/blueoxygen/archive/2005/10/08/14989.htmlhttp://www.aygfsteel.com/blueoxygen/comments/14989.htmlhttp://www.aygfsteel.com/blueoxygen/archive/2005/10/08/14989.html#Feedback0http://www.aygfsteel.com/blueoxygen/comments/commentRss/14989.htmlhttp://www.aygfsteel.com/blueoxygen/services/trackbacks/14989.html1 瀹炵幇涓氬姟灞傛帴鍙?BR>public class ArticleForm extends ActionForm implements ArticleBean{
//...
}
璋冪敤ArticleBean articleBean = (ArticleBean)form;
articleModel.update(articleBean.getKey(),articleBean);
2  鎵嬪姩鍒濆鍖?BR>ArticleForm aForm = (ArticleForm)form;
ArticleBean aBean = new ArticleBean(aFrom.getxxxx..,.,.,.);
4 鎻愪緵宸ュ巶鏂規硶
ActionForm涓皝瑁呮鏂規硶
public ArticleBean getArticleBean(){
ArticleBean aBean = new ArticleBean(
this.getXXXX,
this.getXXXX,
......
)
}
5 浼犻扢ap瀵硅薄
鐢˙eanUtils鍖呮垨鑰呮墜鍔ㄤ駭鐢熶簬ActionForm
public Map describe(){
  map = new HashMap();
  map.add("xx",this.getXXX());
  map.add("xx",this.getXX());
    //......
}
6 鍙嶅皠浼犻掓暟鎹?BR>鍐欎簬action
BeanUtils.copyProperties(myBusinessBean,myActionForm);
  //Business Object's somemethod
BeanUtils.copyProperties(myActionForm,myBusinessBean);

BlueO2 2005-10-08 15:40 鍙戣〃璇勮
]]>
鎵撶牬紲炶瘽http://www.aygfsteel.com/blueoxygen/archive/2005/10/08/14978.htmlBlueO2BlueO2Sat, 08 Oct 2005 04:13:00 GMThttp://www.aygfsteel.com/blueoxygen/archive/2005/10/08/14978.htmlhttp://www.aygfsteel.com/blueoxygen/comments/14978.htmlhttp://www.aygfsteel.com/blueoxygen/archive/2005/10/08/14978.html#Feedback0http://www.aygfsteel.com/blueoxygen/comments/commentRss/14978.htmlhttp://www.aygfsteel.com/blueoxygen/services/trackbacks/14978.html鎰熻Struts鏍囩澶箒鐞愪簡錛屾兂鐢?struts+velocity ,浣嗘槸欏甸潰濡傛灉娌℃湁html:form絳塻truts鏍囩錛岄〉闈㈢殑form elements 鏄惁鑳借祴鍊煎埌formbean涓紝formbean涓殑validate鏂規硶鏄惁榪樻湁鏁堛?BR>banq鐨勭悊瑙o細
褰撶劧涓嶄細鏈夋晥銆傛瘡涓瓧孌靛疄闄呮槸閫氳繃錛?/FONT>
<html:text name="ACTIONFORM鍚嶇О" propert=""
鍏朵腑name寰堥噸瑕侊紝鎸囧畾浜嗕嬌鐢ㄥ摢涓狝ctionForm銆?BR>
淇虹粰涓В絳旓紝涔熻鎸囧嚭涓嶈凍鍜岀悊瑙d笂鐨勫亸棰囷細
name:The attribute name of the bean whose properties are consulted when rendering the current value of this input field. If not specified, the bean associated with the form tag we are nested within is utilized.
Any JavaBean can be used with the Struts JSP tags to populate a control. But to provide automatic validation of the input, Struts uses its own JavaBean subclass,called the ActionForm.
The ActionForm solution
The Struts solution to HTTP parameter handling is to transform the input fields into JavaBean properties. When a property on the ActionForm matches a parameter in the request, the framework automatically sets the property to the value of the parameter. A Struts developer can work with a trusty JavaBean and leave the HTTP rigmarole to the framework.To harvest request parameters, all the Struts developer needs to do is provide an ActionForm with JavaBean properties that match the names of the HTTP parameters. The rest is automatic.

鍏蜂綋濡備綍automatic瑙f瀽錛孉ctionForm濡備綍琚帶鍒訛紝鏈夌┖鍐嶅啓錛屾瘯绔焥truts鐮旂┒鐨勭郴鍒楀績寰楁墠榪涜浜嗗緢灝戠瘒blog錛岀幇鍦ㄥ繖鐫webwork2 hibernate spring


BlueO2 2005-10-08 12:13 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 永定县| 北流市| 禹州市| 三门县| 沿河| 集贤县| 永康市| 罗山县| 建水县| 永丰县| 金塔县| 弥渡县| 卫辉市| 房产| 伊川县| 高尔夫| 上栗县| 阿坝县| 溧阳市| 田林县| 洪泽县| 莱州市| 新津县| 隆德县| 垦利县| 遂宁市| 雅安市| 清水县| 山阴县| 绍兴市| 汕尾市| 麻城市| 广宁县| 新密市| 天台县| 襄汾县| 淳化县| 玉林市| 土默特左旗| 开原市| 黄陵县|