首页 新闻 会员 周边 捐助

MyEclipse的Web开发网站打开为空白

0
悬赏园豆:15 [已关闭问题] 关闭于 2015-10-24 20:57

上面有4张图,以下是关于问题的描述:当我插入图一的语句配置Filter时,在URL上运行Web项目是空白页——见图二。当我去掉Filter那几行配置语句,恢复正常。为什么会这样?

SharpeyeKardel的主页 SharpeyeKardel | 初学一级 | 园豆:30
提问于:2015-10-23 17:23
< >
分享
所有回答(1)
0

贴filter代码看看

之奇一昂 | 园豆:1421 (小虾三级) | 2015-10-24 12:30
package com.qdu.com;

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;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletRequestWrapper;

public class FormFilter implements Filter{
    class Request extends HttpServletRequestWrapper{
        public Request(HttpServletRequest request){
            super(request);
        }
        public String toChi(String input){
            try{
                byte[] bytes = input.getBytes("ISO8859-1");
                return new String(bytes, "GBK");
                
            }catch(Exception ex){
                
            }
            return null;
        }
        private HttpServletRequest getHttpServletRequest(){
            return (HttpServletRequest)super.getRequest();
        }
        
        public String getParameter(String name){
            return toChi(getHttpServletRequest().getParameter(name));
        }
        
        public String[] getParameterValues(String name){
            String values[] = getHttpServletRequest().getParameterValues(name);
            if(values != null){
                for(int i= 0; i<values.length; i++){
                    values[i] = toChi(values[i]);
                }
            }
            return null;
        }
    }
    public void destroy(){
        
    }
    public void doFilter(ServletRequest request, ServletResponse response,
            FilterChain chain) throws IOException, ServletException{
        HttpServletRequest httpreq = (HttpServletRequest)request;
        if(httpreq.getMethod().equals("POST")){
            request.setCharacterEncoding("GBK");
        }else{
            request = new Request(httpreq);
        }
        chain.doFilter(request, response);
        
    }
    public void init(FilterConfig filterConfig)throws ServletException{
        
    }
}

 

支持(0) 反对(0) SharpeyeKardel | 园豆:30 (初学一级) | 2015-10-24 17:26

@SharpeyeKardel: 应该是你自己实现的request的事,如果你用POST请求那个URL也是返回空白页的话就能确定

支持(0) 反对(0) 之奇一昂 | 园豆:1421 (小虾三级) | 2015-10-24 21:17
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册