Ò׽ؽØͼÈí¼þ¡¢µ¥Îļþ¡¢Ãâ°²×°¡¢´¿ÂÌÉ«¡¢½ö160KB

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;
     &


Ïà¹ØÎĵµ£º

jsp:forward±êÇ©ºÍresponse.sendRedirect()·½·¨µÄÇø±ð

ÔÚÍøÉÏ¿´µ½Ò»Ð©Ìû×Ó£¬×ܽáÁËһЩÇø±ð£¬¿ÉÒÔ´ÓÒÔϼ¸¸ö·½ÃæÀ´¿´£º
1.´ÓµØÖ·À¸ÏÔʾÀ´Ëµ
forwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´,·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL,°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´,È»ºó°ÑÕâЩÄÚÈÝ
ÔÙ·¢¸øä¯ÀÀÆ÷.ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝ´ÓÄÄÀïÀ´µÄ,ËùÒÔËüµÄµØÖ·À¸»¹ÊÇÔ­À´µÄµØÖ·.
redirectÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼­,·¢ËÍÒ»¸ö×´ ......

JSPÖеIJÎÊý´«µÝ·½·¨

£¨1£©ÀûÓÃ<jsp:param name="paramName" value="paramValue"></jsp:param>ÆäÖÐnameΪÓëÊôÐÔÏà¹ØÁªµÄ¹Ø¼ü´Ê£¬valueΪÊôÐÔµÄÖµ¡£
    ʾÀý£º´«³£Á¿×Ö·û´®<param name="userName" value="shilei"/>
    ʾÀý£º´«±äÁ¿ User user=new User("shilei");//UserÊÇÒ»¸öÀà
 &n ......

JSP±àÂ볣ʶ[ת]

GBK±àÂë
GBK±àÂëÊÇÖйúÖƶ©µÄ¡¢µÈͬÓÚUCSµÄеÄÖÐÎıàÂëÀ©Õ¹¹ú¼Ò±ê×¼¡£GBK¹¤×÷С×éÓÚ1995Äê10Ô£¬Í¬Äê12ÔÂÍê³ÉGBK¹æ·¶¡£¸Ã±àÂë±ê×¼¼æÈÝGB2312£¬¹²ÊÕ¼ºº×Ö21003¸ö¡¢·ûºÅ883¸ö£¬²¢Ìṩ1894¸öÔì×ÖÂë룬¼ò¡¢·±Ìå×ÖÈÚÓÚÒ»¿â¡£
UTF-8±àÂë
UTF-8±àÂë¿ÉÒÔͨ¹ýÆÁ±ÎλºÍÒÆλ²Ù×÷¿ìËÙ¶Áд¡£×Ö·û´®±È½Ïʱstrcmp()ºÍwcscmp()µÄ·µ»Ø½ ......

µ±jspºÍservlet³öÏÖÂÒÂëÎÊÌâºóµÄ½â¾ö·½°¸

ÉÏÍø¿´Á˺ö࣬¾ÍÕâһƪ½â¾öÁËÎÒµÄÎÊÌ⣬ÏÖת£¬ÎÒµÄÏîÄ¿ÓõÄÊÇMVC¼Ü¹¹£¬ÓÐͳһµÄ¿ØÖÆÆ÷£¬×ªÏò²»Í¬µÄAction£¬ÉÏÍø¿´Á˺ö࣬´ó²¿·ÖÊÇ˵¼ÓÈërequest.setCharacterEncoding("utf-8");µ«ÊǾ­¹ýÎÒµÄÊÔÑ飬ÕâÖ»ÓÐÔÚÀûÓÃJSP´¦Àí±íµ¥´«ÊäÊý¾Ýʱ²Å¿ÉÓã¬ÔÚÎҵĶ«Î÷ÖÐÎÞ·¨½â¾ö£¬ºóÀ´·¢ÏÖ»¹ÊÇÓÃFilterChainºÃ£¬ºÇºÇ£¬Öص㻹ÊÇÔÚrequest ......

JSPÄÚÖöÔÏóÊôÐÔ¼°·½·¨´óÈ«

1.request¶ÔÏó
    ¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚrequest¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇHttpServletRequestÀàµÄʵÀý¡£
ÐòºÅ                    ·½ ·¨      & ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