• struts2


    1.action 乱码

    <constant name="struts.i18n.encoding" value="GBK"/>

    2.action 获取上下文

                //ServletActionContext.getRequest().setCharacterEncoding("UTF-8");
                //String t = ServletActionContext.getRequest().getParameter("title");
                //result = new String(input.getBytes("iso-8859-1"),"utf-8");
                
                /*String requestEncoding = ServletActionContext.getRequest().getCharacterEncoding();
                String responseEncoding = ServletActionContext.getResponse().getCharacterEncoding();

    3.struts2文件下载

    <action name="downloadHistory" class="HistoryAction" method="download">
                <result name="success" type="stream">
                    <!-- 下载文件的文件类型 -->
                    <param name="contentType">${contentType}</param>
                    <!-- 下载文件的来源流 -->
                    <param name="inputName">inputStream</param>
                    <param name="contentDisposition">attachment;filename="${fileName}"</param>
                    <!-- 指定下载文件的缓冲大小 -->
                    <param name="bufferSize">1024000</param>
                </result>
            </action>
    /**
         * 下载附件
         * @return
         */
        public String download(){
            try{
                Map<String,String> map=new HashMap<String,String>();
                map.put("id", id);
                HistoryWebService historyWebService = new HistoryWebService();
                Map resultMap=historyWebService.selectFujian(map);
                DoctranFujianBean fujian=null;
                if(resultMap!=null && !resultMap.isEmpty()){
                    fujian=(DoctranFujianBean)resultMap.get("fujian");
                    fileName=fujian.getFilename();
                    fileName = new String(fileName.getBytes(), "ISO8859-1"); 
                    contentType=fujian.getFiletype();
                    inputStream=new ByteArrayInputStream(fujian.getFilecontent());
                }
                return SUCCESS;
            }catch(Exception e){
                log.error(e.toString());
                e.printStackTrace();
                return NONE;
            }
            
        }

    struts2返回json

    public String info(){

    HttpServletResponse response = ServletActionContext.getResponse(); response.setContentType("text/html;charset=GBK");
    response.getWriter().print(strInfo);
    return null;
    }

    struts2 返回freemarker

    <action name="account_*" class="LocalAccountAction" method="{1}">
                <result name="success" type="freemarker">
                    <param name="location">/com/jit/ftl/structure.ftl</param>  
                    <param name="contentType">application/xml</param>  
                </result>
                <result name="getlocal">localaccount.jsp</result>
            </action>        

    struts2 重定向

    <action name="deleteByDidFromInbox" class="InboxAction" method="deleteByDid">
                <result name="inboxAction" type="redirect-action">
                    <param name="actionName">inbox</param>
                </result>
            </action>

     struts2 重定向传参

    <action name="recieve" class="RecieveAction">
                <result name="success" type="redirect-action">
                    <param name="actionName">inbox</param>
                    <param name="receiveNum">${receiveNum}</param>
                    <param name="saveNum">${saveNum}</param>
                    <param name="errNum">${errNum}</param>
                    <param name="errInfo">${errInfo}</param>
                </result>
                <result name="forwardDraftAction" type="redirect-action">
                    <param name="actionName">draftbox</param>
                </result>
                <result name="sessionOut">error/sessionout.jsp</result>
            </action>
  • 相关阅读:
    Linux下搭建DNS服务器
    Linux下安装Oracle客户端
    CentOS下配置LVM和RAID
    Linux下配置MySQL主从复制
    Linux下二进制文件安装MySQL
    不偏移的天地图地图服务
    Lucene
    Arcpy处理修改shapefile FeatureClass 线要素坐标
    使用ArcGIS实现WGS84经纬度坐标到北京54高斯投影坐标的转换
    ArcGIS自定义坐标变换中的方法说明
  • 原文地址:https://www.cnblogs.com/jentary/p/10977670.html
Copyright © 2020-2023  润新知