锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲校园春色小说,亚洲另类无码一区二区三区,亚洲精品第一国产综合亚AVhttp://m.tkk7.com/cuore/category/32590.htmlzh-cnFri, 27 Jun 2008 04:40:48 GMTFri, 27 Jun 2008 04:40:48 GMT60鐢⊿truts涓婁紶澶氫釜鏂囦歡http://m.tkk7.com/cuore/archive/2008/06/27/211073.htmlgreedygreedyFri, 27 Jun 2008 02:53:00 GMThttp://m.tkk7.com/cuore/archive/2008/06/27/211073.htmlhttp://m.tkk7.com/cuore/comments/211073.htmlhttp://m.tkk7.com/cuore/archive/2008/06/27/211073.html#Feedback0http://m.tkk7.com/cuore/comments/commentRss/211073.htmlhttp://m.tkk7.com/cuore/services/trackbacks/211073.html
package com.cnehu.struts.form;
import javax.servlet.http.HttpServletRequest;

import org.apache.struts.action.ActionError;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.upload.FormFile;
import org.apache.struts.upload.MultipartRequestHandler;

public class UpLoadForm extends ActionForm
{
   public static final String ERROR_PROPERTY_MAX_LENGTH_EXCEEDED = "org.apache.struts.webapp.upload.MaxLengthExceeded";

   protected FormFile theFile;
   protected FormFile theFile2;
   public FormFile getTheFile()
   {
       return theFile;
   }

   public void setTheFile(FormFile theFile)
   {
       this.theFile = theFile;
   }

   public ActionErrors validate(ActionMapping mapping,
           HttpServletRequest request)
   {
       ActionErrors errors = null;
       //has the maximum length been exceeded?
       Boolean maxLengthExceeded = (Boolean) request
               .getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
       if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue()))
       {
           errors = new ActionErrors();
           errors.add(ERROR_PROPERTY_MAX_LENGTH_EXCEEDED, new ActionError(
                   "maxLengthExceeded"));
       }
       return errors;

   }
   /**
    * @return Returns the theFile2.
    */
   public FormFile getTheFile2()
   {
       return theFile2;
   }
   /**
    * @param theFile2 The theFile2 to set.
    */
   public void setTheFile2(FormFile theFile2)
   {
       this.theFile2 = theFile2;
   }
}


浜屻傚緩绔婣ctionServlet

package com.cnehu.struts.action;

import java.io.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;
import com.cnehu.struts.form.UpLoadForm;

public class UpLoadAction extends Action
{
   public ActionForward execute(ActionMapping mapping, ActionForm form,
           HttpServletRequest request, HttpServletResponse response)
           throws Exception
   {
           String encoding = request.getCharacterEncoding();
           if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8")))
           {
               response.setContentType("text/html; charset=gb2312");//濡傛灉娌℃湁鎸囧畾緙栫爜錛岀紪鐮佹牸寮忎負gb2312
           }
           UpLoadForm theForm = (UpLoadForm) form;
           FormFile file = theForm.getTheFile();//鍙栧緱涓婁紶鐨勬枃浠?br />          
           FormFile file2=theForm.getTheFile2();
           try
           {              
               /*
                * 鍙栧綋鍓嶇郴緇熻礬寰凞:\Tomcat5\webapps\coka\ 鍏朵腑coka 涓哄綋鍓峜ontext
                */
               String filePath = this.getServlet().getServletContext().getRealPath("/");
               InputStream stream = file.getInputStream();//鎶婃枃浠惰鍏?br />              
               /*
                * 寤虹珛涓涓笂浼犳枃浠剁殑杈撳嚭嫻?濡傛灉鏄痩inux緋葷粺璇鋒妸UploadFiles鍚庣殑"\\"鎹㈡垚"/"
                */
               OutputStream bos = new FileOutputStream(filePath + "UploadFiles\\"+file.getFileName());
               
               request.setAttribute("fileName",filePath + "/"  + file.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();
               
               InputStream stream2 = file2.getInputStream();//鎶婃枃浠惰鍏?br />                OutputStream bos2 =  new FileOutputStream(filePath + "UploadFiles\\"+file2.getFileName());//寤虹珛涓涓笂浼犳枃浠剁殑杈撳嚭嫻?br />          int bytesRead2 = 0;
               byte[] buffer2 = new byte[8192];
               int i=0;
               while ((bytesRead2 = stream2.read(buffer2, 0, 8192)) != -1)
               {
                   bos2.write(buffer2, 0, bytesRead2);//灝嗘枃浠跺啓鍏ユ湇鍔″櫒
          }          
               bos2.close();
               stream2.close();
               
           } catch (Exception e)
           {
               System.err.print(e);
           }
           return mapping.findForward("display");
         
   }
}

涓夈傚緩绔嬩笂浼犵敤鐨凧SP鏂囦歡 upload.jsp

<%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
<html:html>
<head>
<title>鐢⊿truts涓婁紶鏂囦歡</title>
</head>
<body>
<html:form action="/uploadsAction" enctype="multipart/form-data">
<html:file property="theFile"/>
<html:file property="theFile2"/>

<html:submit/>
</html:form>
</body>
</html:html>

鍥涖傞厤緗畇truts-config.xml鏂囦歡

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
  <data-sources />
  <form-beans >
    <form-bean name="uploadsForm" type="com.cnehu.struts.form.UpLoadForm" />
  </form-beans>

