CommonParamsFilter 关于sos ssid等

package com.renren.wap.fuxi.filter;

import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;

/**
 * Servlet Filter implementation class CommonParamsFilter
 */
public class CommonParamsFilter implements Filter {

    /**
     * @see Filter#destroy()
     */
    public void destroy() {
        // TODO Auto-generated method stub
    }

    /**
     * @see Filter#doFilter(ServletRequest, ServletResponse, FilterChain)
     */
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
            throws IOException, ServletException {
        String osStr = request.getParameter("os");
        String osVersionStr = request.getParameter("os_version");
        String appIdStr = request.getParameter("appid");
        String touchStr = request.getParameter("touch");
        try {
            int os = Integer.valueOf(osStr);
            request.setAttribute("os", os);
            request.setAttribute("sos", "&os=" + os);
        } catch (Exception e) {}
        if (osVersionStr != null) {
            request.setAttribute("osVersion", osVersionStr);
            request.setAttribute("sosVersion", "&os_version=" + osVersionStr);
        }
        if (appIdStr != null) {
            int appId = Integer.valueOf(appIdStr);
            request.setAttribute("appId", appId);
            request.setAttribute("sappId", "&appid=" + appIdStr);
        }
        if (touchStr != null) {
            request.setAttribute("touch", touchStr);
            request.setAttribute("stouch", "&touch=" + touchStr);
        }
        chain.doFilter(request, response);
    }

    /**
     * @see Filter#init(FilterConfig)
     */
    public void init(FilterConfig fConfig) throws ServletException {
        // TODO Auto-generated method stub
    }

}

你可能感兴趣的:(filter)