JavaµÄFilter Ò»£º£¨×ªÔØ£©
¹Ø¼ü×Ö: filter
¹ýÂËÆ÷FilterÒ²¾ßÓÐÉúÃüÖÜÆÚ£ºinit()->doFilter()->destroy()£¬Óɲ¿ÊðÎļþÖеÄfilterÔªËØÇý¶¯¡£ÔÚservlet2.4ÖУ¬¹ýÂËÆ÷ͬÑù¿ÉÒÔÓÃÓÚÇëÇó·ÖÅÉÆ÷£¬µ«ÐëÔÚweb.xmlÖÐÉùÃ÷£¬<dispatcher>INCLUDE»òFORWARD»òREQUEST»òERROR</dispatcher>¸ÃÔªËØλÓÚfilter-mappingÖС£
Ò»¡¢ÅúÁ¿ÉèÖÃÇëÇó±àÂë
Java´úÂë
public class EncodingFilter implements Filter {
private String encoding = null;
public void destroy() {
encoding = null;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
String encoding = getEncoding();
if (encoding == null){
encoding = "gb2312";
}
request.setCharacterEncoding(encoding);// ÔÚÇëÇóÀïÉèÖÃÉÏÖ¸¶¨µÄ±àÂë
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException {
this.encoding = filterConfig.getInitParameter("encoding");
}
private String getEncoding() {
&nbs
Ïà¹ØÎĵµ£º
Èç¹û·þÎñÆ÷Èç¹ûûÓвÉÓ÷´Ïò´úÀí£¬¶øÇÒ¿Í»§¶ËûÓÐÓÃÕýÏò´úÀíµÄ»°£¬
ÄÇô¿ÉÒÔ»ñÈ¡¿Í»§¶ËµÄÕæʵIPµØÖ·request.getRemoteAddr()
Èç¹û·þÎñÆ÷Èç¹ûûÓвÉÓ÷´Ïò´úÀí£¬¶øÇÒ¿Í»§¶ËÓÐÓÃÕýÏò´úÀíµÄ»°£¬
&nbs ......
ÍøÉÏ¿´µ½Ò»Ð©¸Õ¿ªÊ¼Ñ§»òÊÇ»¹Ã»ÓпªÊ¼Ñ§javaµÄͬѧ£¬¾³£ÎÊ£º“Õâ¸öjava£¬ÎÒ¸ÃÔõôѧ£¬Ñ§Ê²Ã´ÄØ£¿”£¬ÎÒÏë¸øËûÃÇ˵һÏ¡£¿ÉÊÇÎÒµÄÄÜÁ¦ÓÐÏÞ¡£ËùÒÔÎÒÒ²²»ºÃ¶Ôij¸öͬѧ¾ßÌåµÄ˵ʲô£¬¿ÉÊÇ£¬½ñÌìÔÚÍøÉÏ¿´µ½Ò»ÕÅͼƬ¡£¸Ð¾õ¶Ô´ó¼ÒÌá³öµÄÕâ¸öÎÊÌâÓиöºÜºÃµÄ½âÊÍ˵Ã÷¡£
  ......
javaģʽ֮µ¥Àýģʽ£º
µ¥Àýģʽȷ±£Ò»¸öÀàÖ»ÓÐÒ»¸öʵÀý£¬×ÔÐÐÌṩÕâ¸öʵÀý²¢ÏòÕû¸öϵͳÌṩÕâ¸öʵÀý¡£
Ìص㣺
1£¬Ò»¸öÀàÖ»ÄÜÓÐÒ»¸öʵÀý
2£¬×Ô¼º´´½¨Õâ¸öʵÀý
& ......
ʵ¼ÊÉÏ£¬ÎÒ¹ØÓÚjavaµÄ»ù´¡ÖªÊ¶µÄ90%ÒÔÉ϶¼À´×ÔThinking in Java¡£¶ÔÓÚÆäÖеÄsynchronized¹Ø¼ü×Ö£¬µ±Ê±¾ÍÊÇä¯ÀÀһϣ¬´ó¸ÅÖªµÀÒâ˼£¬Ò²Ã»ÓÐϸ¿´¡£ºóÀ´Ò»Ö±Ã»ÓÐÓùýÕâ¸ö¹Ø¼ü×Ö¡£×òÌì¿´Thinking in Patterns with JavaÖеÄObserverģʽ£¬¿´ÁËÆäÖеÄObservableÀàµÄÔ´Â룬·¢ÏÖÀïÃ漸ºõËùÓеķ½·¨¶¼ÓÃÁËsynchronized¹Ø¼ü×Ö£¨²»ÊÇÈ ......