  <global-exceptions />
  <global-forwards >
   
  </global-forwards>

  <action-mappings >
           
     <action name="uploadsForm" type="com.cnehu.struts.action.UpLoadAction" path="/uploadsAction">
<forward name="display" path="/display.jsp" />
</action>
   </action-mappings>
         
</struts-config>


greedy 2008-06-27 10:53 鍙戣〃璇勮
]]>
Struts鐗堢殑楠岃瘉鐮佺敓鎴愪嬌鐢ㄦ柟娉?http://m.tkk7.com/cuore/archive/2008/06/27/211072.htmlgreedygreedyFri, 27 Jun 2008 02:51:00 GMThttp://m.tkk7.com/cuore/archive/2008/06/27/211072.htmlhttp://m.tkk7.com/cuore/comments/211072.htmlhttp://m.tkk7.com/cuore/archive/2008/06/27/211072.html#Feedback0http://m.tkk7.com/cuore/comments/commentRss/211072.htmlhttp://m.tkk7.com/cuore/services/trackbacks/211072.html 

package cn.com.lough.struts.action;

import java.awt.Color;
import java.awt.Font;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import java.util.Random;

import javax.imageio.ImageIO;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

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.commons.lang.RandomStringUtils;

/**
* MyEclipse Struts Creation date: 01-11-2007
*
* XDoclet definition:
*
* @struts.action validate="true"
*/
public class ValidatecodeAction extends Action {
 /*
  * Generated Methods
  */

