zoukankan      html  css  js  c++  java
  • 判断WAP1.1和WAP2.0并解析为wml或xhtml

    首先通过取得accept
    java是 request.getHeader("accept")
    .net 是 Request.ServerVariables("HTTP_Accept")



        /**
         * 功能:输出xml为wml1.1(wap1.0)
         * @param doc
         * @param response
         * @throws IOException
         */
        public static void OutPrintWAP11(Document doc, HttpServletResponse response) throws IOException {
            response.setCharacterEncoding("utf-8");
            response.setContentType("text/vnd.wap.wml");
            response.setHeader("Cache-Control", "no-cache, must-revalidate");
            PrintWriter out = response.getWriter();
            OutputFormat format = OutputFormat.createCompactFormat();
            //去掉xml头
            format.setSuppressDeclaration(true);
            format.isPadText();
            format.setEncoding("utf-8");
            XMLWriter writer = new XMLWriter(out, format);
            //加上wml头,保证wap协议访问        
            doc.addDocType("wml", "-//WAPFORUM//DTD WML 1.1//EN", "http://www.wapforum.org/DTD/wml_1.1.xml");    
            writer.write(doc);
            writer.flush();
    }
         
       
        /**
         * 功能:输出xml为xhtml(wap2.0)
         * @param doc
         * @param response
         * @throws IOException
         */
        public static void OutPrintWAP20(Document doc, HttpServletResponse response) throws IOException {
            response.setCharacterEncoding("utf-8");
            response.setContentType("application/vnd.wap.xhtml+xml");
            response.setHeader("Cache-Control", "no-cache, must-revalidate");
            PrintWriter out = response.getWriter();
            OutputFormat format = OutputFormat.createCompactFormat();
            //去掉xml头
            format.setSuppressDeclaration(true);
            format.isPadText();
            format.setEncoding("utf-8");
            XMLWriter writer = new XMLWriter(out, format);
            //加上wml头,保证wap协议访问       
            doc.addDocType("html", "-//WAPFORUM//DTD XHTML Mobile 1.0//EN", "http://www.wapforum.org/DTD/xhtml-mobile10.dtd");   
            writer.write(doc);
            writer.flush();
    }






  • 相关阅读:
    Javascript操作cookie
    上传文件-layui+ashx
    Mysql对查询结果添加序列号
    Maven详解
    解决 go iris ReadJSON 无法获取 json,并提示 unexpected end of JSON input 的错误
    Archlinux 最新安装方法 (2020.07.01-x86_64)之虚拟机 BIOS 安装
    Oracle APEX 发送邮件
    包管理Go module的使用
    Golang 解决 Iris 被墙的依赖包
    解决 Nginx 代理Apex慢的问题
  • 原文地址:https://www.cnblogs.com/yesun/p/501875.html
Copyright © 2011-2022 走看看