jsp涓枃涔辩爜闂

时间:2023-02-06 13:08:51
琛ㄥ崟鏂囦欢

<%@ page contentType="text/html; charset=gb2312" language="java"  %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>甯愬彿瀵嗙爜</title>
</head>

<body>
<form action="../addDo" method="post">
    濮撳悕<input type="text" name="name"  /><br />
    瀵嗙爜<input type="text" name="password" />
    <input type="submit" value="纭畾" />
    
</form>
</body>
</html>
 




澶勭悊鏂囦欢
package mypack;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


public class addDo extends HttpServlet
{
    public void doPost(HttpServletRequest request,HttpServletResponse response) throws ServletException,IOException
    {
        PrintWriter out = response.getWriter();
       
        //response.setCharacterEncoding("gb2312");鎶婅繖閲岀殑娉ㄩ噴鍘绘帀涔熶笉琛?br>         
        out.println("濮撳悕:"+request.getParameter("name"));
        out.println("瀵嗙爜:"+request.getParameter("password"));
    }
}



杈撳叆锛?
寮犱笁
123456

杈撳嚭锛?
??:寮犱笁 ??:123456 


涔熷氨鏄锛屼紶閫掔殑鍙傛暟娌℃湁涔辩爜锛屼絾鏄痑ddDo鏈韩鎵撳嵃鐨勪腑鏂囦贡鐮佷簡銆?
鍙﹀ 鎶奱ddDo鐨勬敞閲婂幓鎺変篃涓嶈銆?

杩欐槸鎬庝箞鍥炰簨鍛紵
搴旇鍜嬪姙锛?
璋㈣阿!

17 涓В鍐虫柟妗?/h2>

#1


鏁版嵁搴撲粈涔堢紪鐮侊紵
淇濇寔涓€鐩寸殑鍦版柟锛?
jsp椤甸潰
request response鏃?nbsp;寤鸿鐢╢ilter
缂栬緫鍣ㄧ紪鐮?
db缂栫爜

#2


鍔犱笂
response.setContentType("text/html; charset=GBK");

#3


<%@ page pageEncoding="gb2312"%>鍔犱笂

#4


^_^

#5


addDo.java杩欎釜鏂囦欢鑷韩涓嶆槸GBK缂栫爜鐨勩€?

濡傛灉浣犱娇鐢‥clipse ,鐪嬬湅杩欎釜鏂囩珷  http://www.java2000.net/viewthread.jsp?tid=580

#6


鍥?妤?nbsp;娌℃湁浣跨敤鏁版嵁搴?
鍥?妤?nbsp;鍔犱簡涔熶笉琛?nbsp;璇曡繃銆?

#7


琛ュ厖涓?nbsp;鍦ㄧ綉椤垫簮鐮佹煡鐪嬪埌鐨勫悓涓婇潰鐨勪竴鏍枫€?
灏辨槸浼犻€掔殑涓枃鍙傛暟娌℃湁涔辩爜 浣嗘槸addDo鏈韩鎵撳嵃鐨勫叏閮ㄦ槸涔辩爜锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒

#8


 response.setCharacterEncoding("gb2312");//鏀惧湪鍓嶉潰
request.setCharacterEncoding("gb2312");//涔熷姞涓?nbsp;灏卞彲浠ヤ簡
        PrintWriter out = response.getWriter();
       
       
        
        out.println("濮撳悕:"+request.getParameter("name"));
        out.println("瀵嗙爜:"+request.getParameter("password"));

#9


 response.setCharacterEncoding("gb2312");//鍝嶅簲鏁版嵁涓枃澶勭悊
request.setCharacterEncoding("gb2312");//璇锋眰鏁版嵁涓枃澶勭悊

#10


 response.setCharacterEncoding("gb2312");
request.setCharacterEncoding("gb2312");

  杩欎簩鍙ユ斁JSP涓湅鐪?

#11


瀹屽叏鍚屾剰妤间笂鐨勭湅娉?

#12




1.浼犲弬鏁颁箣鍓嶇敤鏂囨湰妗嗙敤trim()鏂规硶

2.request.getParameter("name")鏀规垚
 new String(request.getparameter("name").getBytes("ISO-8859-1"),"GB2312")

3.鍔犲叆涓嬩袱鍙ワ紝閮借鍔犱笂
request.setCharacterEncoding("gb2312");       
response.setContentType("text/html;charset=gb2312"); 

1 or 2 or 3鐪嬬湅

#13


浣犵敤鐨刴ysql鏁版嵁搴?

#14


涓嶈鐢╣b2312锛岀敤gbk

#15



