µ±jspºÍservlet³öÏÖÂÒÂëÎÊÌâºóµÄ½â¾ö·½°¸
ÉÏÍø¿´Á˺ö࣬¾ÍÕâһƪ½â¾öÁËÎÒµÄÎÊÌ⣬ÏÖת£¬ÎÒµÄÏîÄ¿ÓõÄÊÇMVC¼Ü¹¹£¬ÓÐͳһµÄ¿ØÖÆÆ÷£¬×ªÏò²»Í¬µÄAction£¬ÉÏÍø¿´Á˺ö࣬´ó²¿·ÖÊÇ˵¼ÓÈërequest.setCharacterEncoding("utf-8");µ«ÊǾ¹ýÎÒµÄÊÔÑ飬ÕâÖ»ÓÐÔÚÀûÓÃJSP´¦Àí±íµ¥´«ÊäÊý¾Ýʱ²Å¿ÉÓã¬ÔÚÎҵĶ«Î÷ÖÐÎÞ·¨½â¾ö£¬ºóÀ´·¢ÏÖ»¹ÊÇÓÃFilterChainºÃ£¬ºÇºÇ£¬Öص㻹ÊÇÔÚrequest.setCharacterEncoding("")ÖУ»Ï£Íû¶Ô´ó¼ÒÓеã°ïÖú
ת×Ô£¨http://www.itwis.com/html/java/jsp/20080814/2158.html£©
µ±jspºÍservlet³öÏÖÂÒÂëÎÊÌâºóµÄ½â¾ö·½°¸
À´Ô´£º ·¢²¼Ê±¼ä£º2008-08-14 ·¢²¼ÈË£º ä¯ÀÀ£º162 ÈË´Î ×ÖÌ壺 [´ó ÖРС]
ÔÚ½øÐÐjspºÍservletµÄ¿ª·¢Ê±£¬ºÜÓпÉÄÜÓöµ½³öÏÖÁËÖÐÎÄÂÒÂëÎÊÌ⣬ÏÖÔÚÎÒÃÇÀ´¿´¿´±ÊÕßÊÇÈçºÎ½â¾öµÄ£¬ËûÒ²ÊÇÓÃÁËÐí¶à·½·¨£¬·¢ÏÖ»¹Êǽâ¾ö²»ÁË¡£×îºóÓÃÁ˹ýÂËÆ÷£¬²ÅËãÖսᡣ
´Ë·½·¨×ܽáÈçÏ£ºÔÚjspÒ³ÃæÖÐʹÓÃ<%@ page pageEncoding="GB2312"%> £¬ÕâÀïµÄpageEncodingÊÇGB2312,ÄÇôÎÒÃÇÔÚ¹ýÂËÆ÷web.xmlÖÐËùʹÓõÄ<param-value>GB2312</param-value>ҲΪGB2312¡£×ÜÖ®Ò»Ìõ£º¾ÍÊÇÉÏÊöÁ½ÕßÒ»Ö¼´¿É,±ÈÈçͬΪUTF-8
½«¹ýÂËÆ÷µÄjava´úÂëºÍweb.xmlµÄÅäÖÃд
//--------java´úÂ벿·Ö£ºCharsetFilter .java
package com;
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;
public class CharsetFilter implements Filter {
private String charset = "GB2312";
public void destroy() {
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain arg2) throws IOException, ServletException {
request.setCharacterEncoding(charset);
arg2.doFilter(request, response);
}
public void init(FilterConfig arg0) throws ServletException {
charset = arg0.getInitParameter("charset");
System.out.println("×Ö·û¹ýÂËÆ÷¿ªÆô£¬µ±Ç°×´Ì¬£º"+charset);
}
}
//--------web.xml²¿·Ö£¨ÒÔϲ¿·Ö¿ÉÒÔÖ±½Ó¸´ÖÆÕ³Ìùµ½WEB.XMLÏ£©
<filter>
<filter-name>CharsetFilter</filter-name>
<filter-class>com.CharsetFilter</fi
Ïà¹ØÎĵµ£º
ÕâÖ÷ÒªÊÇtomcatµÄÎÊÌ⣬Ëü»áÔÚ´«Ë͵Äʱºò°Ñ×Ö·û¼¯ÖØбàÒ룬µÈ´«¹ýÈ¥µÄjspÒ³Ãæ½ÓÊܵÄʱºò¾Í»á³öÏÖÂÒÂ룬
²»¹ÜÔÚÒ³ÃæÀïÈçºÎÉèÖÃ×Ö·û¼¯¶¼Ã»°ì·¨½â¾ö£¬Õâʱºò±ØÐë±ØÐëÔÚtomcat°²×°Ä¿Â¼Àï½øÐÐÉèÖã¬
C:\Program Files\apache-tomcat-6.0.14\confĿ¼Ï server.xmlÏ <Connector/>±êÇ©Ï ¼ÓÒ»¾ä URIEncoding="GBK" ¾ÍºÃÁ ......
1¡¢ÈçºÎ»ìºÏʹÓÃJspºÍSSI #include?
ÔÚJSPÖпÉÒÔʹÓÃÈçÏ·½Ê½°üº¬´¿HTML£º
µ«ÊÇÈç¹ûdata.incÖаüº¬JSP CODE £¬ÎÒÃÇ¿ÉÒÔʹÓãº
2¡¢ÈçºÎÖ´ÐÐÒ»¸öḬ̈߳²È«µÄJSP?
Ö»ÐèÔö¼ÓÈçÏÂÖ¸Áî
3¡¢JSPÈçºÎ´¦ÀíHTML FORMÖеÄÊý¾Ý?
ͨ¹ýÄÚÖõÄrequest¶ÔÏó¼´¿É£¬ÈçÏ£º
String item = request.getParameter("item");
int howM ......
ÔÚÏîÄ¿ÖУ¬ÎÒÃǾ³£Óöµ½ÐèÒªÔÚjspÒ³ÃæÇл»Öд«µÝÖÐÎÄ×Ö·û¡£ÕâÖ÷ÒªÓÐÁ½ÖÖ·½Ê½¡£
¡¡¡¡URL·½Ê½£¬ÀýÈ磺http://website/test1.jsp?act=add&type=Æ»¹û¶m=%20D%20B
¡¡¡¡FORM·½Ê½£¬ÀýÈ磺
¡¡¡¡<form name=test mehtod="post">
¡¡¡¡<input type=hidden name=text2 value="ÖÐÎÄ">
¡¡¡¡<input type=t ......
ÐÞ¸ÄÁËcss ÑùʽÎļþºó£¬ÖØÐÂä¯ÀÀ¸ÃjspÒ³Ã棬·¢ÏÖÐÂÐ޸ĵÄÑùʽûÓÐÉúЧ¡£×ÜÒÔΪÊÇÏîÄ¿»º´æËùÒýÆðµÄ£¬ÓÚÊÇÇåÀíËùÓÐÏîÄ¿£¬ÖØй¹½¨ÏîÄ¿¡£²»ÐС£Ö´ÐÐserver µÄ publish »¹ÊDz»ÐС£ÓÃwindow µÄËÑË÷¹¦ÄÜ·¢ÏÖ³ýÁË WebContent Ŀ¼Óиà css ÎļþÍ⣬.metadata\.plugins\org.eclipse.wst.server.core\tmp1\webapps\ Ŀ¼ÏÂÒ²´æÔڸà c ......
ÔÚjspÖв»Óö¨Òå¿ÉÒÔÖ±½ÓÓõľÍÊÇjspµÄ9¸öÄÚ½¨¶ÔÏóÁË
1£¬Request 2,Response 3,session 4,out 5,page
6,application 7,pageContext 8,config
9,exception
1¡¢Request¶ÔÏó
¸Ã¶ÔÏó·â×°ÁËÓû§Ìá½»µÄÐÅÏ¢£¬Í¨¹ýµ÷ÓøöÔÏóÏàÓ¦µÄ·½·¨¿ÉÒÔ»ñÈ¡·â×°µÄÐÅÏ¢£¬¼´Ê¹ÓøöÔÏó¿ÉÒÔ
»ñÈ¡Óû§Ìá½»µÄÐÅÏ¢¡£
µ±Request¶ÔÏó»ñÈ¡¿Í» ......