- 浏览: 85764 次
文章分类
最新评论
-
cuisuqiang:
smallbee 写道信息: Initializing Coy ...
apache tomcat负载均衡实验记录 -
hwy1782:
数据库分库分表使用的是TDDL
淘宝网技术分析(整理中) -
smallbee:
信息: Initializing Coyote HTTP/1. ...
apache tomcat负载均衡实验记录 -
likebin:
受用,值得学习
新浪微博架构分析
import java.io.File; import javax.servlet.ServletContext; import org.apache.commons.io.FileUtils; import com.opensymphony.xwork2.ActionSupport; public class StrutsFileUpload extends ActionSupport implements private File upload;// 实际上传文件 private String uploadContentType; // 文件的内容类型 private String uploadFileName; // 上传文件名 private String fileCaption;// 上传文件时的备注 private ServletContext context; public String execute() throws Exception { try { addActionError(e.getMessage()); return INPUT; return SUCCESS; } public String getFileCaption() { public void setFileCaption(String fileCaption) { public File getUpload() { public void setUpload(File upload) { public String getUploadContentType() { public void setUploadContentType(String uploadContentType) { public String getUploadFileName() { public void setUploadFileName(String uploadFileName) { public void setServletContext(ServletContext context) { } 3.页面 上传页面:upload.jsp <%@ page language="java" contentType="text/html; charset=GB2312"%> </head> <body> <s:actionerror /> <s:file name="upload" label="上传的文件" /> 上传成功页面:upload_success.jsp <%@ page language="java" contentType="text/html; charset=GB2312"%> <body> <td colspan="2"> <tr> <tr> <tr> </body> 4.struts.xml <?xml version="1.0" encoding="UTF-8" ?> <struts> </struts> <?xml version="1.0" encoding="UTF-8"?> <display-name>customization</display-name> <filter> </web-app>
Struts2上传文件示例
2.Action类
package com.sterning;
import org.apache.struts2.util.ServletContextAware;
ServletContextAware {
String targetDirectory = context.getRealPath("/upload");
String targetFileName = uploadFileName;
File target = new File(targetDirectory, targetFileName);
FileUtils.copyFile(upload, target);
setUploadFileName(target.getPath());//保存文件的存放路径
} catch (Exception e) {
}
return fileCaption;
}
this.fileCaption = fileCaption;
}
return upload;
}
this.upload = upload;
}
return uploadContentType;
}
this.uploadContentType = uploadContentType;
}
return uploadFileName;
}
this.uploadFileName = uploadFileName;
}
this.context = context;
}
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>文件上传示例</title>
<link href="<s:url value="/css/main.css"/>" rel="stylesheet"
type="text/css" />
<s:fielderror />
<s:form action="doUpload" method="POST" enctype="multipart/form-data">
<tr>
<td colspan="2">
<h1>
文件上传示例
</h1>
</td>
</tr>
<s:textfield name="fileCaption" label="备注" />
<s:submit value="上 传"/>
</s:form>
</body>
</html>
<%@ taglib prefix="s" uri="/struts-tags"%>
<html>
<head>
<title>上传成功</title>
<link href="<s:url value="/css/main.css"/>" rel="stylesheet"
type="text/css" />
</head>
<table class="wwFormTable">
<tr>
<h1>
上传成功
</h1>
</td>
</tr>
<td class="tdLabel">
<label for="doUpload_upload" class="label">
内容类型:
</label>
</td>
<td>
<s:property value="uploadContentType" />
</td>
</tr>
<td class="tdLabel">
<label for="doUpload_upload" class="label">
文件路径:
</label>
</td>
<td>
<s:property value="uploadFileName" />
</td>
</tr>
<tr>
<td class="tdLabel">
<label for="doUpload_upload" class="label">
临时文件:
</label>
</td>
<td>
<s:property value="upload" />
</td>
</tr>
<td class="tdLabel">
<label for="doUpload_upload" class="label">
备注:
</label>
</td>
<td>
<s:property value="fileCaption" />
</td>
</tr>
</table>
</html>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<constant name="struts.devMode" value="true" />
<constant name="struts.i18n.encoding" value="GB2312" />
<package name="NG" namespace="/" extends="struts-default">
<action name="showUpload">
<result>/upload.jsp</result>
</action>
<action name="doUpload" class="com.sterning.StrutsFileUpload">
<result name="input">/upload.jsp</result>
<result>/upload_success.jsp</result>
</action>
</package>
5.web.xml
<web-app id="WebApp_ID" version="2.4"
xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<filter-name>struts-cleanup</filter-name>
<filter-class>
org.apache.struts2.dispatcher.ActionContextCleanUp
</filter-class>
</filter>
<filter>
<filter-name>struts2</filter-name>
<filter-class>
org.apache.struts2.dispatcher.FilterDispatcher
</filter-class>
</filter>
<filter-mapping>
<filter-name>struts-cleanup</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
发表评论
-
搜索引擎爬虫蜘蛛的User-Agent收集
2012-01-17 14:57 1343百度爬虫 * Baiduspider+ ... -
Spring MVC 3.0.5+Spring 3.0.5+MyBatis3.0.4全注解实例详解
2012-01-10 12:00 1007Spring MVC 3.0.5+Spring 3.0. ... -
网络自动化测试框架
2011-11-12 11:46 734Selenium http://seleniumhq. ... -
javascript跨域访问(前端解决方案)
2011-10-03 17:11 969什么是跨域 JavaScript出于安全方面的考虑,不允许跨 ... -
海量数据处理专题(转)
2011-09-21 16:43 838原文: http://bbs.xjtu. ... -
apache tomcat负载均衡实验记录
2011-09-20 00:28 16929http://www.iteye.com/topic/1 ... -
性能调优学习笔记(转载)
2011-09-02 13:06 7101、性能调优的步骤 ... -
(转)Apache common-pool, common-dbcp源码解读与对象池原理剖析
2011-08-15 10:46 1055原文地址: http://macroch ... -
JSP中EL表达式的取值范围
2011-08-04 22:30 7450在JSP中,脚本化语言如“<%=contextPath% ... -
linux方面最近要看的书
2011-08-04 21:06 821鸟哥的Linux私房菜 http://linux-vbird ... -
Java内存泄露的理解与解决
2011-07-24 23:56 722转载请注明出处:http:// ... -
23个经典JDK设计模式
2011-07-21 17:09 808酷壳版主陈皓近日发表博文《JDK里的设计模式》,文中他列出 ... -
Session实现原理
2011-07-15 17:34 685HTTP协议 ( http://www.w3.or ...
相关推荐
文件上传吗,你懂得,一个简单的小例子而已,有简单的注释可供查看
struts 上传文件的示例,是一个myeclipse工程
struts2上传文件示例,有详细的图文解析,清晰易懂
最近在做struts2的学习研究,这里共享一份完整能运行的示例
struts2中的文件上传和下载示例 struts2中的文件上传和下载示例 struts2中的文件上传和下载示例
Struts2 的简单上传。功能基本实现。
本程序为struts2文件是上传程序。解压后就可以使用。程序比较简单适合于初学者。奔驰呢工序仅供参考。严禁用于其他用途
Struts2实现文件的上传,附有详细的代码注释。献给自学Struts2的童鞋们
struts2 + uploadify上传文件示例
struts2上传文件Demo,用struts2做了个简单的Demo。 上传到Csdn里面来跟大家分享。 里面写了个辅助上传文件,……
基于struts2实现了单一文件上传,多文件上传和文件下载的功能.
Struts1.x的上传文件示例。Struts1.x的教程参考我的Blog:http://blog.csdn.net/boyazuo
文件上传代码示例,使用了struts,简单易懂
该案例是基于struts2.0 来上传图片的案例,可以轻松的限制图片的类型,大小路径,如果有不明白的地方可以844818108@qq.com
利用struts 实现 文件上传功能的代码示例
struts2 文件上传和下载示例程序 http://blog.csdn.net/zhiweiv/archive/2008/10/13/3070610.aspx
struts2文件上传,包含了单个文件上传和多文件上传的代码示例
文档讲述了利用strurts1来上传和下载文件,远程也可以进行上传和下载!
可以实现一次性上传多个文件,使用JavaScript动态添加一个上传文本框。是用struts2实现的