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

תÔØ 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´«ÖÐÎÄ×î¼òµ¥ÕýÈ·µÄ·½·¨

ÔÚjspÖУ¬Èç¹ûÔÚurlÖд«µÝÖÐÎÄʱ»á³öÏÖÂÒÂ룬ÔÚÍøÉϹØÓÚÕâÒ»ÎÊÌâµÄ½â¾ö·½·¨Î廨°ËÃÅ£¬µ«¶¼²»ÊǺÜ×àЧ£¡Æäʵ½â¾ö·½·¨·Ç³£¼òµ¥£º µÚÒ»²½£º±àÂ루ÒÔ´«µÝµÄ²ÎÊýΪstrΪÀý£© ÔÚ´«µÝÊý¾ÝÇ°½«str½øÐбàÂëJava.net.URLEncoder.encode(str) µÚ¶þ²½£º½âÂë ÔÚ»ñÈ¡Êý¾Ý¶Ë½«µÃµ½µÄÊý¾Ý½øÐнâÂë new String£¨str.getBytes("ISO8859_1")£© ......

jspÂÒÂë½â¾ö


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

jsp´¦ÀíÂÒÂ뺯Êý

<%@ page language="java" contentType="text/html; charset=GBK" %>
<%!
 String   getCh(String   s)   {  
   try   {  
              String &nb ......

ASPÓëJSP ¹ØÓÚÒ³ÃæµÄÊäÈëºÍÊä³öµÄÎÊÌâ

Ò³ÃæµÄÊäÈëºÍÊä³öÉæ¼°µ½ÁËRequestºÍResponse,ÓÉÓÚËûÃǺÍJspÖеÄÏàËÆ,
ÏÂÃæÎÒÃǽøÐÐÏêϸµÄ½â¶Á£º
JSPÖУº
    ÔÚ¶¯Ì¬ÍøÒ³¿ª·¢ÖУ¬HTML±íµ¥ÊÇÓëÓû§½»»¥ÐÅÏ¢µÄÖ÷ÒªÊֶΡ£
    ʹÓÃJSP´¦Àí±íµ¥ÇëÇóʱ£¬Ò»°ã×ñÑ­ÕâÑùÒ»ÖÖģʽ£¬Ê×ÏÈ£¬Óû§Í¨¹ý±íµ¥¿Ø¼þÊäÈë²¢Ìá½»ÐÅÏ¢;½Ó×Å£¬JSPÒ³Ãæ»ñµÃ±íµ¥Êý ......

Jsp·½Ãæ

1¡¢forward ºÍredirectµÄÇø±ð
´ð£ºforwardÊÇ·þÎñÆ÷ÇëÇó×ÊÔ´£¬·þÎñÆ÷Ö±½Ó·ÃÎÊÄ¿±êµØÖ·µÄURL£¬°ÑÄǸöURLµÄÏìÓ¦ÄÚÈݶÁÈ¡¹ýÀ´£¬È»ºó°ÑÕâЩÄÚÈÝÔÙ·¢¸øä¯ÀÀÆ÷£¬ä¯ÀÀÆ÷¸ù±¾²»ÖªµÀ·þÎñÆ÷·¢Ë͵ÄÄÚÈÝÊÇ´ÓÄĶùÀ´µÄ£¬ËùÒÔËüµÄµØÖ·À¸Öл¹ÊÇÔ­À´µÄµØÖ·¡£
    redirect¾ÍÊÇ·þÎñ¶Ë¸ù¾ÝÂß¼­,·¢ËÍÒ»¸ö״̬Âë,¸æËßä ......
© 2009 ej38.com All Rights Reserved. ¹ØÓÚE½¡ÍøÁªÏµÎÒÃÇ | Õ¾µãµØͼ | ¸ÓICP±¸09004571ºÅ