• 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>
  • 相关阅读:
    LoRa硬件调试-前导码
    LoRaWAN调试踩坑心得(二)
    LoRaWAN调试踩坑心得(一)
    LoRaWAN_stack移植笔记(七)_数据包的接收发送
    LoRaWAN协议(七)--完整数据流程
    Android Studio Error while executing: am start -n错误解决方案
    Spring系列(八)
    并发工具类简介
    CAS
    多线程基础(一)线程创建
  • 原文地址:https://www.cnblogs.com/jentary/p/10977670.html
Copyright © 2020-2023  润新知