תÔØ jspËٳɾ«Òª
ServletÈý¸öÒªËØ:
1.±ØÐë¼Ì³Ð×ÔHttpServlet
2.±ØÐëʵÏÖdoGet()»òÕßdoPost()
3.±ØÐëÔÚweb.xmlÖÐÅäÖÃServlet
<servlet>
<servlet-name> </servlet-name>
<servlet-class> </servlet-class>
</servlet>
<servlet-mapping>
<servlet-name> </servlet-name>
<url-pattern> </url-pattern>
</servelt-mapping>
HttpServeltRrequest:ÇëÇó¶ÔÏó
getParameter():»ñµÃ±íµ¥ÔªËصÄÖµ
getAttribute():»ñµÃrequest·¶Î§ÖеÄÊôÐÔÖµ
setAttribute():ÉèÖÃreqeust·¶Î§ÖеÄÊôÐÔÖµ
setCharacterEncoding():ÉèÖÃ×Ö·û±àÂë
HttpSerletResponse:ÏàÓ¦¶ÔÏó
sendRedirect():ÍⲿÌøת
getWriter():»ñµÃÊä³öÁ÷¶ÔÏó
setContentType("text/html; charset=utf-8"):ÉèÖÃÏàÓ¦ÄÚÈݸñʽºÍ±àÂë
ËÄÖֻỰ¸ú×Ù·½Ê½:
1.Session
HttpSession session = request.getSession();
session.setAttribute("name", "zhangsan");
session.setAttribute("pwd", "aaa");
String name = (String) session.getAttribute("name");
2.cookie:
//´´½¨Cookie
Cookie cookie = new Cookie("name", "zhangsan");
//ÉèÖÃCookieµÄ³¬Ê±Ê±¼ä
cookie.setMaxAge(24 * 60 * 60 *60);
//°ÑCookie·¢Ë͵½¿Í»§¶Ë
response.addCookie(cookie);
//µÃµ½¿Í»§¶Ë·¢Ë͵ÄCookie
Cookie [] cookies = request.getCookies();
for(int i=0; i <cookies.length; i++) {
Cookie temp = cookies[i];
String key = temp.getName();
String value = temp.getValue();
}
3.Òþ²Ø±íµ¥Óò
<input type="hidden" name="name" value="zhangsan" />
request.getParameter("name");
4.UrlÖØд
ÎʺŴ«²Î
LoginServlet?username=zhangsan&pwd=123
String name = request.getParameter("username");
String pwd =request.getPareameter("pwd");
ÄÚ²¿Ìøת:
LoginServlet
request.getRequestDispatcher("index.jsp").forward(request, resposne);
ÍⲿÌøת:
response.sendRedirect("index.jsp");
ÄÚ²¿ÌøתÊÇÒ»´ÎÇëÇóºÍÒ»´ÎÏìÓ¦
ÍⲿÌøתÊÇÁ½´ÎÇëÇóºÍÁ½´ÎÏìÓ¦
ServletContext:ServletÉÏÏÂÎĶÔÏó
ËüÊÇÒ»¸ö¹«¹²ÇøÓò,¿ÉÒÔ±»ËùÓеĿͻ§¶Ë¹²Ïí
setAttribute():Ïò¹«¹²ÇøÓòÀï·ÅÈëÊý¾Ý
getAttribute():´Ó¹«¹²ÇøÓòÀïÈ¡Êý¾Ý
¶þ:
Èý:Èý¸ö±ê×¼·¶Î§:requ
Ïà¹ØÎĵµ£º
ÔÚjspÖУ¬Èç¹ûÔÚurlÖд«µÝÖÐÎÄʱ»á³öÏÖÂÒÂ룬ÔÚÍøÉϹØÓÚÕâÒ»ÎÊÌâµÄ½â¾ö·½·¨Î廨°ËÃÅ£¬µ«¶¼²»ÊǺÜ×àЧ£¡Æäʵ½â¾ö·½·¨·Ç³£¼òµ¥£º µÚÒ»²½£º±àÂ루ÒÔ´«µÝµÄ²ÎÊýΪstrΪÀý£© ÔÚ´«µÝÊý¾ÝÇ°½«str½øÐбàÂëJava.net.URLEncoder.encode(str) µÚ¶þ²½£º½âÂë ÔÚ»ñÈ¡Êý¾Ý¶Ë½«µÃµ½µÄÊý¾Ý½øÐнâÂë new String£¨str.getBytes("ISO8859_1")£©
......
GBK±àÂë
GBK±àÂëÊÇÖйúÖƶ©µÄ¡¢µÈͬÓÚUCSµÄеÄÖÐÎıàÂëÀ©Õ¹¹ú¼Ò±ê×¼¡£GBK¹¤×÷С×éÓÚ1995Äê10Ô£¬Í¬Äê12ÔÂÍê³ÉGBK¹æ·¶¡£¸Ã±àÂë±ê×¼¼æÈÝGB2312£¬¹²ÊÕ¼ºº×Ö21003¸ö¡¢·ûºÅ883¸ö£¬²¢Ìṩ1894¸öÔì×ÖÂë룬¼ò¡¢·±Ìå×ÖÈÚÓÚÒ»¿â¡£
UTF-8±àÂë
UTF-8±àÂë¿ÉÒÔͨ¹ýÆÁ±ÎλºÍÒÆλ²Ù×÷¿ìËÙ¶Áд¡£×Ö·û´®±È½Ïʱstrcmp()ºÍ
wcscmp()µÄ· ......
ÎÊÌâÈçÏ£º
֮ǰ,д¹ýÒ»¸öDownload.jspÎļþ,¿ÉÒÔ½â¾öÏÂÔØÎļþÂÒÂëÎÊÌâ(ÖîÈç:DOC,XSLÎļþµÈµÈ).
ºóÀ´·¢ÏÖ,Óöµ½ÖÐÎÄÃûµÄÎļþµÄʱºò,ÎļþÏÂÔؽ«»á±¨´í~~~~
½ñÌì,ͨ¹ý¸ÄдÔDownload.jspÎļþÒѾ³¹µ×½â¾öÁËÕâ¸öÎÊÌâ~
ÏÖÔÚ,°ÑÒ»ÕûÌ×µÄÎļþÉÏ´«ÏÂÔصķ½·¨¸øÌù³öÀ´~~~ÒÔ±ã´ó¼Ò½è¼ø!~!~!~!~!
×÷Õß:¹Å°£¼°·¨ÀÏ
download ......
JSPÄÚÖöÔÏó(9¸ö³£ÓõÄÄÚÖöÔÏó)
1.request¶ÔÏó
¿Í»§¶ËµÄÇëÇóÐÅÏ¢±»·â×°ÔÚrequest¶ÔÏóÖУ¬Í¨¹ýËü²ÅÄÜÁ˽⵽¿Í»§µÄÐèÇó£¬È»ºó×ö³öÏìÓ¦¡£ËüÊÇHttpServletRequestÀàµÄʵÀý¡£
ÐòºÅ ·½ ·¨ ˵ Ã÷
1 object getAttribute(String name) ·µ»ØÖ¸¶¨ÊôÐÔµÄÊôÐÔÖµ
2 Enumeration getAttributeNames() ·µ»ØËùÓпÉÓÃÊôÐÔÃû ......