JSPÖÐfilter¹ýÂËÆ÷ÑéÖ¤Óû§µÇ¼
JSPÖÐfilter¹ýÂËÆ÷ÑéÖ¤Óû§µÇ¼
ÏÖÔÚJSPʹÓÃÔ½À´Ô½¹ã·ºÁË£¬ÓÈÆäÊǺܶàÕþ¸®µÄÍøÕ¾¶¼²ÉÓÃÁËJSP¼¼Êõ£¬Æ书ÄÜÇ¿´óÇÒ°²È«¡£
³õѧÕߺܶàÓÐÕâô¸öÎÊÌ⣬¾ÍÊÇ£¬ÍøÕ¾µÄÒ»¸öȨÏÞÉèÖ㬱ÈÈçµÇ¼Óû§¿ÉÒԲ鿴ÄÄЩҳÃ棬¶øÓοÍÓÖÓÐȨÏÞ¿ÉÒÔ¿´ÄÄЩÄÚÈÝÄØ£¿
JSPÊÇÇ¿´óµÄ£¬µ«Æä´úÂ뻹ÊÇÏà¶Ô·±ËöµÄ£¬ÆäʵÓÃÒ»¸ö¹ýÂËÆ÷(filter)¾Í¿ÉÒÔʵÏÖÕâ¸ö¹¦ÄÜÁË¡£
ÒÔÏÂΪUserFilteµÄ´úÂ룺
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.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import User;
import UserDAO;
import SessionUtils;
public class UserFilter implements Filter
{
String nofilter;
String nofilterFiles[];
String sendRedirect;
public void destroy()
{
}
public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException
{
HttpServletRequest request=(HttpServletRequest)req;
HttpServletResponse response=(HttpServletResponse)res;
&
Ïà¹ØÎĵµ£º
ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËһЩÇø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔÀ´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼,·¢ËÍÒ»¸ö×´ ......
£¨1£©ÀûÓÃ<jsp:param name="paramName" value="paramValue"></jsp:param>ÆäÖÐnameΪÓëÊôÐÔÏà¹ØÁªµÄ¹Ø¼ü´Ê£¬valueΪÊôÐÔµÄÖµ¡£
ʾÀý£º´«³£Á¿×Ö·û´®<param name="userName" value="shilei"/>
ʾÀý£º´«±äÁ¿ User user=new User("shilei");//UserÊÇÒ»¸öÀà
&n ......
GBK±àÂë
GBK±àÂëÊÇÖйúÖƶ©µÄ¡¢µÈͬÓÚUCSµÄеÄÖÐÎıàÂëÀ©Õ¹¹ú¼Ò±ê×¼¡£GBK¹¤×÷С×éÓÚ1995Äê10Ô£¬Í¬Äê12ÔÂÍê³ÉGBK¹æ·¶¡£¸Ã±àÂë±ê×¼¼æÈÝGB2312£¬¹²ÊÕ¼ºº×Ö21003¸ö¡¢·ûºÅ883¸ö£¬²¢Ìṩ1894¸öÔì×ÖÂë룬¼ò¡¢·±Ìå×ÖÈÚÓÚÒ»¿â¡£
UTF-8±àÂë
UTF-8±àÂë¿ÉÒÔͨ¹ýÆÁ±ÎλºÍÒÆλ²Ù×÷¿ìËÙ¶Áд¡£×Ö·û´®±È½Ïʱstrcmp()ºÍwcscmp()µÄ·µ»Ø½ ......
ÉÏÍø¿´Á˺ö࣬¾ÍÕâһƪ½â¾öÁËÎÒµÄÎÊÌ⣬ÏÖת£¬ÎÒµÄÏîÄ¿ÓõÄÊÇMVC¼Ü¹¹£¬ÓÐͳһµÄ¿ØÖÆÆ÷£¬×ªÏò²»Í¬µÄAction£¬ÉÏÍø¿´Á˺ö࣬´ó²¿·ÖÊÇ˵¼ÓÈërequest.setCharacterEncoding("utf-8");µ«ÊǾ¹ýÎÒµÄÊÔÑ飬ÕâÖ»ÓÐÔÚÀûÓÃJSP´¦Àí±íµ¥´«ÊäÊý¾Ýʱ²Å¿ÉÓã¬ÔÚÎҵĶ«Î÷ÖÐÎÞ·¨½â¾ö£¬ºóÀ´·¢ÏÖ»¹ÊÇÓÃFilterChainºÃ£¬ºÇºÇ£¬Öص㻹ÊÇÔÚrequest ......
1.request¶ÔÏó
¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚrequest¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇHttpServletRequestÀàµÄʵÀý¡£
ÐòºÅ ·½ ·¨ & ......