jspÖÐÎÄÂÒÂëÎÊÌâ½â¾ö·½·¨
1.µ÷ÓÃJSPÒ³ÃæÏÔʾÂÒÂë
ͨ¹ýä¯ÀÀÆ÷µ÷ÓÃJSPÒ³Ã棬ÔÚ¿Í»§¶Ëä¯ÀÀÆ÷ÖÐËùÓеÄÖÐÎÄÄÚÈݳöÏÖÂÒÂë¡£
solution£º
Ê×ÏÈÈ·Èϱ¾JSPÔÚ±à¼Æ÷Öб£´æʱ£¬Ê¹ÓõÄÊÇGBKµÄ±àÂë¸ñʽ£¬È»ºóÔÚJSPÒ³ÃæµÄ¿ªÊ¼²¿·ÖÌí¼Ó <%@ pageEncoding="GBK" %>¾Í¿ÉÒÔ½â¾öÖÐÎÄÂÒÂëÎÊÌâ¡£
2.µ÷ÓÃServletÒ³ÃæÏÔʾÂÒÂë
ͨ¹ýä¯ÀÀÆ÷µ÷ÓÃServlet£¬ServletÔÚä¯ÀÀÆ÷ÖÐÏÔʾÄÚÈݳöÏÖÂÒÂë
solution£º
ÔÚServletʹÓÃresponseÔÚÊä³öÄÚÈÝ֮ǰ£¬ÏÈÖ´ÐÐresponse.setContentType("text/html;charset=GBK")É趨Êä³öÄÚÈݵıàÂëΪGBK
3.Post±íµ¥´«µÝ²ÎÊýÂÒÂë
ͨ¹ýJSPÒ³Ãæ¡¢HTMLÒ³Ãæ»òÕßServletÖÐµÄ±íµ¥ÔªËØÌá½»²ÎÊý¸ø¶ÔÓ¦µÄJSPÒ³Ãæ»òÕßServelt¶øJSPÒ³Ãæ»òÕßServlet½ÓÊÕµÄÖÐÎIJÎÊýÖµÂÒÂë¡£
solution£º
ÔÚ½ÓÊÕPOSTÌá½»µÄ²ÎÊý֮ǰ£¬Ê¹ÓÃrequest.setCharacterEncoding("GBK")É趨½ÓÊÕ²ÎÊýµÄÄÚÈÝʹÓÃGBK±àÂë
¸üºÃµÄ½â¾ö·½·¨ÊÇʹÓùýÂËÆ÷¼¼Êõ
Encoding¹ýÂËÆ÷
package com.htt;
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 Encoding implements Filter {
public void destroy() { }
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
request.setCharacterEncoding("GBK");
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig) throws ServletException { }
}
Web.xmlÎļþÖеÄÉèÖÃ
<filter>
<filter-name>encoding</filter-name>
<filter-class>com.htt.Encoding</filter-class>
</filter>
<filter-mapping>
<filter-name>encoding</filter-name>
<url-pattern>/ToCh_zn</url-pattern>
</filter-mapping>
4.Get·½Ê½±íµ¥´«µÝºÍURI·½Ê
Ïà¹ØÎĵµ£º
Ò»¡¢JSPÒ³ÃæÏÔʾÂÒÂë
ÏÂÃæµÄÏÔʾҳÃæ(display.jsp)¾Í³öÏÖÂÒÂ룺
<html>
<head>
<title>JSPµÄÖÐÎÄ´¦Àí</title>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
</head>
<body>
<%
out.print("JSPµÄÖÐÎÄ´¦Àí");
%>
< ......
1.»ù±¾¸ÅÄîµÄÀí½â
¾ø¶Ô·¾¶£º¾ø¶Ô·¾¶¾ÍÊÇÄãµÄÖ÷Ò³ÉϵÄÎļþ»òĿ¼ÔÚÓ²ÅÌÉÏÕæÕýµÄ·¾¶£¬(URLºÍÎïÀí·¾¶)ÀýÈ磺
C:xyz est.txt ´ú±íÁËtest.txtÎļþµÄ¾ø¶Ô·¾¶¡£http://www.sun.com/index.htmÒ²´ú±íÁËÒ»¸öURL¾ø¶Ô·¾¶¡£
Ïà¶Ô·¾¶£ºÏà¶ÔÓëij¸ö»ù׼Ŀ¼µÄ·¾¶¡£°üº¬WebµÄÏà¶Ô·¾¶£¨HTMLÖеÄÏà¶ÔĿ¼£©£¬ÀýÈ磺ÔÚ
Ser ......
JSPºÍServletÖеľø¶Ô·¾¶ºÍÏà¶Ô·¾¶ÎÊÌâÀ§ÈÅÁËÎҺü¸Ì죬¾¹ýŬÁ¦Ö®ºó½«Æ䲿·ÖÐĵúʹó¼Ò¹²Ïí¡£
Ç°Ì᣺¼ÙÉèÄãµÄHttpµØַΪhttp://192.168.0.1/ÄãµÄwebÓ¦ÓÃΪwebapp£¬ÄÇôÄãµÄwebÓ¦ÓÃURLΪhttp://192.168.0.1/webapp/
webÓ¦ÓõÄĿ¼½á¹¹£º
webapp/
web-inf/
......
½ñÌìÖØÐÂÕûÀíµçÄÔ£¬ÕÒµ½Ò»¸öÎļþ£¬¿´ÁËÏÂÈÕÆÚ£¨2006.10.21£© £¬Å²»Ð¡ÐÄÔÙ¶ªÁË£¬´æµ½ÍøÉÏÀ´É¹É¹¡£
0»ò1¸öpackage É趨ÀàËùÔÚ°ü
0»ò¶à¸öimport µ¼Èë±ØÒªÀà
script ÊÖ¸å, ÊÖ¼£, ¾ç±¾, ¿¼ÉúµÄ±ÊÊÔ¾í, Ô±¾
alert v.Ìá·ÀµÄ, ¾¯ÌèµÄ n.¾¯Ìè, ......
²»ÒªÔÚJSPÖд¦ÀíÓû§ÇëÇó£¨request£©£¬Ò²²»ÒªÔÚJSPÖÐǶÈë¿ØÖÆÁ÷´úÂë
²»Òª½«Óû§½çÃ沿·ÖºÍÒµÎñÂß¼²¿·Ö»ìºÏ
ÔÚJSPÖо¡Á¿²»Òª°üº¬java´úÂ룬ELÔÚÕâ·½Ãæ¿ÉÒÔ¸øÎÒÃǺܴó°ïÖú
½«Ò³Ãæ·ÖΪ¼¸¸ö²¿·Ö£ºHeader£¬Menu£¬Main¡£¡£¡£
......