- 論壇徽章:
- 0
|
java初學(xué)者應(yīng)讀--轉(zhuǎn)載CSDN之 wjmmml (笑著悲傷)
7:解決java中文問題:
針對applet和awt:
1:)
Font f = new Font(UIResource.getString( "Default_font" ,Font.PLAIN,12);
UIManager.put("Label.font",f);
UIManager.put("Label.foreground",Color.black);
UIManager.put("Button.font",f);
UIManager.put("Menu.font",f);
UIManager.put("MenuItem.font",f);
UIManager.put("List.font",f);
UIManager.put("CheckBox.font",f);
UIManager.put("RadioButton.font",f);
UIManager.put("ComboBox.font",f);
UIManager.put("TextArea.font",f);
2:)
Font f = new Font("隸書",Font.PLAIN,15);
UIManager.put("Button.font",font);
UIManager.put("ToggleButton.font",font);
UIManager.put("RadioButton.font",font);
UIManager.put("CheckBox.font",font);
UIManager.put("ColorChooser.font",font);
UIManager.put("ToggleButton.font",font);
UIManager.put("ComboBox.font",font);
UIManager.put("ComboBoxItem.font",font);
UIManager.put("InternalFrame.titleFont",font);
UIManager.put("Label.font",font);
UIManager.put("List.font",font);
UIManager.put("MenuBar.font",font);
UIManager.put("Menu.font",font);
UIManager.put("MenuItem.font",font);
UIManager.put("RadioButtonMenuItem.font",font);
UIManager.put("CheckBoxMenuItem.font",font);
UIManager.put(" opupMenu.font",font);
UIManager.put("OptionPane.font",font);
UIManager.put(" anel.font",font);
UIManager.put(" rogressBar.font",font);
UIManager.put("ScrollPane.font",font);
UIManager.put("Viewport",font);
UIManager.put("TabbedPane.font",font);
UIManager.put("TableHeader.font",font);
UIManager.put("TextField.font",font);
UIManager.put(" asswordFiled.font",font);
UIManager.put("TextArea.font",font);
UIManager.put("TextPane.font",font);
UIManager.put("EditorPane.font",font);
UIManager.put("TitledBorder.font",font);
UIManager.put("ToolBar.font",font);
UIManager.put("ToolTip.font",font);
UIManager.put("Tree.font",font);
。常海┽槍sp和servlet:
解決辦法:
第一:
在jsp頁面加入:
<%@ page contentType="text/html; charset=gb2312" %>;
或者在servlet里面
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html; charset=gb2312" ;//這是重要的
上面的如果在不行就用如下的方法在數(shù)據(jù)入庫前進行調(diào)用:
public static String UnicodeToChinese(String s){
try{
if(s==null||s.equals("" ) return "";
String newstring=null;
newstring=new String(s.getBytes("ISO8859_1" ,"gb2312" ;
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
public static String ChineseToUnicode(String s){
try{
if(s==null||s.equals("" ) return "";
String newstring=null;
newstring=new String(s.getBytes("gb2312" ,"ISO8859_1" ;
return newstring;
}
catch(UnsupportedEncodingException e)
{
return s;
}
}
3 解決weblogic/webshpere中文問題:
在web.xml文件中需要配置中文環(huán)境。r如下:
<context-param>;
<param-name>;weblogic.httpd.inputCharset./*</param-name>;
<param-value>;GB2312</param-value>;
</context-param>;
4:)javamail附件中文亂碼:
/*
@從BodyPart中提取使用ISO-8859-1編嗎的文件名
@因為BodyPart.getFilename()過程已經(jīng)對文件名作了一次編碼,有時不能直接使用
*/
public static String getISOFileName(Part body){
//設(shè)置一個標志,判斷文件名從Content-Disposition中獲取還是從Content-Type中獲取
boolean flag=true;
if(body==null){
return null;
}
String[] cdis;
try{
cdis=body.getHeader("Content-Disposition" ;
}
catch(Exception e){
return null;
}
if(cdis==null){
flag=false;
}
if(!flag){
try{
cdis=body.getHeader("Content-Type" ;
}
catch(Exception e){
return null;
}
}
if(cdis==null){
return null;
}
if(cdis[0]==null){
return null;
}
//從Content-Disposition中獲取文件名
if(flag){
int pos=cdis[0].indexOf("filename=");
if(pos<0){
return null;
}
//如果文件名帶引號
if(cdis[0].charAt(cdis[0].length()-1)=='"'){
return cdis[0].substring(pos+10,cdis[0].length()-1);
}
return cdis[0].substring(pos+9,cdis[0].length());
}
else{
int pos=cdis[0].indexOf("name=");
if(pos<0){
return null;
}
//如果文件名帶引號
if(cdis[0].charAt(cdis[0].length()-1)=='"'){
return cdis[0].substring(pos+6,cdis[0].length()-1);
}
return cdis[0].substring(pos+5,cdis[0].length());
}
}
8:字符串分割:
public int getCount(String str,String sign){//查找某一字符串中str,特定子串s的出現(xiàn)次數(shù)
if(str==null) return 0;
StringTokenizer s=new StringTokenizer(str,sign);
return s.countTokens();
}
public String[] getArray(String str,String sign){//按特定子串s為標記,將子串截成數(shù)組。
int count=getCount(str,sign);
int j=0;
String[] arr=new String[count];
for(int i=0;i<count;i++){
if(str.indexOf(sign)!=-1){
j =str.indexOf(sign);
arr=str.substring(0,j);
str =str.substring(j+1);
}else{
arr=str;
}
}
return arr;
}
9:jdk1.3沒有字符串替換函數(shù),(jdk1.4有)。
解決1.3中的個這個問題如下:
public String stringReplace(String sourceString, String toReplaceString, String replaceString)
{
String returnString = sourceString;
int stringLength = 0;
if(toReplaceString != null)
{
stringLength = toReplaceString.length();
}
if(returnString != null && returnString.length() >; stringLength)
{
int max = 0;
String S4 = "";
for(int i = 0; i < sourceString.length(); i++)
{
max = i + toReplaceString.length() >; sourceString.length()? sourceString.length():i + stringLength;
String S3 = sourceString.substring(i, max);
if(!S3.equals(toReplaceString))
{
S4 += S3.substring(0,1);
}else{
S4 += replaceString;
i += stringLength -1 ;
}
}
returnString = S4;
}
return returnString;
}
9:設(shè)置weblogic連接池:
pool的配置:
假設(shè)已配置服務(wù):expserv
且數(shù)據(jù)庫服務(wù)器機器名為:expserv
數(shù)據(jù)庫sid:expservSID,用戶名和密碼都為:expserv
以weblogic7.0為例,首先啟動服務(wù)
http://localhost:port/console
打開service\jdbc\connection pools
配置oraclePool如下:
Configuration:
Name: oraclePool
URL: jdbc racle:thin expserv:1521:expservSID
Driver Classname: oracle.jdbc.driver.OracleDriver
Properties(key=value): user=expserv
Targets:
Targets-Server:expserv
在weblogic7.0中除了數(shù)據(jù)庫密碼,其他的pool參數(shù)都可以在config.xml中直接用文本編輯器直接修改。 |
|