strus2文件上传
来源:互联网 发布:创玻璃优化软件 编辑:程序博客网 时间:2024/06/08 04:08
1. 使用Struts2上传文件到服务器中,文件上传成功后在eclipse的工作区间是看不见上传的文件的,可以在Tomcat服务器指定路径中查看上传的文件信息。
2. WebRoot目录下必须创建一个用于保存上传文件的目录,否则报错“找不到指定目录”。
上传页面:upload.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><% String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <base href="<%=basePath%>"> <title>Struts2文件上传</title> <meta http-equiv="pragma" content="no-cache"> <meta http-equiv="cache-control" content="no-cache"> <meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"> <meta http-equiv="description" content="This is my page"> <!-- <link rel="stylesheet" type="text/css" href="styles.css"> --> </head> <body> <center> <h1>Struts 2完成上传</h1> <form action="upload.action" method="post" enctype="multipart/form-data"> <table> <tr> <td>用户名:</td> <td><input type="text" name="username" ></td> </tr> <tr> <td>上传文件:</td> <td><input type="file" name="myFile"></td> </tr> <tr> <td><input type="submit" value="上传"></td> <td><input type="reset"></td> </tr> </table> </form> </center> </body> </html>
strus2配置文件:struts.xml
<?xml version="1.0" encoding="UTF-8" ?><!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="struts2" extends="struts-default"> <action name="upload" class="net.hncu.struts2.action.UploadAction"> <result name="success">/result.jsp</result> <result name="input">/upload.jsp</result> </action> </package> </struts>
上传成功显示页面:result.jsp
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%><%@taglib prefix="s" uri="/struts-tags" %><%String path = request.getContextPath();String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";%><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html> <head> <base href="<%=basePath%>"> <title>My JSP 'result.jsp' starting page</title> <meta http-equiv="pragma" content="no-cache"><meta http-equiv="cache-control" content="no-cache"><meta http-equiv="expires" content="0"> <meta http-equiv="keywords" content="keyword1,keyword2,keyword3"><meta http-equiv="description" content="This is my page"><!--<link rel="stylesheet" type="text/css" href="styles.css">--> </head> <body> 上传成功!!<br> 用户名:<s:property value="username"/><br> 文件名:<s:property value="myFileFileName"/> </body></html>
- strus2文件上传
- Strus2上传文件大小
- ajaxupload控制客户端上传到使用strus2控制层服务器
- strus2使用commons-fileupload-1.3.1.jar工具包的图片上传
- strus2注解
- strus2注解
- strus2注解
- Strus2概览
- strus2中Action方法将 base64 字符串转成 图片文件实体
- 文件上传---文件上传
- Strus2的应用
- 解决strus2中文乱码
- 解决strus2中文乱码
- strus2 配置详解
- Strus2的处理流程
- Strus2学习笔记-02
- Mybatis+strus2+spring 整合
- strus2超简单实例
- P2P流媒体开源项目介绍
- NSString去掉换行符和空白字符
- 重构机房收费系统之文档 ---疑惑重重
- 用tar命令打包时如何排除指定文件和目录
- python_wxpython
- strus2文件上传
- android源代码之LruCache
- Coin Change(暴力枚举)
- 编译原理--文法分类和推导树
- 黑马程序员_高新代理
- Hybrid中的页面加载优化
- 【STM32l0B-LK1学习板】之六 例程5- 外部中断实验
- linux下安装Postgresql相关问题的解决
- 番茄工作法