jspÖÐÎÄÂÒÂëÎÊÌâ
Ò»¡¢JSPÒ³ÃæÏÔʾÂÒÂë
ÏÂÃæµÄÏÔʾҳÃæ(display.JSP)¾Í³öÏÖÂÒÂ룺
¶Ô²»Í¬µÄWEB·þÎñÆ÷ºÍ²»Í¬µÄJDK°æ±¾£¬´¦Àí½á¹û¾Í²»Ò»Ñù¡£ÔÒò£º·þÎñÆ÷ʹÓõıàÂ뷽ʽ²»Í¬ºÍä¯ÀÀÆ÷¶Ô²»Í¬µÄ×Ö·ûÏÔʾ½á¹û²»Í¬¶øµ¼Öµġ£½â¾ö°ì·¨£ºÔÚJSPÒ³ÃæÖÐÖ¸¶¨±àÂ뷽ʽ(gb2312),¼´ÔÚÒ³ÃæµÄµÚÒ»ÐмÓÉÏ£º£¬¾Í¿ÉÒÔÏû³ýÂÒÂëÁË¡£ÍêÕûÒ³ÃæÈçÏ£º
¶þ¡¢±íµ¥Ìá½»ÖÐÎÄʱ³öÏÖÂÒÂë
ÏÂÃæÊÇÒ»¸öÌá½»Ò³Ãæ(submit.JSP)£¬´úÂëÈçÏ£º
ÏÂÃæÊÇ´¦ÀíÒ³Ãæ(process.JSP)´úÂ룺
Èç¹ûsubmit.JSPÌá½»Ó¢ÎÄ×Ö·ûÄÜÕýÈ·ÏÔʾ£¬Èç¹ûÌá½»ÖÐÎÄʱ¾Í»á³öÏÖÂÒÂë¡£ÔÒò£ºä¯ÀÀÆ÷ĬÈÏʹÓÃUTF-8±àÂ뷽ʽÀ´·¢ËÍÇëÇ󣬶øUTF-8ºÍGB2312±àÂ뷽ʽ±íʾ×Ö·ûʱ²»Ò»Ñù£¬ÕâÑù¾Í³öÏÖÁ˲»ÄÜʶ±ð×Ö·û¡£½â¾ö°ì·¨:ͨ¹ýrequest.seCharacterEncoding("gb2312")¶ÔÇëÇó½øÐÐͳһ±àÂ룬¾ÍʵÏÖÁËÖÐÎĵÄÕý³£ÏÔʾ¡£Ð޸ĺóµÄprocess.JSP´úÂëÈçÏ£º
Èý¡¢Êý¾Ý¿âÁ¬½Ó³öÏÖÂÒÂë
Ö»ÒªÉæ¼°ÖÐÎĵĵط½È«²¿ÊÇÂÒÂ룬½â¾ö°ì·¨£ºÔÚÊý¾Ý¿âµÄÊý¾Ý¿âURLÖмÓÉÏuseUnicode=true&characterEncoding=GBK¾ÍOKÁË¡£
ËÄ¡¢Êý¾Ý¿âµÄÏÔʾÂÒÂë
ÔÚmysql4.1.0ÖÐ,varcharÀàÐÍ£¬textÀàÐ;ͻá³öÏÖÖÐÎÄÂÒÂ룬¶ÔÓÚvarcharÀàÐÍ°ÑËüÉèΪbinaryÊôÐԾͿÉÒÔ½â¾öÖÐÎÄÎÊÌ⣬¶ÔÓÚtextÀàÐ;ÍÒªÓÃÒ»¸ö±àÂëת»»ÀàÀ´´¦Àí£¬ÊµÏÖÈçÏ£º
public class Convert {
/** °ÑISO-8859-1Âëת»»³ÉGB2312
*/
public static String ISOtoGB(String iso){
String gb;
try{
if(iso.equals("") || iso == null){
return "";
}
else{
iso = iso.trim();
gb = new String(iso.getBytes("ISO-8859-1"),"GB2312");
return gb;
}
}
catch(Exception e){
System.err.print("±àÂëת»»´íÎó£º"+e.getMessage());
return "";
}
}
}
°ÑËü±àÒë³Éclass£¬¾Í¿ÉÒÔµ÷ÓÃConvertÀàµÄ¾²Ì¬·½·¨ISOtoGB()À´×
Ïà¹ØÎĵµ£º
ÔÚµ±Ç°Ó¦ÓÃϵͳµÄweb.xmlÀï¼ÓÈëjsp-config´úÂ룺
<web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
<jsp-config>
< ......
½ñÌì²âÊÔÈËÔ±¸øÎÒÌáÁËÒ»¸öbug£¬ËµÎÒ¿ª·¢µÄÄ£¿é±¨¿ò¼ÜµÄjs´íÎ󣬵±Ê±Ò»Ìý¾ÍãÂÁË£¬ÎÒ±¾µØ²âÊÔÍêȫûÎÊÌ⣬ÔõôÉÏÁË·þÎñÆ÷»á³öÏÖÕâ¸öÎÊÌâÄØ£¿
ÓÚÊÇÎÒÈ¥·þÎñÆ÷ÉϲâÁËÒ»ÏÂ×Ô¼ºÐ´µÄÄǸöÄ£¿é£¬½á¹û±¨µÄ´íÎ󻹺ͲâÊÔÈËÔ±Ìá¸øÎҵĴíÎó²»Ò»Ö£¬ÔÓ»ØÊ£¿ÓÚÊÇÎÒÓÖÕÒµ½Ò»ÃûͬÊ£¬ÈÃËû°ïÎÒ²âһϣ ......
ʵÑ鱨¸æ
Ò». »ù±¾Ë¼Â·¼°ÊµÑé½á¹û£¨¼Ç¼¸÷ÖÖÔËÐÐÇé¿ö»òÒ³ÃæµÄÔËÐÐЧ¹û£©£»
1¡¢Ê¹ÓÃTOMCAT·þÎñÆ÷ÅäÖÃjspÓ¦ÓÃ
1£©´ò¿ªTOMCAT/webapps×ÓĿ¼£¬´´½¨Ò»webÓ¦Óã¨Èçmyweb£©£¬½«example0.jspÓëexample1.jspÎļþ¸´ÖÆÈëÄÚ£¬²¢ÔÚ¸ÃĿ¼ÏÂÉèÖÃWEB-INFĿ¼¼°web.xmlÅäÖÃÎļþ£»
2£©ÔÚä¯ÀÀÆ÷µØÖ·À¸ÊäÈëhttp://localhost:8080/myweb/ex ......
Ò»¡¢ÊµÑéÄ¿µÄ
1¡¢ ÕÆÎÕ±íµ¥µÄʹÓ÷½·¨£¬ÒÔ¼°·þÎñÆ÷¶Ë´¦Àí±íµ¥ÇëÇóµÄ·½·¨£»
2¡¢ Àí½âForwardµÄ×÷Óã»
3¡¢ ÊìÁ·ÔËÓÃJSPµÄµäÐÍÄÚÖöÔÏó
¶þ¡¢ÊµÑéÄÚÈݼ°²½Öè
1¡¢±íµ¥µÄʹÓü°ÆäµÝ½»¡¢´¦Àí¹ý³Ì
ÔÚÔ´´½ÌÎñϵͳÖУ¬ÏµÍ³»á¸ù¾ÝÓû§ÀàÐÍ(½Ìʦ/ѧÉú)ÏÔʾ²»Í¬µÄÒ³Ã档ΪģÄâ¸Ã¹¦ÄÜ£¬ÐèÒª¶¨ÒåÉè¼ÆÈçÏÂҳà ......
½ñÌìÔÚµ÷ÊÔ´úÂëʱ£¬·¢ÏÖÒ»¶ÎдÔÚjsp¶ËµÄjava´úÂëÔõô±àÒ룬ÉèÖöϵ㶼²»»áÔڶϵ㴦ͣÁô¡£°Ù˼²»µÃÆä½â£¬ÔÚͬʵİïÖúÏ£¬·¢ÏÖÊÇ´úÂë×¢ÊÍÓÐÎÊÌâ¡£
Ô´úÂ룺
<!-- <jsp:forward page="/hello/Welcome.do"/> - ......