我的頁面跳轉輸出還是亂碼,已經在使用格式轉換了,也沒有報錯,有誰知道是哪里有問題嗎
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String piccode = (String)request.getSession().getAttribute("piccode");
//獲取用戶輸入的驗證碼
String checkcode = request.getParameter("checkcode");
//設置輸出流,從而獲得輸出
PrintWriter out = response.getWriter();
checkcode = checkcode.toUpperCase();
response.setContentType("text/html;charset=utf8");
if(checkcode.equals(piccode)){
out.println("驗證碼輸入成功!!");
}else{
out.println("驗證碼輸入有誤,請重試?。。。?!");
}
out.flush();
out.close();
}
}
2018-01-01
我也遇到跟你一樣的問題了。對了你上面的編碼少了一個缸,utf-8 有解決辦法請告訴我一下,我現在去百度
2017-02-16
一般使用response.setContentType()方法來設置HTTP 響應的編碼,同時指定了瀏覽器顯示的編碼;
因為他在執行該方法通知服務器端以指定編碼進行編碼后,會自動調用response.setCharacterEncoding()方法來通知瀏覽器以指定編碼來解碼;使用此方法要在response.getWriter()執行之前或response提交之前;
不會的多百度
你這個PW寫在編碼前面了,調調位置,我也是亂碼,已經解決
2017-01-19
把tomcat重啟就好了。
2016-12-12
先把Tomcat關掉然后在LoginServlet中將老師的response.setContentType("text/html;charset=gbk");換成response.setCharacterEncoding("GBK");
再重啟Tomcat刷新訪問頁面,我這樣做的成功了
2016-11-26
一樣的錯誤,我也是怎么改都是????????
2016-11-26
response.setContentType("text/html;charset=utf8");
這一句寫在輸出流的前面
2016-11-23
你上面寫的是response.setContentType("text/html;charset=utf8"),加一個-試試,如果不行,那我也不知道了
2016-11-23
如果你index頁面中是utf-8的話,這里也應該是utf-8,如果是GBK,這里就是GBK