锘??xml version="1.0" encoding="utf-8" standalone="yes"?>亚洲校园春色小说,亚洲另类无码一区二区三区,亚洲精品第一国产综合亚AV http://www.tkk7.com/cuore/category/32590.htmlzh-cn Fri, 27 Jun 2008 04:40:48 GMT Fri, 27 Jun 2008 04:40:48 GMT 60 鐢⊿truts涓婁紶澶氫釜鏂囦歡 http://www.tkk7.com/cuore/archive/2008/06/27/211073.htmlgreedy greedy Fri, 27 Jun 2008 02:53:00 GMT http://www.tkk7.com/cuore/archive/2008/06/27/211073.html http://www.tkk7.com/cuore/comments/211073.html http://www.tkk7.com/cuore/archive/2008/06/27/211073.html#Feedback 0 http://www.tkk7.com/cuore/comments/commentRss/211073.html http://www.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>
]]> Struts鐗堢殑楠岃瘉鐮佺敓鎴愪嬌鐢ㄦ柟娉? http://www.tkk7.com/cuore/archive/2008/06/27/211072.htmlgreedy greedy Fri, 27 Jun 2008 02:51:00 GMT http://www.tkk7.com/cuore/archive/2008/06/27/211072.html http://www.tkk7.com/cuore/comments/211072.html http://www.tkk7.com/cuore/archive/2008/06/27/211072.html#Feedback 0 http://www.tkk7.com/cuore/comments/commentRss/211072.html http://www.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" />
]]>鐢⊿truts涓婁紶鏂囦歡 http://www.tkk7.com/cuore/archive/2008/06/27/211069.htmlgreedy greedy Fri, 27 Jun 2008 02:47:00 GMT http://www.tkk7.com/cuore/archive/2008/06/27/211069.html http://www.tkk7.com/cuore/comments/211069.html http://www.tkk7.com/cuore/archive/2008/06/27/211069.html#Feedback 0 http://www.tkk7.com/cuore/comments/commentRss/211069.html http://www.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灝辨槸闅忎究鍐欎竴涓垚鍔熼〉-->
]]>
主站蜘蛛池模板:
久久久久久A亚洲欧洲AV冫 |
国产成人亚洲综合 |
亚洲手机中文字幕 |
亚洲精品免费视频 |
亚洲精品欧洲精品 |
男女免费观看在线爽爽爽视频
|
亚洲日韩欧洲乱码AV夜夜摸 |
一级做α爱过程免费视频 |
不卡精品国产_亚洲人成在线 |
EEUSS影院WWW在线观看免费 |
亚洲午夜国产精品无码 |
十八禁在线观看视频播放免费 |
久久精品国产亚洲一区二区 |
99热这里只有精品免费播放 |
亚洲电影唐人社一区二区 |
在线永久看片免费的视频 |
亚洲精品欧美综合四区 |
免费a级毛片永久免费 |
不卡视频免费在线观看 |
久久久无码精品亚洲日韩京东传媒 |
免费福利视频导航 |
亚洲中文字幕AV每天更新 |
国产成人高清精品免费鸭子
|
亚洲AV无一区二区三区久久 |
99精品热线在线观看免费视频 |
亚洲国产高清在线精品一区
|
99久久精品免费精品国产 |
亚洲人妖女同在线播放 |
免费一级毛片在线播放 |
日本三级在线观看免费 |
亚洲国产成人手机在线电影bd |
国产极品粉嫩泬免费观看 |
黄色免费在线网站 |
亚洲看片无码在线视频 |
国产乱辈通伦影片在线播放亚洲
|
久久精品国产影库免费看 |
亚洲一区二区影院 |
国产成人免费a在线视频色戒
|
99爱在线精品免费观看 |
免费看又黄又爽又猛的视频软件
|
亚洲av无码专区在线观看亚 |