jspµÄ9¸öÄÚ½¨¶ÔÏó
ÔÚjspÖв»Óö¨Òå¿ÉÒÔÖ±½ÓÓõľÍÊÇjspµÄ9¸öÄÚ½¨¶ÔÏóÁË
1£¬Request 2,Response 3,session 4,out 5,page
6,application 7,pageContext 8,config
9,exception
1¡¢Request¶ÔÏó
¸Ã¶ÔÏó·â×°ÁËÓû§Ìá½»µÄÐÅÏ¢£¬Í¨¹ýµ÷ÓøöÔÏóÏàÓ¦µÄ·½·¨¿ÉÒÔ»ñÈ¡·â×°µÄÐÅÏ¢£¬¼´Ê¹ÓøöÔÏó¿ÉÒÔ
»ñÈ¡Óû§Ìá½»µÄÐÅÏ¢¡£
µ±Request¶ÔÏó»ñÈ¡¿Í»§Ìá½»µÄºº×Ö×Ö·ûʱ£¬»á³öÏÖÂÒÂëÎÊÌ⣬±ØÐë½øÐÐÌØÊâ´¦Àí¡£Ê×ÏÈ£¬½«»ñÈ¡µÄ
×Ö·û´®ÓÃISO-8859£1½øÐбàÂ룬²¢½«±àÂë´æ·¢µºÒ»¸ö×Ö½ÚÊý×éÖУ¬È»ºóÔÙ½«Õâ¸öÊý×éת»¯Îª×Ö·û´®¶ÔÏó
¼´¿É¡£ÈçÏ£º
String
textContent=request.getParameter("boy");
byte
b[]=textContent.getBytes("ISO-8859-1");
textContent=new String(b);
Request³£Óõķ½·¨£º
1.01 getParameter(String strTextName) »ñÈ¡±íµ¥Ìá½»µÄÐÅÏ¢¡£
String strName£½request.getParameter("name");
1.02 getProtocol()
»ñÈ¡¿Í»§Ê¹ÓõÄÐÒé¡£
String strProtocol=request.getProtocol();
1.03
getServletPath() »ñÈ¡¿Í»§Ìá½»ÐÅÏ¢µÄÒ³Ãæ¡£
String
strServlet=request.getServletPath();
1.04 getMethod()
»ñÈ¡¿Í»§Ìá½»ÐÅÏ¢µÄ·½Ê½£¬get|post¡£
String strMethod = request.getMethod();
1.05 getHeade() »ñÈ¡HTTPÍ·ÎļþÖеÄaccept¡¢accept-encodingºÍHostµÄÖµ¡£
String strHeader = request.getHeader("accept");
1.06
getRermoteAddr() »ñÈ¡¿Í»§µÄIPµØÖ·¡£
String strIP = request.getRemoteAddr();
1.07 getRemoteHost() »ñÈ¡¿Í»§»úµÄÃû³Æ¡£
String clientName =
request.getRemoteHost();
1.08 getServerName() »ñÈ¡·þÎñÆ÷Ãû³Æ¡£
String serverName = request.getServerName();
1.09
getServerPort() »ñÈ¡·þÎñÆ÷µÄ¶Ë¿ÚºÅ¡£
int serverPort = request.getServerPort();
1.10 getParameterNames() »ñÈ¡¿Í»§¶ËÌá½»µÄËùÓвÎÊýµÄÃû×Ö¡£
Enumeration enum =
request.getParameterNames();
while(enum.hasMoreElements()){
String
s=(String)enum.nextElement();
out.println(s);
}
2¡¢Response¶ÔÏó
¶Ô¿Í»§µÄÇëÇó×ö³ö¶¯Ì¬µÄÏìÓ¦£¬Ïò¿Í»§¶Ë·¢ËÍÊý¾Ý¡£
2.1 ¶¯Ì¬ÏìÓ¦contentTypeÊôÐÔ
µ±Ò»¸öÓû§·ÃÎÊÒ»¸öJSPÒ³Ãæʱ£¬Èç¹û¸ÃÒ³ÃæÓÃpageÖ¸ÁîÉèÖÃÒ³ÃæµÄcontentTypeÊôÐÔʱtext/html£¬ÄÇôJSPÒýÇ潫°´ÕÕÕâ¸öÊôÐÔÖµ×ö³ö·´Ó¦¡£Èç¹ûÒª¶¯Ì¬¸Ä±äÕâ»»¸öÊôÐÔÖµÀ´Ï
Ïà¹ØÎĵµ£º
ÔÚ·ÃÎÊJSPÎļþ»òÕßServletµÄʱºò£¬Èç¹ûÌáʾÏÂÔز¢±£´æ£¬ÈçÏÂͼËùʾ£º
ͬÑùµÄ³ÌÐòÓеÄä¯ÀÀÆ÷³ö´í£¬ÓеÄä¯ÀÀÆ÷²»³ö´í¡£´íÎóµÄÔÒòÊÇÉèÖÃMIMEÀàÐ͵ĴúÂëÓÐÎó¡£
Èç¹ûÊÇJSPÎļþ£¬²é¿´ÎļþÍ·£º
<%@ page contentType="text/html;charset=gb2312"%>
Èç¹ûÊÇServletÎļþ£¬²é¿´£º
response.setContentType("text/html;char ......
http:/localhost/123/jsp/test.jsp:
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %>
<%@ taglib uri="http://struts.apache.org/tags-logi ......
Servlet£º
ÔÚServletÖУ¬ÌøתÔÚdoGet»òÕßdoPost·½·¨ÖÐʵÏÖ¡£
<1>redirectʵÏÖÒ³ÃæÌøת£º
response.sendRedirect("/login.jsp");
·½·¨µÄ²ÎÊýÊÇÏà¶Ô·¾¶£¬É趨Õâ¸ö²ÎÊý¿ÉÒÔʹҳÃæÌøתµ½ÈκÎÒ³Ã棬°üÀ¨www.baidu.comµÈÍøÂçÒ³Ãæ¡£
ÌøתºóÄã¿ÉÒÔ·¢ÏÖµØÖ·À¸·¢ÉúÁ˱仯¡£
µ×²ãÔÀí£ºÊ¹ÓÃredir ......
GBK±àÂë
GBK±àÂëÊÇÖйúÖƶ©µÄ¡¢µÈͬÓÚUCSµÄеÄÖÐÎıàÂëÀ©Õ¹¹ú¼Ò±ê×¼¡£GBK¹¤×÷С×éÓÚ1995Äê10Ô£¬Í¬Äê12ÔÂÍê³ÉGBK¹æ·¶¡£¸Ã±àÂë±ê×¼¼æÈÝGB2312£¬¹²ÊÕ¼ºº×Ö21003¸ö¡¢·ûºÅ883¸ö£¬²¢Ìṩ1894¸öÔì×ÖÂë룬¼ò¡¢·±Ìå×ÖÈÚÓÚÒ»¿â¡£
UTF-8±àÂë
UTF-8±àÂë¿ÉÒÔͨ¹ýÆÁ±ÎλºÍÒÆλ²Ù×÷¿ìËÙ¶Áд¡£×Ö·û´®±È½Ïʱstrcmp()ºÍwcscmp()µÄ·µ»Ø½ ......