判断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();
}
 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值