1

I have a SmartGWT app and in it a Filter in which I'm trying to figure out (on login) if the request should be forwarded (e.g. desktop to mobile). The code executes and the browser makes a get request but doesn't get a response and doesn't do a redirect. I've tried with http://google.com and that didn't work too so it must be something else.

public void doFilter(ServletRequest req, ServletResponse res,
        FilterChain chain) throws ServletException, IOException {

    HttpServletRequest request = (HttpServletRequest) req;
    HttpServletResponse response = (HttpServletResponse) res;
    HttpSession session = request.getSession();

    WURFLHolder wurfl = (WURFLHolder) getFilterConfig().getServletContext().getAttribute(WURFLHolder.class.getName());

    WURFLManager manager = wurfl.getWURFLManager();

    Device device = manager.getDeviceForRequest(request);

    boolean webBrowser = isWebBrowser(device);

    String path = ((HttpServletRequest) request).getRequestURI();

    boolean isBrowserOnMobile = true; // webBrowser && path.contains(MOBILE_REQ_PATH);

    boolean isMobileOnDesktop = !webBrowser && path.contains(DESKTOP_REQ_PATH);

    if (isBrowserOnMobile || isMobileOnDesktop) {
        if (isBrowserOnMobile) {
            path = "http://www.google.com";
        } else {
            path = "/PregledPredmeta/MobileAppEntryPoint.html";
        }
        response.encodeRedirectURL(path);
        response.sendRedirect(path);
        return;

......

4

1 回答 1

2

您在使用之前是否向 HTTP 响应发送了任何内容response.sendRedirect()?要使用 HTTP Redirect HEADER,您不能向浏览器发送任何响应。即使是空格或换行符/换行符也可以停止重定向。

如果您检查了所有代码并确保没有向浏览器发送任何内容,则可以使用 JavaScript 重定向<script>location.href='yoururl';</script>。它不是一个很酷的解决方案,但它确实有效。

于 2013-09-03T19:53:13.557 回答