发布于 2015-12-24 23:24:08 | 172 次阅读 | 评论: 1 | 来源: PHPERZ

这里有新鲜出炉的精品教程,程序狗速度看过来!

Struts Java MVC框架

Struts 是Apache软件基金会(ASF)赞助的一个开源项目。它最初是Jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目。它通过采用JavaServlet/JSP技术,实现了基于Java EEWeb应用的MVC设计模式的应用框架,是MVC经典设计模式中的一个经典产品。


  1. 设置Tomcat编码格式为UTF-8:修改tomcat-->conf-->server.xml文件,设置URIEncoding为UTF-8,不设置时默认值为ISO8859-1

    <Connector port="8080" protocol="HTTP/1.1"
                   connectionTimeout="20000"
                   redirectPort="8443" URIEncoding="UTF-8"/>

    <Connector port="8009" protocol="AJP/1.3" redirectPort="8443" URIEncoding="UTF-8"/>

  2. 项目及Java文件,JSP文件格式当然也要是UTF-8

  3. java代码

    /**
         * 设置下载文件名
         * @param downloadFileName
         */
        public void setDownloadFileName(String downloadFileName) {
            try {
                HttpServletRequest request=ServletActionContext.getRequest();
                if (request.getHeader("User-Agent").toLowerCase()
                        .indexOf("firefox") > 0) {
                    this.downloadFileName = "=?UTF-8?B?"
                            + (new String(org.apache.commons.codec.binary.Base64.encodeBase64(downloadFileName
                                    .getBytes("UTF-8")))) + "?=";
                } else {
                    this.downloadFileName = java.net.URLEncoder.encode(
                            downloadFileName, "UTF-8");
                }
            } catch (UnsupportedEncodingException e) {
                e.printStackTrace();
            }
        }



最新网友评论  共有(1)条评论 发布评论 返回顶部
tjlj 发布于2016-04-10 04:11:15
还能再仔细点吗?
支持(0)  反对(0)  回复

Copyright © 2007-2017 PHPERZ.COM All Rights Reserved   冀ICP备14009818号  版权声明  广告服务