<%@ page contentType="text/html; charset=gb2312" language="java"  %>
鎶奵harset杩欓噷鏀规垚utf-8璇曚笅锛?

#16


寮曠敤 8 妤?nbsp;yzsunlight 鐨勫洖澶?
response.setCharacterEncoding("gb2312");//鏀惧湪鍓嶉潰
request.setCharacterEncoding("gb2312");//涔熷姞涓?nbsp;灏卞彲浠ヤ簡
PrintWriter out = response.getWriter();



out.println("濮撳悕:"+request.getParameter("name"));
out.println("瀵嗙爜:"+request.getParameter("password"));

姝ゆ硶鍙互瑙e喅锛?
浣嗘渶濂戒笉瑕佺敤gbk锛寀tf8姣旇緝濂?

#17


鎶奼b2312鏀规垚utf-8灏卞ソ浜?

#1


鏁版嵁搴撲粈涔堢紪鐮侊紵
淇濇寔涓€鐩寸殑鍦版柟锛?
jsp椤甸潰
request response鏃?nbsp;寤鸿鐢╢ilter
缂栬緫鍣ㄧ紪鐮?
db缂栫爜

#2


鍔犱笂
response.setContentType("text/html; charset=GBK");

#3


<%@ page pageEncoding="gb2312"%>鍔犱笂

#4


^_^

#5


addDo.java杩欎釜鏂囦欢鑷韩涓嶆槸GBK缂栫爜鐨勩€?

濡傛灉浣犱娇鐢‥clipse ,鐪嬬湅杩欎釜鏂囩珷  http://www.java2000.net/viewthread.jsp?tid=580

#6


鍥?妤?nbsp;娌℃湁浣跨敤鏁版嵁搴?
鍥?妤?nbsp;鍔犱簡涔熶笉琛?nbsp;璇曡繃銆?

#7


琛ュ厖涓?nbsp;鍦ㄧ綉椤垫簮鐮佹煡鐪嬪埌鐨勫悓涓婇潰鐨勪竴鏍枫€?
灏辨槸浼犻€掔殑涓枃鍙傛暟娌℃湁涔辩爜 浣嗘槸addDo鏈韩鎵撳嵃鐨勫叏閮ㄦ槸涔辩爜锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒锛侊紒

#8


 response.setCharacterEncoding("gb2312");//鏀惧湪鍓嶉潰
request.setCharacterEncoding("gb2312");//涔熷姞涓?nbsp;灏卞彲浠ヤ簡
        PrintWriter out = response.getWriter();
       
       
        
        out.println("濮撳悕:"+request.getParameter("name"));
        out.println("瀵嗙爜:"+request.getParameter("password"));

#9


 response.setCharacterEncoding("gb2312");//鍝嶅簲鏁版嵁涓枃澶勭悊
request.setCharacterEncoding("gb2312");//璇锋眰鏁版嵁涓枃澶勭悊

#10


 response.setCharacterEncoding("gb2312");
request.setCharacterEncoding("gb2312");

  杩欎簩鍙ユ斁JSP涓湅鐪?

#11


瀹屽叏鍚屾剰妤间笂鐨勭湅娉?

#12




1.浼犲弬鏁颁箣鍓嶇敤鏂囨湰妗嗙敤trim()鏂规硶

2.request.getParameter("name")鏀规垚
 new String(request.getparameter("name").getBytes("ISO-8859-1"),"GB2312")

3.鍔犲叆涓嬩袱鍙ワ紝閮借鍔犱笂
request.setCharacterEncoding("gb2312");       
response.setContentType("text/html;charset=gb2312"); 

1 or 2 or 3鐪嬬湅

#13


浣犵敤鐨刴ysql鏁版嵁搴?

#14


涓嶈鐢╣b2312锛岀敤gbk

#15



<%@ page contentType="text/html; charset=gb2312" language="java"  %>
鎶奵harset杩欓噷鏀规垚utf-8璇曚笅锛?

#16


寮曠敤 8 妤?nbsp;yzsunlight 鐨勫洖澶?
response.setCharacterEncoding("gb2312");//鏀惧湪鍓嶉潰
request.setCharacterEncoding("gb2312");//涔熷姞涓?nbsp;灏卞彲浠ヤ簡
PrintWriter out = response.getWriter();



out.println("濮撳悕:"+request.getParameter("name"));
out.println("瀵嗙爜:"+request.getParameter("password"));

姝ゆ硶鍙互瑙e喅锛?
浣嗘渶濂戒笉瑕佺敤gbk锛寀tf8姣旇緝濂?

#17


鎶奼b2312鏀规垚utf-8灏卞ソ浜?