 /**
  * Method execute
  *
  * @param mapping
  * @param form
  * @param request
  * @param response
  * @return ActionForward
  */
 public ActionForward execute(ActionMapping mapping, ActionForm form,
     HttpServletRequest request, HttpServletResponse response) {
   try {
     int width = 50;
     int height = 18;
     // 鍙栧緱涓涓?浣嶉殢鏈哄瓧姣嶆暟瀛楀瓧絎︿覆
     String s = RandomStringUtils.random(4, true, true);
     
     // 淇濆瓨鍏ession,鐢ㄤ簬涓庣敤鎴風殑杈撳叆榪涜姣旇緝.
     // 娉ㄦ剰姣旇緝瀹屼箣鍚庢竻闄ession.
     HttpSession session = request.getSession(true);
     session.setAttribute("validateCode", s);

     response.setContentType("images/jpeg");
     response.setHeader("Pragma", "No-cache");
     response.setHeader("Cache-Control", "no-cache");
     response.setDateHeader("Expires", 0);

     ServletOutputStream out = response.getOutputStream();
     BufferedImage image = new BufferedImage(width, height,
         BufferedImage.TYPE_INT_RGB);
     Graphics g = image.getGraphics();
     // 璁懼畾鑳屾櫙鑹?br />      g.setColor(getRandColor(200, 250));
     g.fillRect(0, 0, width, height);

     // 璁懼畾瀛椾綋
     Font mFont = new Font("Times New Roman", Font.BOLD, 18);// 璁劇疆瀛椾綋
     g.setFont(mFont);

     // 鐢昏竟妗?br />      // g.setColor(Color.BLACK);
     // g.drawRect(0, 0, width - 1, height - 1);

     // 闅忔満浜х敓騫叉壈綰匡紝浣垮浘璞′腑鐨勮璇佺爜涓嶆槗琚叾瀹冪▼搴忔帰嫻嬪埌
     g.setColor(getRandColor(160, 200));
     // 鐢熸垚闅忔満綾?br />      Random random = new Random();
     for (int i = 0; i < 155; i++) {
       int x2 = random.nextInt(width);
       int y2 = random.nextInt(height);
       int x3 = random.nextInt(12);
       int y3 = random.nextInt(12);
       g.drawLine(x2, y2, x2 + x3, y2 + y3);
     }

     // 灝嗚璇佺爜鏄劇ず鍒板浘璞′腑
     g.setColor(new Color(20 + random.nextInt(110), 20 + random
         .nextInt(110), 20 + random.nextInt(110)));

     g.drawString(s, 2, 16);

     // 鍥捐薄鐢熸晥
     g.dispose();
     // 杈撳嚭鍥捐薄鍒伴〉闈?br />      ImageIO.write((BufferedImage) image, "JPEG", out);
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return null;
 }

 private Color getRandColor(int fc, int bc) { // 緇欏畾鑼冨洿鑾峰緱闅忔満棰滆壊
   Random random = new Random();
   if (fc > 255)
     fc = 255;
   if (bc > 255)
     bc = 255;
   int r = fc + random.nextInt(bc - fc);
   int g = fc + random.nextInt(bc - fc);
   int b = fc + random.nextInt(bc - fc);
   return new Color(r, g, b);
 }
}



jsp欏甸潰鐨勮皟鐢?br /> <html:img page="/validatecode.do" border="0" onclick="this.src='/validatecode.do'" alt="璇瘋緭鍏ユ楠岃瘉鐮侊紝濡傜湅涓嶆竻璇風偣鍑誨埛鏂般? style="cursor:pointer" />

greedy 2008-06-27 10:51 鍙戣〃璇勮
]]>
鐢⊿truts涓婁紶鏂囦歡 http://m.tkk7.com/cuore/archive/2008/06/27/211069.htmlgreedygreedyFri, 27 Jun 2008 02:47:00 GMThttp://m.tkk7.com/cuore/archive/2008/06/27/211069.htmlhttp://m.tkk7.com/cuore/comments/211069.htmlhttp://m.tkk7.com/cuore/archive/2008/06/27/211069.html#Feedback0http://m.tkk7.com/cuore/comments/commentRss/211069.htmlhttp://m.tkk7.com/cuore/services/trackbacks/211069.html
FormFile鐨勫嚑涓柟娉曪細
String getContentType();
byte[] getFileData();
String getFileName();
int getFileSize();
濡傛灉鏈夊繀瑕佸彲浠ュ湪validate閲岃皟鐢ㄤ竴涓嬪仛涓浜涘垽鏂?br />
閫夋嫨涓婁紶鏂囦歡欏甸潰錛歴elfile.jsp

--------------------------------------------------------------------------------
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
<html:html>
<html:form action="/uploadsAction.do" enctype="multipart/form-data">
<html:file property="theFile"/>
<html:submit/>
</html:form>
</html:html>

--------------------------------------------------------------------------------
UpLoadAction.java
--------------------------------------------------------------------------------

import java.io.*;
import javax.servlet.http.*;
import org.apache.struts.action.*;
import org.apache.struts.upload.FormFile;

public class UpLoadAction extends Action {
 public ActionForward execute(ActionMapping mapping,
                              ActionForm form,
                              HttpServletRequest request,
                              HttpServletResponse response)
     throws Exception {
   if (form instanceof uploadsForm) {//濡傛灉form鏄痷ploadsForm

       UpLoadForm theForm = (UpLoadForm ) form;
       FormFile file = theForm.getTheFile();//鍙栧緱涓婁紶鐨勬枃浠?br />        try {
         InputStream stream = file.getInputStream();//鎶婃枃浠惰鍏?br />          String filePath = request.getRealPath("/");//鍙栧綋鍓嶇郴緇熻礬寰?br />          OutputStream bos = new FileOutputStream(filePath + "/" +
                                                 file.getFileName());//寤虹珛涓涓笂浼犳枃浠剁殑杈撳嚭嫻?br />          //System.out.println(filePath+"/"+file.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();
       }catch(Exception e){
         System.err.print(e);
       }
       //request.setAttribute("dat",file.getFileName());
       return mapping.findForward("display");
   }
   return null;
 }
}


