JSPÒ³Ãæ´«ÖµÖÐÎÄÂÒÂëµÄ¼òµ¥½â¾ö·½·¨
Ô´´úÂ룬a.jspÍùb.jsp´«Öµ£º
a.jspÒ³ÃæÄÚÈÝ
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<form action="b.jsp">
¡¡¡¡name:<input type=text name=name>
¡¡¡¡<input type=submit>
</form>
b.jspÒ³ÃæÄÚÈÝ£º
<%@ page language="java" import="java.util.*" pageEncoding="GB2312"%>
<%
String name=request.getParameter("name");
%>
<body>
¡¡¡¡<%=name%>
</body>
ÏÖÏó£ºÖÐÎÄÂÒÂë,±ÈÈç“£¿£¿£¿£¿£¿£¿”
¡¡¡¡½â¾ö·½·¨ÈçÏ£º
¡¡¡¡·½·¨Ò»£º
¡¡¡¡1. ÔÚb.jspÖаÑpageEncoding="GB2312"¸ÄΪpageEncoding="ISO8859-1"
¡¡¡¡ËäÈ»ÕâÑùb.jspÒ³ÃæÏÔʾµÄÄÚÈÝ»¹ÊÇÂÒÂ룬µ«ÊDz»ÊÇÄÇÖÖ“£¿£¿£¿£¿£¿£¿”µÄÂÒÂ룬¶øÊÇһЩÌØÊâ×Ö·û
¡¡¡¡2. È»ºóÔÚä¯ÀÀÆ÷Öв鿴²Ëµ¥ÖÐÐ޸ijÉGB2312µÄ±àÂ룬ÕâʱÂÒÂë¾ÍÏÔʾÖÐÎÄÁË¡£
¡¡¡¡3. µ«ÊÇÕâÖÖ·½·¨ÊDz»¿ÉÐеġ£
¡¡¡¡·½·¨¶þ£º
¡¡¡¡1. ÔÚb.jspÖаÑString name=request.getParameter("name");ÐÞ¸ÄΪ
¡¡¡¡String name=new String(request.getParameter("name").getBytes("ISO-8859-1"),"GB2312");
¡¡¡¡2. ÕâʱÔÙÔÚÒ³ÃæÉÏÏÔʾ£¬Ôò¾ÍÊÇÖÐÎÄÁË¡£
¡¡¡¡·½·¨Èý£º
¡¡¡¡1. ÓÐÈË˵ÐÞ¸Äget/postµÄ´«Öµ·½Ê½,µ«ÊÇÕâÊÇÓÐÇ°ÌáµÄ,Èç¹ûÖ»ÊÇ°Ñget·½Ê½Ð޸ijÉpost·½Ê½,Ò³Ãæ½á¹û»¹ÊÇÂÒÂë!
¡¡¡¡2. Ç°ÌáÄã±ØÐëÅäÖÃÁ˹ýÂËÆ÷,Èô¹ûÄãÖ»ÊÇÅäÖÃÁ˹ýÂËÆ÷,Ôò´«Öµ·½Ê½±ØÐëÊÇ:post·½Ê½²Å²»ÊÇÂÒÂë,Èç¹ûÊÇget·½Ê½ÕÕÑùÊÇÂÒÂë!
¡¡¡¡3. ¹ýÂËÆ÷µÄÅäÖÃ,ÎÒÏë´ó¼Ò¶¼ÄÜÓÐ,ÎҾͲ»ËµÁË
¡¡¡¡·½·¨ËÄ:
¡¡¡¡1. ÓÐÈË˵ÅäÖÃtomcatµÄÅäÖÃÎļþserver.xmlÀïÕâ¾ä£º
<Connector URIEncoding="GB2312"
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ port="8080" maxHttpHeaderSize="8192"
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ maxThreads="150" minSpareThreads="25" maxSpareThreads="75"
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ enableLookups="false" redirectPort="8443" acceptCount="100"
¡¡¡¡¡¡¡¡¡¡¡¡¡¡ connectionTimeout="20000" disableUploadTimeout="true" />
¼ÓÉÏÕâ¾ä£ºURIEncoding="GB2312"
¡¡¡¡2. ËäÈ»¿ÉÒÔµ«ÊÇÓÐÇ°ÌáµÄ,Èô¹ûÄã¹ýÂËÆ÷ûÓÐÅäÖÃ,ÔòÖ»ÊÇÅäÖÃÁËserver.xmlÎļþ,ÕâÑùÖ»ÓÐÔÚ±íµ¥ÊÇget´«ÖµÊ±ºò²Å¿ÉÒÔ!µ±ÊÇpost·½Ê½Ê±,ÕÕÑùÊÇÂÒÂë!
¡¡¡¡*ÕâʱÎÒÃǾͿÉÒÔ¿´³öÔÚtomcat5ÖеÄpostÓëget´«Öµ·½Ê½ÊDz»Ò»ÑùµÄ*
¡¡¡¡*ÓÐÈËÒªÎÊÓÐûÓÐÒ»ÖÖ·½·¨Èô«ÖµÊ¹ÓÃget·½Ê½»òpost·½Ê½¶¼ºÃÓÃÄØ,ÏÂÃæ¾ÍÊÇ
Ïà¹ØÎĵµ£º
Ò».ʲôÊÇcookies£¿
¡¡¡¡´ó¼Ò¶¼ÖªµÀ£¬ä¯ÀÀÆ÷ÓëWEB·þÎñÆ÷Ö®¼äÊÇʹÓÃHTTPÐÒé½øÐÐͨÐŵģ¬µ±Ä³¸öÓû§·¢³öÒ³ÃæÇëÇóʱ£¬WEB·þÎñÆ÷Ö»ÊǼòµ¥µÄ½øÐÐÏìÓ¦£¬È»ºó¾Í¹Ø±ÕÓë¸ÃÓû§µÄÁ¬½Ó¡£Òò´Ëµ±Ò»¸öÇëÇó·¢Ë͵½WEB·þÎñÆ÷ʱ£¬ÎÞÂÛÆäÊÇ·ñÊǵÚÒ»´ÎÀ´·Ã£¬·þÎñÆ÷¶¼»á°ÑËüµ±×÷µÚÒ»´ÎÀ´¶Ô´ý£¬ÕâÑùµÄ²»ºÃÖ®´¦¿ÉÏë¶øÖª¡£ÎªÁËÃÖ²¹Õâ¸öȱÏÝ£¬Netsc ......
ÔÚµ±Ç°Ó¦ÓÃϵͳµÄ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>
< ......
1. jspÒ³ÃæÏÔʾÖÐÎÄÂÒÂ룺
jspÒ³ÃæµÄ±àÂ뷽ʽÓÐÁ½¸öµØ·½ÐèÒªÉèÖãº
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ page contentType="text/html;charset=utf-8"%>
ÆäÖУºpageEncoding Ö¸µÄÊÇjspÎļþ±¾É ......
ÔÚactionÀïʹÓÃfileuploadʱ£¬´ÓreqeustµÃµ½µÄÖÐÎÄÊý¾ÝΪÂÒÂ룬³¢ÊÔʹÓÃÁË
Java´úÂë
1. DiskFileItemFactory factory = new DiskFileItemFactory();
ServletFileUpload upload = new ServletFileUpload(factory);
upload.setHeaderEnco ......