- 浏览: 39044 次
- 性别:
- 来自: 重庆
文章分类
最新评论
LoadImgForm.java代码:
- /*
- * Generated by MyEclipse Struts
- * Template path: templates/java/JavaClass.vtl
- */
- package com.jqqd.struts.formAction;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.struts.action.ActionErrors;
- import org.apache.struts.action.ActionForm;
- import org.apache.struts.action.ActionMapping;
- import org.apache.struts.upload.FormFile;
- /**
- * MyEclipse Struts
- * Creation date: 06-06-2008
- *
- * XDoclet definition:
- * @struts.form name="upLoadImg"
- */
- public class UpLoadImgForm extends ActionForm {
- /*
- * Generated Methods
- */
- private FormFile file;
- /**
- *
- */
- private static final long serialVersionUID = 1L;
- /**
- * Method validate
- * @param mapping
- * @param request
- * @return ActionErrors
- */
- public ActionErrors validate(ActionMapping mapping,
- HttpServletRequest request) {
- // TODO Auto-generated method stub
- return null ;
- }
- /**
- * Method reset
- * @param mapping
- * @param request
- */
- public void reset(ActionMapping mapping, HttpServletRequest request) {
- // TODO Auto-generated method stub
- }
- public FormFile getFile() {
- return file;
- }
- public void setFile(FormFile file) {
- this .file = file;
- }
- }
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.jqqd.struts.formAction; import javax.servlet.http.HttpServletRequest; import org.apache.struts.action.ActionErrors; import org.apache.struts.action.ActionForm; import org.apache.struts.action.ActionMapping; import org.apache.struts.upload.FormFile; /** * MyEclipse Struts * Creation date: 06-06-2008 * * XDoclet definition: * @struts.form name="upLoadImg" */ public class UpLoadImgForm extends ActionForm { /* * Generated Methods */ private FormFile file; /** * */ private static final long serialVersionUID = 1L; /** * Method validate * @param mapping * @param request * @return ActionErrors */ public ActionErrors validate(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub return null; } /** * Method reset * @param mapping * @param request */ public void reset(ActionMapping mapping, HttpServletRequest request) { // TODO Auto-generated method stub } public FormFile getFile() { return file; } public void setFile(FormFile file) { this.file = file; } }
UpLoadImgAction.java代码
- /*
- * Generated by MyEclipse Struts
- * Template path: templates/java/JavaClass.vtl
- */
- package com.jqqd.struts.action;
- import java.io.ByteArrayOutputStream;
- import java.io.FileOutputStream;
- import java.io.InputStream;
- import java.io.OutputStream;
- 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.jqqd.struts.formAction.UpLoadImgForm;
- /**
- * MyEclipse Struts Creation date: 06-06-2008
- *
- * XDoclet definition:
- *
- * @struts.action path="/upLoadImg" name="upLoadImg" input="/uploadImg.jsp"
- * scope="request" validate="true"
- * @struts.action-forward name="error" path="/error.jsp"
- * @struts.action-forward name="success" path="/success.jsp"
- */
- public class UpLoadImgAction 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) {
- if (form instanceof UpLoadImgForm) { // 如果form是uploadsForm
- String encoding = request.getCharacterEncoding();
- if ((encoding != null ) && (encoding.equalsIgnoreCase( "utf-8" ))) {
- response.setContentType("text/html; charset=gb2312" ); // 如果没有指定编码,编码格式为gb2312
- }
- UpLoadImgForm upLoad = (UpLoadImgForm) form;
- FormFile formFile = upLoad.getFile();
- try {
- InputStream stream = formFile.getInputStream();
- String realPath = request.getRealPath("/" + "upload" );
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- OutputStream bao = new FileOutputStream(realPath + "/"
- + formFile.getFileName());
- int bytesRead = 0 ;
- byte [] buffer = new byte [ 8192 ];
- while ((bytesRead = stream.read(buffer, 0 , 8192 )) != - 1 ) {
- bao.write(buffer, 0 , bytesRead);
- }
- bao.flush();
- bao.close();
- stream.close();
- } catch (Exception e) {
- System.out.println(e);
- }
- return mapping.findForward( "success" );
- }
- return mapping.findForward( "error" );
- }
- }
/* * Generated by MyEclipse Struts * Template path: templates/java/JavaClass.vtl */ package com.jqqd.struts.action; import java.io.ByteArrayOutputStream; import java.io.FileOutputStream; import java.io.InputStream; import java.io.OutputStream; 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.jqqd.struts.formAction.UpLoadImgForm; /** * MyEclipse Struts Creation date: 06-06-2008 * * XDoclet definition: * * @struts.action path="/upLoadImg" name="upLoadImg" input="/uploadImg.jsp" * scope="request" validate="true" * @struts.action-forward name="error" path="/error.jsp" * @struts.action-forward name="success" path="/success.jsp" */ public class UpLoadImgAction 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) { if (form instanceof UpLoadImgForm) {// 如果form是uploadsForm String encoding = request.getCharacterEncoding(); if ((encoding != null) && (encoding.equalsIgnoreCase("utf-8"))) { response.setContentType("text/html; charset=gb2312");// 如果没有指定编码,编码格式为gb2312 } UpLoadImgForm upLoad = (UpLoadImgForm) form; FormFile formFile = upLoad.getFile(); try { InputStream stream = formFile.getInputStream(); String realPath = request.getRealPath("/"+"upload"); ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStream bao = new FileOutputStream(realPath + "/" + formFile.getFileName()); int bytesRead = 0; byte[] buffer = new byte[8192]; while ((bytesRead = stream.read(buffer, 0, 8192)) != -1) { bao.write(buffer, 0, bytesRead); } bao.flush(); bao.close(); stream.close(); } catch (Exception e) { System.out.println(e); } return mapping.findForward("success"); } return mapping.findForward("error"); } }
struts-config.xml代码:
- <? xml version = "1.0" encoding = "UTF-8" ?>
- <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
- < struts-config >
- < data-sources />
- < form-beans >
- < form-bean name = "upLoadImg" type = "com.jqqd.struts.formAction.UpLoadImgForm" />
- </ form-beans >
- < global-exceptions />
- < global-forwards />
- < action-mappings >
- < action
- attribute = "upLoadImg"
- validate = "false"
- name = "upLoadImg"
- path = "/upLoadImg"
- scope = "request"
- type = "com.jqqd.struts.action.UpLoadImgAction" >
- < forward name = "error" path = "/error.jsp" />
- < forward name = "success" path = "/success.jsp" />
- </ action >
- </ action-mappings >
- < message-resources parameter = "com.jqqd.struts.ApplicationResources" />
- </ struts-config >
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd"> <struts-config> <data-sources /> <form-beans > <form-bean name="upLoadImg" type="com.jqqd.struts.formAction.UpLoadImgForm" /> </form-beans> <global-exceptions /> <global-forwards /> <action-mappings > <action attribute="upLoadImg" validate="false" name="upLoadImg" path="/upLoadImg" scope="request" type="com.jqqd.struts.action.UpLoadImgAction"> <forward name="error" path="/error.jsp" /> <forward name="success" path="/success.jsp" /> </action> </action-mappings> <message-resources parameter="com.jqqd.struts.ApplicationResources" /> </struts-config>
uploadImg.jsp文件的代码:
- < %@ page language = "java" pageEncoding = "GB2312" % >
- < %@ taglib uri = "http://struts.apache.org/tags-html" prefix = "html" % >
- < html >
- < head >
- < title > uploadImg.do </ title >
- < link type = "text/css" rel = "stylesheet" href = "css/upload.css" />
- </ head >
- < body >
- < html:form action = "upLoadImg.do" enctype = "multipart/form-data" >
- < div id = "uploadD" >
- < div id = "uploadTitD" > 图片上传 </ div >
- < div id = "uploadConD" >
- < html:file property = "file" > </ html:file > < br /> < br />
- < html:submit > </ html:submit > < html:reset > </ html:reset > </ div >
- </ div >
- </ html:form >
- </ body >
- </ html >
<%@ page language="java" pageEncoding="GB2312"%> <%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> <html> <head> <title>uploadImg.do</title> <link type="text/css" rel="stylesheet" href="../../css/upload.css" /> </head> <body> <html:form action="upLoadImg.do" enctype="multipart/form-data"> <div id="uploadD"> <div id="uploadTitD">图片上传</div> <div id="uploadConD"> <html:file property="file"></html:file><br/><br/> <html:submit></html:submit><html:reset></html:reset></div> </div> </html:form> </body> </html>
base.css代码:
- html,body{margin:0px;border:0px; background-color:#333333; text-align:center; font-size:12px; color:#FFFFFF; }
- body img,body div{border:0px; margin-left:auto; margin-right:auto;}
html,body{margin:0px;border:0px; background-color:#333333; text-align:center; font-size:12px; color:#FFFFFF; } body img,body div{border:0px; margin-left:auto; margin-right:auto;}
upload.css代码:
- @import url(base.css);
- #uploadD{width:600px; height:500px; border:1px solid #FFFFFF; margin-top:50px;}
- #uploadTitD,#uploadConD{width:600px; height:30px; border:0px; background-color:#999999; line-height:2.5em; height:2.5em;}
- #uploadConD{background-color:#666666;}
---------------------------------------------------------------------------------
学习工作累了,休闲娱乐一下 ~~~
天迹网游世界: http://tjwl.jimdo.com/
我们的淘客网开通啦,欢迎大家去逛逛
~\(
≧▽≦
)/~
啦啦啦
~~~
淘宝购物资讯网:
http://taoke178.jimdo.com
淘乐园: http://taoleyuan.jimdo.com
发表评论
-
为Struts 2.0做好学习准备(图)
2010-02-04 13:19 775Struts作为MVC 2的Web框架 ... -
JSF进行Web开发的三大优势
2010-01-30 11:37 751JSF优势之一:UI组件(UI-c ... -
将Flex集成到Java EE应用程序的最佳实践
2010-01-23 20:27 793作者:廖雪峰 传统的 Java EE 应用程序通 ... -
初学者如何开发出高质量J2EE系统
2010-01-21 17:45 727J2EE学习者越来越多,J2EE本身技术不断在发展,涌现出各种 ... -
构建高性能J2EE应用的十个技巧
2010-01-21 17:43 577构建高性能的J2EE应用不但需要了解常用的实施技巧。下面介 ... -
J2EE学习中一些值得研究的开源项目
2010-01-21 17:39 772一、JavaServlet和JSP方向 很多人都是从Serv ... -
Spring 3.0 正式版发布
2010-01-21 10:30 1083经过四个里程碑版、三个RC版,Spring框架终于发布了3.0 ... -
Struts DynaActionForm配置
2010-01-20 17:20 857为什么要有动态ActionForm ... -
学Struts2从HelloWorld示例开始
2010-01-20 17:14 810介绍 当提交一个Html的Form给Strut ... -
Struts,MVC 的一种开放源码实现
2010-01-20 17:12 787简介 小学生也可以在因特网上发布 HTML 网 ... -
高性能、高弹性JSP和Servlet性能优化
2010-01-20 17:07 800你的J2EE 应用是不是运行的很慢?它们能不能承受住不断上升 ... -
Struts2的工作流程图
2010-01-19 12:41 1195Struts2的工作流程图(学习笔记) 当接 ... -
Struts2和Struts1的区别
2010-01-19 12:38 715Struts2和Struts1的不同 Action 类: ... -
WSDL编写的五个步骤
2010-01-18 17:49 694WSDL编写的五个步骤 1)声明名称空间 必须在 < ... -
JAVA EE 中间件
2010-01-18 17:43 996Weblogic ...
相关推荐
struts2文件上传教程
Struts2文件上传和下载教程
struts2文件上传-基本
struts构建文件上传,如果有这方面需求的朋友,希望能给你一点帮助.
Struts1.x的上传文件示例。Struts1.x的教程参考我的Blog:http://blog.csdn.net/boyazuo
struts2学习教程包括:第一个Struts2程序,处理一个form多个submit,struts.xml常用配置解析,使用validate方法验证数据,使用Validation框架验证数据,在Action类中获得HttpServletResponse对象的四种方法,上传...
很好的struts2入门教程,网上搜集整理的! 内容: ... ·Struts 2中实现文件上传 ·Struts 2中的OGNL ·Strus 2的新表单标签的使用 ·Struts 2与AJAX ·Struts2分页 ·完全Struts's Tiles入门
01 为Struts 2.0做好准备 02 常用的Struts 2.0的标志(Tag) 03 Struts 2.0的Action讲解...09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 trus 2的新表单标志的使用 13 Struts 2与AJAX
十二、总结 本教程对struts2的基本知识进行了一些说明,关于struts2的更多详细内容应参看struts2的官方文档及提供的app实例。 下面对struts2的基本执行流程作一简要说明,此流程说明可以结合官方提供的struts2结构图...
struts2的文件上传教程,讲的挺好的,值得下载
教程名称:浪曦Struts2系列视频教程课程目录:【】1 Struts2入门与配置【】10 Struts2的核心 拦截器【】11 Struts2的核心 拦截器续【】12 Struts2的文件上传和下载【】13 Struts2的文件上传和下载续【】14 Struts2的...
struts2相关经典教程 fileupload struts2
博文链接:https://zzwwyf.iteye.com/blog/231491
01 为Struts 2.0做好准备 02 常用的Struts 2.0的标志(Tag) 03 Struts 2.0的Action...09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 Struts 2的新表单标志的使用 13 Struts 2与AJAX
itcast的struts2简单教程 包括:环境搭建、国际化、OGNL、标签、拦截器、文件上传等
Struts2中文教程,包括:标志,Action讲解,国际化,拦截器,文件上传等等,内容非常详细!
09 在Struts 2中实现文件上传 10 在Struts 2中实现CRUD 11 Struts 2中的OGNL 12 trus 2的新表单标志的使用 13 Struts 2与AJAX Struts2中用Spring实现IoC.doc Struts2中的零配置与CoC(Convention over Configration...
Struts2提供的文件上传下载机制十分简便,使得我们写很少的代码,下面这篇文章主要给大家介绍了关于Struts2学习手册之文件上传的相关资料,文中通过示例代码介绍的非常详细,需要的朋友可以参考下
包含: Struts2.0中文教程 struts2权威指南 struts架构的指导 struts框架详细介绍 struts整体架构及核心标签库 validator页面验证 用struts架构实现文件上传任务