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

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章