当前位置:首页 > 开发 > Web前端 > JavaScript > 正文

wap jsp 开发

发表于: 2011-10-31   作者:cooler1217   来源:转载   浏览:
摘要: wap 学习-3 jsp中使用wml  2010-05-03 16:44:15|  分类: WAP |字号 订阅 wml有两个版本;1.0,2.0 1.0 在JSP中,使用如下 <?xml version="1.0"?> <%@page contentType="text/vnd.wap.wml; charset
wap 学习-3 jsp中使用wml 

2010-05-03 16:44:15|  分类: WAP |字号 订阅
wml有两个版本;1.0,2.0

1.0 在JSP中,使用如下
<?xml version="1.0"?>
<%@page contentType="text/vnd.wap.wml; charset=gb2312"%>
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
或者
<%@page contentType="text/vnd.wap.wml; charset=gb2312"%><?xml version="1.0"?> //这里不能换行
<!DOCTYPE wml PUBLIC "-//WAPFORUM//DTD WML 1.1//EN" "http://www.wapforum.org/DTD/wml_1.1.xml">
否则,使用Opera浏览器浏览无法按wml进行解析浏览

wml的content-type为:text/vnd.wap.wml
mime类型:application/vnd.wap.wml

或者在web.xml中进行全局设置:
public class SetContentTypeFilter implements Filter {
private String contentType;
private String encoding;
public void init(FilterConfig filterConfig) throws ServletException {
contentType = filterConfig.getInitParameter("contentType");
encoding = filterConfig.getInitParameter("encoding");
}

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException,
ServletException {
HttpServletRequest httpServletRequest = (HttpServletRequest) request;
HttpServletResponse httpServletResponse = (HttpServletResponse) response;

httpServletRequest.setCharacterEncoding(encoding);
httpServletResponse.setContentType(contentType);
httpServletResponse.setCharacterEncoding(encoding);

chain.doFilter(httpServletRequest, httpServletResponse);
}
public void destroy() {
}
}
web.xml
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>com.infowarelab.wap.filter.SetContentTypeFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>contentType</param-name>
<param-value>text/vnd.wap.wml</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
注:若使用了struts2+freemarker,必须设置freemarker result-type 的 content-type="text/vnd.wap.wml",否则freemarker默认会使用text/html,即使设置了过滤器也无效

2.0 在JSP中,使用如下
<?xml version="1.0" encoding="utf-8"?>
<!DOCTYPE html PUBLIC "-//WAPFORUM//DTD XHTML Mobile 1.0//EN" "http://www.wapforum.org/DTD/xhtml-mobile10.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta http-equiv="Pragma" content="no-cache"/>
<meta http-equiv="Cache-Control" content="no-cache"/>
<meta http-equiv="Expires" content="0"/>
<link href="/wml/info/style.css" rel="stylesheet" type="text/css" />
<title>我的网易</title>
</head>
<body>
<div id="body" style="width:100%;">

一个web应用同时使用1.0,2.0
使用不同的前缀(如/v1,/v2)来区分两个版本的访问,然后使用过滤器对每个版本统一处理
    <filter>
        <filter-name>encodingFilter</filter-name>
        <filter-class>com.infowarelab.wap.filter.SetCharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
    </filter>
    <filter>
        <filter-name>contentTypeFilter</filter-name>
        <filter-class>com.infowarelab.wap.filter.SetContentTypeFilter</filter-class>
        <init-param>
            <param-name>contentType</param-name>
            <param-value>text/vnd.wap.wml</param-value>
        </init-param>
    </filter>
    <filter-mapping>
        <filter-name>encodingFilter</filter-name>
        <url-pattern>/*</url-pattern>  //v1,v2都需要进行编码设置
    </filter-mapping>
    <filter-mapping>
        <filter-name>contentTypeFilter</filter-name>
        <url-pattern>/v1/*</url-pattern>  //只有v1需要修改content type设置
    </filter-mapping>

wap jsp 开发

  • 0

    开心

    开心

  • 0

    板砖

    板砖

  • 0

    感动

    感动

  • 0

    有用

    有用

  • 0

    疑问

    疑问

  • 0

    难过

    难过

  • 0

    无聊

    无聊

  • 0

    震惊

    震惊

版权所有 IT知识库 CopyRight © 2009-2015 IT知识库 IT610.com , All Rights Reserved. 京ICP备09083238号