javaBean中传到页面中的汉字为乱码???内有详情!(50分)

  • 主题发起人 主题发起人 kangjiazyx
  • 开始时间 开始时间
K

kangjiazyx

Unregistered / Unconfirmed
GUEST, unregistred user!
package login;
import java.util.*;
public class LogBean{
private String username;
private String password;
private String email;
private String swww;
private String oicq;
private Hashtable errors;
public LogBean(){
username="";
password="";
email="";
swww="";
oicq="";
errors=new Hashtable();
}
public String getUsername(){
return username;
}
public String getpassword(){
return password;
}
public String getEmail(){
return email;
}
public String getswww(){
return swww;
}
public String getoicq(){
return oicq;
}
public void setUsername(String usernameStr){
username=usernameStr;
}
public void setPassword(String passwordStr){
password=passwordStr;
}
public void setEmail(String emailStr){
email=emailStr;
}
public void setswww(String swwwStr){
swww=swwwStr;
}
public void setoicq(String oicqStr){
oicq=oicqStr;
}
public void setErrors(String Key,String msg){
errors.put(Key,msg);
}
public boolean validate(){
boolean allOk=true;


if (username.equals("")||username.indexOf("'")!=-1){
errors.put("username","请输入一个正确的用户名称!");
username="";
allOk=false;
}
if(password.equals("")||password.indexOf("'")!=-1||(password.length()>10||password.length()<6)){
errors.put("password","Please enter avalid password of 6-10 charactors!");
password="";
allOk=false;
}
if (email.equals("")||username.indexOf("'")!=-1||(email.indexOf('@')==-1)||(email.indexOf('.')==-1)){
errors.put("email","Please enter avalid Email address!");
email="";
allOk=false;
}

return allOk;
}
public String getErrorMsg(String s){
String errorMsg=(String)errors.get(s.trim());
return(errorMsg==null)?"":errorMsg;
}
}
在页面中这样调用的:<%=handle.getErrorMsg("username")%>出来的是乱码,我已经用了好多方法都试了都还是不行。
 
在最上面加上<%request.setCharacterEncoding("gb2312");%>
 
不行出来的都成了
?????????????
 
那就再加一句:
<%@ page contentType="text/html;
charset=gb2312" language="java" %>
<%request.setCharacterEncoding("gb2312");%>
这样还不行?
 
接受答案了.
 
不对,我的<%@ include file="head.htm"
%>中的都成???了.
 
在jsp页面要包含静态页面换个include方法,或者把你的head.htm改为.jsp
 
好了,谢了!
 
后退
顶部