struts2图片上传并且显示(注意乱码)
来源:互联网 发布:大数据的工资待遇 编辑:程序博客网 时间:2024/06/03 20:17
struts2图片上传并且显示(注意乱码)
web.xml:
<?xml version="1.0" encoding="UTF-8"?> <web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"> <filter> <filter-name>strut2</filter-name> <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class> </filter> <filter-mapping> <filter-name>strut2</filter-name> <url-pattern>/*</url-pattern> </filter-mapping> <welcome-file-list> <welcome-file>index.jsp</welcome-file> </welcome-file-list> </web-app>
上传的页面 index.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>Struts2 Common File Upload</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> <h3>Struts2 文件上传到服务器</h3> <form action="fileUpload" method="post" enctype="multipart/form-data"> 文件:<input type="file" name="fileImage"/> <input type="submit" value="上传"/> </form> <s:fielderror/> </body> </html>
struts.xml文件的action :
<!DOCTYPE struts PUBLIC "-//Aoacge Siftware Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <!-- 解决乱码 --> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <package name="com.upload.imageupload" extends="struts-default"> <action name="fileUpload" class="com.upload.imageupload.ImageFileUpload" method="execute"> <result name="success">upload.jsp</result> <result name="error">error.jsp</result> <!-- 动态设置savePath的属性值 --> <!-- <param name="savePath">/images</param> --> <interceptor-ref name="fileUpload"> <!-- 文件过滤 --> <param name="allowedTypes">image/bmp,image/png,image/gif,image/jpeg,image/jpg</param> <!-- 文件大小, 以字节为单位 --> <param name="maximumSize">1024*20</param> </interceptor-ref> <!-- 默认拦截器必须放在fileUpload之后,否则无效 --> <interceptor-ref name="defaultStack" /> <result name="input">index.jsp</result> </action> </package> </struts>
上传成功的页面 upload.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>图片上传成功</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></br> <img src="${pageContext.request.contextPath}/<s:property value="'images/'+fileImageFileName"/>"> <s:debug></s:debug> </body> </html>
注意!上传中文名称会出现问题:
需要在tomcat的server.xml中加入URIEncoding=”utf-8” (网页的编码是utf-8)
0 0
- struts2图片上传并且显示(注意乱码)
- PHP上传图片并且显示
- nodejs之上传图片并且显示图片
- 上传图片并且显示所略图
- struts2上传图片和显示图片
- struts2上传图片后并显示图片
- Struts2上传文件带中文名时.图片显示会出现%乱码解决
- struts2文件上传图片中文乱码
- Struts2文件(图片)上传及页面显示
- 用asp.net 多文件上传 (并且图片即使显示)并隐藏上一个文件选择器
- 选择多张图片上传显示,并且删除。
- 将一张图片上传并且在某个div进行显示
- Struts2上传注意
- struts2 uploadify 批量上传图片文件名出现乱码
- AFNetworking 上传图片 (相册、拍照,并且图片可裁剪)
- SpringMVC+Ajax用FormData对象上传页面的图片(文件),并且立马在页面上显示出来
- 上传图片,显示,并且把图片信息存储到数据库表中9.17
- Node.js零起点开发(七)-上传图片并且显示图片
- 一些概念
- bzoj4597 [Shoi2016]随机序列
- 队列
- thinkphp5.0 在nginx下的配置
- android
- struts2图片上传并且显示(注意乱码)
- 实现主函数将年、月、日(结构体类型)传递给days函数,days函数计算该年该月该日是该年的第几天并传回主函数输
- Codeforces Round #386 (Div. 2) A+B+C+D!
- Exploit Development – 使用SEH绕过Security Cookie
- spring--filter如何注入 spring管理的bean(54)
- Windows Ubuntu 下多个版本OpenCV配置及使用
- 移动端H5页面的设计稿尺寸
- 结束JVM的方法,System.exit(int status)和Runtime类中的halt(int status)
- 支付宝接口开发总结