`
xiaokanrensheng87
  • 浏览: 2831 次
社区版块
存档分类
最新评论
收藏列表
标题 标签 来源
过滤器分别对ajax,url处理 java jsp filter基于不同请求(ajax,url)过滤返回不同结果
   if (flag) {                //flag:是否通过过滤
	    	filterChain.doFilter(servletRequest, servletResponse);
	    } else {
	    	String requestType =(String) ((HttpServletRequest)servletRequest).getHeader("X-Requested-With"); 
	    	if (requestType != null && requestType.equals("XMLHttpRequest")) {
			  	 try{
			        JSONObject json = new JSONObject();  
			        json.put("returncode", "-1");  
			        PrintWriter pw = servletResponse.getWriter();  
			        pw.print(json.toString());  
			        pw.close();  
			  	 } catch (org.codehaus.jettison.json.JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				 }
	    	
	    	}else{
	    		HttpServletResponse httpServletResponse = (HttpServletResponse)servletResponse;
		  	    httpServletResponse.sendRedirect("/cardIssue/login.jsp");
	    	}
	      
	    }
线程安全 java concurrentHashMap是线程安全且强一致性的吗?
/**
* ConcurrentHashMap list entry. Note that this is never exported
* out as a user-visible Map.Entry.
*
* Because the value field is volatile, not final, it is legal wrt
* the Java Memory Model for an unsynchronized reader to see null
* instead of initial value when read via a data race.  Although a
* reordering leading to this is not likely to ever actually
* occur, the Segment.readValueUnderLock method is used as a
* backup in case a null (pre-initialized) value is ever seen in
* an unsynchronized access method.
*/
static final class HashEntry<K,V> {
        final K key;
        final int hash;
        volatile V value; // <-- volatile
        final HashEntry<K,V> next;
}
Global site tag (gtag.js) - Google Analytics