--------------------------------------------------------------------------------
UpLoadForm.java
--------------------------------------------------------------------------------

import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.*;
import org.apache.struts.upload.*;

public class UpLoadForm extends ActionForm {
 public static final String ERROR_PROPERTY_MAX_LENGTH_EXCEEDED = "org.apache.struts.webapp.upload.MaxLengthExceeded";
 protected FormFile theFile;
 public FormFile getTheFile() {
     return theFile;
 }
 public void setTheFile(FormFile theFile) {
     this.theFile = theFile;
 }
 public ActionErrors validate(ActionMapping mapping, HttpServletRequest request)
 {
     ActionErrors errors = null;
     //has the maximum length been exceeded?
     Boolean maxLengthExceeded = (Boolean)
             request.getAttribute(MultipartRequestHandler.ATTRIBUTE_MAX_LENGTH_EXCEEDED);
     if ((maxLengthExceeded != null) && (maxLengthExceeded.booleanValue()))
     {
         errors = new ActionErrors();
         errors.add(ERROR_PROPERTY_MAX_LENGTH_EXCEEDED, new ActionError("maxLengthExceeded"));
     }
     return errors;

 }
}
//榪欐槸鐩稿搴旂殑form錛岃繕鏈夊叾浠栧睘鎬у彲浠ヨ緗紝鍏蜂綋鍙互鍙傝僺truts鐨勪笂浼犱緥瀛愩?br />

--------------------------------------------------------------------------------
struts-config.xml
--------------------------------------------------------------------------------

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
<struts-config>
 <form-beans>
   <form-bean name="uploadsForm" type="UpLoadForm" />
 </form-beans>
 <action-mappings>
   <action name="uploadsForm" type="UpLoadAction" path="/uploadsAction">
     <forward name="display" path="/display.jsp" />
   </action>
 </action-mappings>
</struts-config>
<!--display.jsp灝辨槸闅忎究鍐欎竴涓垚鍔熼〉-->


greedy 2008-06-27 10:47 鍙戣〃璇勮
]]>
主站蜘蛛池模板: 亚洲成人免费网站| 猫咪www免费人成网站| 国产一级在线免费观看| 青娱乐免费在线视频| 久久亚洲精品人成综合网| 最近中文字幕大全免费版在线| 区三区激情福利综合中文字幕在线一区亚洲视频1 | 老司机免费午夜精品视频| 久久精品免费观看国产| 日本一道本高清免费| 亚洲男女性高爱潮网站| 特a级免费高清黄色片| 成视频年人黄网站免费视频| 久久精品国产亚洲av麻| 免费视频精品一区二区| 在线免费观看污网站| 亚洲成AV人片在| 中国国语毛片免费观看视频| 免费中文字幕不卡视频| 国产精品亚洲精品观看不卡| 黄色a级免费网站| 四虎影视在线影院在线观看免费视频| 亚洲黄黄黄网站在线观看| 亚洲综合色婷婷在线观看| 日本黄网站动漫视频免费| 在线播放免费人成视频在线观看| 亚洲欧洲日本精品| 99蜜桃在线观看免费视频网站| 成人性生交大片免费看午夜a| 亚洲特级aaaaaa毛片| 91精品免费观看| 女人张腿给男人桶视频免费版| 亚洲综合久久久久久中文字幕| 足恋玩丝袜脚视频免费网站| 久久久亚洲欧洲日产国码aⅴ| 亚洲熟妇无码久久精品| 亚洲日韩精品国产一区二区三区| 亚洲国产小视频精品久久久三级 | 最近中文字幕电影大全免费版 | 最近免费中文字幕mv在线电影| 午夜精品一区二区三区免费视频|