a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 147|回复: 2

[其他] java新手必看:经验总结(1)

[复制链接]
发表于 2012-8-4 12:28:23 | 显示全部楼层 |阅读模式
1:jdk开发中系统环境变量设置: , b' A; V4 R* z
方法如下:
6 G4 _9 D  Y- P* ^; ZWin2000中:
# f( z2 j' S/ C; K7 K6 N: S7 t右键我的电脑--》属性--》高级--》环境环境变量 3 T+ X, {9 d; e0 }
classpath=.;jdk安装目\lib 1 s5 Y5 C7 ]: ?; u* c3 _7 M
path=jdk安装目录\bin
$ z' I; @  b" d8 W2 o0 i3 J注意:一定不可忽略"."。 5 ^% \$ c: m1 A
Win98中:
3 N% u0 k3 R6 `修改autocexe.bat 就是修改自动批处理文件。
' z; b- {5 ~& @( z添加: 0 b# q2 A. I, r+ v! B7 T6 n. v! r. I
set classpath=.;jdk安装目\lib & X% h6 P9 Y: C+ n/ ~* b
set path=jdk安装目录\bin;%path%
0 L  T" B4 D/ g; Q0 W( {6 \+ ]2 z$ _( g7 [$ r
2:(前提设置好了系统环境变量)
$ l! p6 J+ c' g3 o; A+ R' a不带包的编译,相当简单: 5 Z7 A2 \: n# z  b& `6 D1 S
javac 类名.java ' v- f% _1 e( G' v
java 类名
* ~5 X& |6 U0 p9 T6 r
1 J% u% A! J1 `9 c" T, w' g关于带包的编译问题: - n! }6 K; I4 ^# w& Z& h
如果你的类是带包的,应该用如下方法编译:
; Z* x: q' @9 R0 Djavac -d 包的父目录 类名.java
) S. m4 q6 t) S0 W7 Ejava 包名.类名
; S4 V1 L0 q' @5 x: e" q+ x
; P6 P: G) u" n4 ]6 A3:Tomcat服务器配置:
9 \. m# B( E  p0 W- Q6 H1):设置好系统环境变量。
# t/ |" e" Y; }% y6 Z2):JAVA_HOME=G:\JBuilder6\jdk1.3.1
6 T, x, e1 `1 c! P# ~( JG:\JBuilder6\jdk1.3.1为jdk安装目录
8 J8 y. D& n+ F4 U( Z2 |3):TOMCAT_HOME=tomcat安装目录 ) f0 z* m! V+ L4 s
4:修改serlet而不重新启动tomcat
( X) q: l# r* I0 [' B* z: T5 j修改 $ ^3 Q  p( a* ]# J( |1 B9 ]
%TOMCAT_HOME%\conf\server.xml
$ i+ J+ Z  V3 ?7 S- B- e6 m2 I大致如下: 0 F5 R2 a4 B) H0 `& e9 \+ [

$ e, |" U! a+ U, H4 a其中reloadable就是配置是否自动reload的,把它设为true,如果没有这一项,加上。 - S3 m2 Q( v- {" C; k8 ~
5:修改webshpere中的servlet而不重新启动服务: : s0 O# H) e8 j( d! {  k5 b. i, A4 i
修改..\WEB-INF下面的web.xml:
6 I$ }6 r# P7 k0 t% Y# I) n+ P加入其中reloadInterval="3" reloadingEnabled="true" fileServingEnabled="true" directoryBrowsingEnabled="true" serveServletsByClassnameEnabled="true"是主要的,reloadInterval="3" reloadingEnabled="true" 是说修改后3秒自动重新载 8 Q" v( ]# @% \
入。 * Q9 Y# w% w# O1 A
6:配置jbuilder6+webshpere4.0AE,其实jb7可以参照: . i, @/ v' f$ p
首先安装j2ee,然后把j2ee加入到jb的libraries里面。方法如下 ( `3 `1 p/ {' M& t' p; |, M
1:)tools--->configure libraries-->new--->name:里面填写j2ee,Location:里面默认的旧可以了。---->add-->选在j2ee安装路径,选中lib文件夹--ok--oK.
3 c$ a/ u; Z- u/ r& f- g2 g  2:)返回到configure libraries也面后,选中Required Libraries-->add--》选中你刚才创建的j2ee,点ok就可以了。
5 E/ H1 |" Q6 T% c3 o/ Z6 o1 q然后配置webshpere应用服务器和database pilot:
! c2 u: G8 M2 ]9 a8 }2 m! h9 X1 T4 ~第一步:tools-->enterprise setup-->Application servers设置安装路径以及IBM的JAVA路径,DB2你自己看着办
( T7 W2 t+ [5 t; E第二步:project-->Defaults project properties里servers选择Ws4.0,应该可以用了
8 L5 f. O$ [: P* ?  A! P0 Owebshpere4.0不支持ejb2.0,webshpere5.0支持。
: z9 H: _3 D4 j' U% _2 r) Y配置database pilot . h# I9 e6 @0 S1 L8 N# P
第一步:添加类库tools-->config libraries添加你的数据库驱动程序类
/ {( y7 l: [8 u0 `2 D) a) j第二步:tools-->enterprise setup-->Database Drivers里面添加你刚添加的那个类库 ' s3 ~; m8 ]/ |7 ^7 x
第三步:重启JBilder后,tools-->database pilot-->option-->drivers,添加驱动程序 / p8 I3 z4 L1 M# S' u
第四步:在database pilot点新建就可以了,driver:COM.ibm.db2.jdbc.app.DB2Driver。url:jdbc:db2:db_sdbc.(db_sdbc为服务器上的db2数据库).
1 a9 u9 @1 d. }( J
, e$ E/ c3 Y0 d4 r+ P- h: r+ ]# I
! r' x0 r: @3 u7 [" ?! C7:解决java中文问题: 9 E: B" U0 X1 Q$ x. s1 Q
针对applet和awt:
, r% t1 q. P* c* [1:)
1 N; W$ A# p1 X/ ~Font f = new Font(UIResource.getString( "Default_font"),Font.PLAIN,12);
: H3 j- K; V" N: J+ t; S# HUIManager.put("Label.font",f); : g0 r+ b$ h3 `, b4 `! W/ V" c
UIManager.put("Label.foreground",Color.black); - u' j5 c" i" \: i$ b' D
UIManager.put("Button.font",f); 6 R4 n+ |1 J' j/ H. L6 T4 a
UIManager.put("Menu.font",f); 2 U& M: {% g5 k" G" I
UIManager.put("MenuItem.font",f); . S* H. o% T1 x
UIManager.put("List.font",f);
+ ~# v! a5 r) r" u# BUIManager.put("CheckBox.font",f); 8 V6 p4 O* z! T1 L9 ]( D$ D. M
UIManager.put("RadioButton.font",f); $ q& o% M9 m. _+ X/ \  Q/ g
UIManager.put("ComboBox.font",f); / W' x# a6 ^$ u5 z8 g/ y
UIManager.put("TextArea.font",f);
回复

使用道具 举报

 楼主| 发表于 2012-8-4 12:28:24 | 显示全部楼层

java新手必看:经验总结(1)

2:)
9 G! Y  ^7 L4 a6 z; yFont f = new Font("隶书",Font.PLAIN,15);
2 S# @. c1 Q- P$ ^; F) `# X* n2 [UIManager.put("Button.font",font);
- j2 ^$ e/ y7 k; z) DUIManager.put("ToggleButton.font",font); 5 t0 i! y# c. }  |: o0 i
UIManager.put("RadioButton.font",font);
5 S; _- G3 V. G- WUIManager.put("CheckBox.font",font); & O' o, H5 F8 p
UIManager.put("ColorChooser.font",font); 2 c. U. X# ^9 @" g* q
UIManager.put("ToggleButton.font",font);
' p7 P9 v& a/ X. Q9 X; iUIManager.put("ComboBox.font",font);
3 z* W% |; T9 }$ I/ x/ XUIManager.put("ComboBoxItem.font",font); 4 G1 e9 O% S2 {% Y1 u
UIManager.put("InternalFrame.titleFont",font);
9 y* W+ z7 d! q, Y5 `' a3 e; KUIManager.put("Label.font",font);
  Z  d% H# `2 f0 T) n4 YUIManager.put("List.font",font);
' U# O8 h' m) OUIManager.put("MenuBar.font",font); 7 g7 v6 E5 E# A9 V- \
UIManager.put("Menu.font",font);
6 g: D# Y. q' [- _UIManager.put("MenuItem.font",font); % y- c+ N2 W; L% g7 o7 [! k
UIManager.put("RadioButtonMenuItem.font",font); 6 Q5 H" P! N% C5 h( ]' }
UIManager.put("CheckBoxMenuItem.font",font); ! e2 ]# y* |, Q- L* h/ k- X
UIManager.put("PopupMenu.font",font); % b! y1 m7 g$ o! m* h
UIManager.put("OptionPane.font",font);
7 Q8 [2 }, o# W8 L; s% X& m1 hUIManager.put("Panel.font",font); ! x0 {* K0 r) M8 K/ g" ~
UIManager.put("ProgressBar.font",font); . c/ B3 S2 s5 Y3 f" v/ H
UIManager.put("ScrollPane.font",font); - y  [. M' T! W2 f
UIManager.put("Viewport",font);
/ U- n$ I+ F8 p% j/ _. n5 X3 R" AUIManager.put("TabbedPane.font",font);
: z" C$ M7 ~, B) M& ?UIManager.put("TableHeader.font",font); ) N% x) `0 n. u  }) [$ }# t* H' a3 y! a
UIManager.put("TextField.font",font); , a, ~& w6 d( U' `" p6 c/ j# |0 ?
UIManager.put("PasswordFiled.font",font); / h  v6 ?( B( j* i; {
UIManager.put("TextArea.font",font);
) \" ^+ U- \1 }$ oUIManager.put("TextPane.font",font); 4 I( ?/ l. @% i( s" o
UIManager.put("EditorPane.font",font);
' A7 Y, g5 c3 fUIManager.put("TitledBorder.font",font); 9 L  j+ N1 V2 }5 d1 J, \
UIManager.put("ToolBar.font",font); " g" ?( L; h0 E7 i3 m0 S
UIManager.put("ToolTip.font",font); % ?2 c- K& `# Z2 Z  D0 r6 {1 Y( S
UIManager.put("Tree.font",font); ) k& X9 H5 {: `) a: n# U# G
! j% s5 J& @1 {  D7 i; z
  3:)针对jsp和servlet:
; \; V* ^; R& P解决办法:
! x( d. ~$ c6 p, S/ u6 R第一: - `3 c: c6 B& C+ L2 {8 Y
在jsp页面加入: 3 l0 _9 b+ }5 Z& h) [! l+ s- `
  F! s' C9 V4 b, ^7 |
或者在servlet里面 2 w% b- _9 b: t8 p- |- M& c
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { + L% m* X: I: ?  f+ m
response.setContentType("text/html; charset=gb2312");//这是重要的 ' M% c8 L% ^3 R" k
上面的如果在不行就用如下的方法在数据入库前进行调用: # `! j1 Z4 G) e& Q3 x
public static String UnicodeToChinese(String s){ 3 Q7 @' R9 T3 t+ C
try{
& d& E( }# e, W& q3 c1 `% jif(s==null||s.equals("")) return ""; 3 Y+ @& \! g2 Y% D: E3 v
String newstring=null; 3 u3 Q! ?  G+ I" m+ \+ w
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
3 \" K" a' O6 w1 q! t, t4 R. a6 m, H% Ureturn newstring;
. F( M8 L% J/ S7 y1 y}
6 h* c, A$ {0 L& T0 ^catch(UnsupportedEncodingException e) 7 v3 O# R" B$ u$ u
{ 1 T) M$ H9 d$ T8 k
return s; # e' Y+ Q) Y; T' v4 ]8 X$ _
} % L; E# S- P; ]3 e
}
+ {5 A8 ~6 ?( w9 v# u: y! Z. U1 A2 Q2 x- t" B2 u+ ~# D& k! E
public static String ChineseToUnicode(String s){
. i/ R( n: r, o( F+ a5 Qtry{
. K7 _8 I) d' A6 B8 mif(s==null||s.equals("")) return ""; ( \: {7 }6 @' c9 o
String newstring=null;
5 u1 n5 S# `! Z' Enewstring=new String(s.getBytes("gb2312"),"ISO8859_1");
- {5 H( ?1 e( w$ Ereturn newstring; - P) s3 P" L: g5 ^3 t' O
}
. m/ }  w8 U' [9 C. I: X+ lcatch(UnsupportedEncodingException e)
# y# o1 p8 O# Y: M# |8 y{
. Z- k# r4 J4 ~, O& [. wreturn s; ! {, d* D: a% m; _& k! m4 s3 B. L
}   E4 ^/ Q6 i( c0 P
}
回复 支持 反对

使用道具 举报

 楼主| 发表于 2012-8-4 12:28:25 | 显示全部楼层

java新手必看:经验总结(1)

3:)解决weblogic/webshpere中文问题:
/ m9 _6 {. {  @在web.xml文件中需要配置中文环境。r如下:
. Z8 b% A$ o! {% Q
- k6 H: i& w9 p# w4 N- Y6 |: bweblogic.httpd.inputCharset./* $ {- T: h' p( ]* I+ X4 Z
GB2312 4 T0 Q! m' M( A
; H0 a3 m3 t6 a+ D+ [' R" W
   4:)javamail附件中文乱码: : n3 s* \! ^5 X3 F
/*
, q1 G2 ?1 m6 T4 }" o. ]# L  L) g@从BodyPart中提取使用ISO-8859-1编吗的文件名
/ W! x( k% c1 N# b& K7 w7 [@因为BodyPart.getFilename()过程已经对文件名作了一次编码,有时不能直接使用 2 t+ _* x6 V9 O% C7 Y9 ?, V
*/ , K4 J3 B) p3 A) u' Y
public static String getISOFileName(Part body){ 6 m; e9 M! a2 N* u3 U2 Q
//设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取
& q4 f+ P( @( Bboolean flag=true; ; y( V$ U0 v% U
if(body==null){ & g. Z* v/ |# r( B
return null;
) @% q$ W& E" H% M' v% I( W} # X3 ^9 l  n' ]7 Q: N& Q
String[] cdis; 9 r4 D4 u/ b) ], f
try{   u- \1 Y' v/ V8 W* p( z7 y
cdis=body.getHeader("Content-Disposition"); . }! d- |9 O/ \( \9 N) l1 N" D
} 8 }8 m9 K1 I) y% @1 }# f1 [
catch(Exception e){ ; b, Y1 w- V. O; t
return null;
( W* @$ }+ Y2 j# {}
; ?4 J& R3 D9 ]; R  Hif(cdis==null){
3 ?9 @  n3 ?& r6 `! x2 j- Q4 S2 @flag=false; " W9 h, ]. N3 Q. X- f3 h5 G) ~
}
- B2 m# i. h- k# |if(!flag){
1 A9 K) W% B- c$ @( }0 utry{ ' v8 b/ f, A' W% M
cdis=body.getHeader("Content-Type");
' S* k% k. U3 I! v$ p6 p4 x  A} 8 m  P% m2 Y+ k- X
catch(Exception e){
' X5 s: R5 r8 U* A& ?* x% Ireturn null;
  P9 m& k9 i. ?& S3 ~1 W} * V/ `* _' L6 t' L% \& C& ]
} 2 s4 {6 p7 W; |- P1 g; ~* W; G3 ?
if(cdis==null){ . c) S5 J0 a& k" Q0 G
return null;
. k$ f- W3 L4 B7 F/ s} / g% x1 `  n% a, s- s/ k
if(cdis[0]==null){ 1 N3 _) k. Q0 I, l7 r5 Y/ R
return null;
3 r6 o+ c; U, F4 x/ [, a; O}
& j, l8 t% Q. w//从Content-Disposition中获取文件名
: Q9 K5 w, v7 M/ oif(flag){ 2 r# S+ T! A) s8 x/ M$ E* Z
int pos=cdis[0].indexOf("filename=");
9 d% ^4 f7 s4 J( J4 @6 g" Fif(pos
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|Woexam.Com ( 湘ICP备18023104号 )

GMT+8, 2024-5-5 22:41 , Processed in 0.201898 second(s), 25 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

快速回复 返回顶部 返回列表