a我考网

 找回密码
 立即注册

QQ登录

只需一步,快速开始

扫一扫,访问微社区

查看: 174|回复: 2

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

[复制链接]
发表于 2012-8-4 12:28:23 | 显示全部楼层 |阅读模式
1:jdk开发中系统环境变量设置:
: _8 e( x! j2 H3 T6 ^方法如下: * v2 T. ^6 O% D" R" [
Win2000中:   c0 E( D- l1 r5 N  ]
右键我的电脑--》属性--》高级--》环境环境变量 * _9 d" `$ L# F2 @9 j- Q% N
classpath=.;jdk安装目\lib # B) p' |2 x# H3 w+ E8 O2 |
path=jdk安装目录\bin . c% I7 R* P" _" F  Q7 g# C2 u
注意:一定不可忽略"."。 * q! W  p$ d* v4 {' R5 x8 H
Win98中: 7 n6 f! u# F8 a/ g
修改autocexe.bat 就是修改自动批处理文件。 * J# _7 }  W) u! \3 q0 g2 X* T. x
添加: 3 G8 J, A7 s4 j9 A
set classpath=.;jdk安装目\lib
3 h( S# `" f' A9 bset path=jdk安装目录\bin;%path% : H! S0 m- k. X" y

+ ^( R2 m$ t2 i2:(前提设置好了系统环境变量)
' ]8 S. j4 N& T  O9 x% P6 _% ^2 T不带包的编译,相当简单:
% z2 e( `0 T$ g. l  g! |3 ejavac 类名.java
( L: C/ f  W/ E5 z0 xjava 类名 ' y. Q" I" G7 ?6 N" |
! B. p9 \: F+ ~6 r0 G
关于带包的编译问题:
$ D0 i4 ]9 }. A+ J9 J如果你的类是带包的,应该用如下方法编译:
8 W/ n9 @$ F; @+ [$ @! M  v0 o# kjavac -d 包的父目录 类名.java ' Q7 ?2 r. `8 T8 q2 W
java 包名.类名 ' Q- j5 ]$ K3 z6 E! Z2 n' Q
4 c2 `  d* I. l
3:Tomcat服务器配置:
8 U( l! v9 ^- g* ]8 D. C9 K& t1 v  U1):设置好系统环境变量。
! L1 w: R9 B/ @& y) \9 A  Z/ n: V& ?2):JAVA_HOME=G:\JBuilder6\jdk1.3.1 $ z. v/ Z& k6 ]( A
G:\JBuilder6\jdk1.3.1为jdk安装目录 ( _1 ?- N0 ?4 Q, @1 I
3):TOMCAT_HOME=tomcat安装目录 / k# I$ j+ t7 s7 w
4:修改serlet而不重新启动tomcat
; }% g+ b. C" z' h8 W" o$ n! ^& A修改 3 @5 Z; w5 h$ O0 f% c1 w
%TOMCAT_HOME%\conf\server.xml 6 U) d, A) F/ k2 g4 i3 M. K
大致如下:
& l, D: ]- d6 c! ^   e' L+ V1 P# F; q5 r, ?3 R
其中reloadable就是配置是否自动reload的,把它设为true,如果没有这一项,加上。
: {2 G9 k3 ?# R' W7 X$ H: `' w* Q" X5:修改webshpere中的servlet而不重新启动服务: 1 M2 _, S" V; Y% v: g
修改..\WEB-INF下面的web.xml:
! S  J; \* U( [' G0 z加入其中reloadInterval="3" reloadingEnabled="true" fileServingEnabled="true" directoryBrowsingEnabled="true" serveServletsByClassnameEnabled="true"是主要的,reloadInterval="3" reloadingEnabled="true" 是说修改后3秒自动重新载
+ C8 ~9 p# K8 x! h" ^# \入。 9 {- P6 N0 l) J% a7 `
6:配置jbuilder6+webshpere4.0AE,其实jb7可以参照:
3 S( K3 Q7 {$ l. J" t/ f; e首先安装j2ee,然后把j2ee加入到jb的libraries里面。方法如下
9 O. g/ T/ ]; K+ K6 L1:)tools--->configure libraries-->new--->name:里面填写j2ee,Location:里面默认的旧可以了。---->add-->选在j2ee安装路径,选中lib文件夹--ok--oK. - ]5 t' G; {, ]* C1 O9 \9 f
  2:)返回到configure libraries也面后,选中Required Libraries-->add--》选中你刚才创建的j2ee,点ok就可以了。 6 O" f+ F4 ~- `/ |. L) D- w
然后配置webshpere应用服务器和database pilot:
3 ]7 ]4 A, `  X6 m( p+ j" X5 L第一步:tools-->enterprise setup-->Application servers设置安装路径以及IBM的JAVA路径,DB2你自己看着办
0 P+ w! L, H7 |. e# D; J- @+ T第二步:project-->Defaults project properties里servers选择Ws4.0,应该可以用了 / S6 M; i0 W" O5 s! ^! A
webshpere4.0不支持ejb2.0,webshpere5.0支持。
* @3 `8 Y# C* I配置database pilot
& C9 |2 f' b( r第一步:添加类库tools-->config libraries添加你的数据库驱动程序类 - t0 x% f5 J( d) U8 q( Q
第二步:tools-->enterprise setup-->Database Drivers里面添加你刚添加的那个类库 * J3 V' z' _. f4 b, y; _, m* ?
第三步:重启JBilder后,tools-->database pilot-->option-->drivers,添加驱动程序
/ }& z' R, u4 l3 F0 n8 E- A0 l1 F0 C第四步:在database pilot点新建就可以了,driver:COM.ibm.db2.jdbc.app.DB2Driver。url:jdbc:db2:db_sdbc.(db_sdbc为服务器上的db2数据库).
* T. \+ a% F$ R  a. i2 I
+ W1 ]: p" {' m# k: {. t, g7 U/ y% J* N0 d/ u0 W1 i: `
7:解决java中文问题: ' f/ W+ E, [/ w# }5 j
针对applet和awt: & D$ B9 h2 _: y% }
1:) ! x0 h# e4 m* f: s4 p$ O
Font f = new Font(UIResource.getString( "Default_font"),Font.PLAIN,12);
8 J' ], C1 F  y7 _* T: h& V, y4 iUIManager.put("Label.font",f);
! e& h, B0 j! {* Q: Q5 `: h/ ]UIManager.put("Label.foreground",Color.black);
# A  f/ F0 W! M, i3 ~4 ]UIManager.put("Button.font",f);
$ f* L4 d) P2 Q0 d! sUIManager.put("Menu.font",f); 1 R6 Z: b: g  O0 I% C+ t, E8 l% s
UIManager.put("MenuItem.font",f); - h' x5 R; K, A
UIManager.put("List.font",f);
( L4 A' k1 u! m+ E/ |1 x' ^: ]UIManager.put("CheckBox.font",f);
+ T  F; f3 a% l1 [! a  zUIManager.put("RadioButton.font",f); / L5 t% g% A, t  z0 ~4 J3 J
UIManager.put("ComboBox.font",f); : |9 [3 u+ Z/ e2 f  O4 c
UIManager.put("TextArea.font",f);
回复

使用道具 举报

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

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

2:)
; l4 A: V8 e& ~Font f = new Font("隶书",Font.PLAIN,15); $ ~2 l) H# H& j+ Y! O" k# m0 l
UIManager.put("Button.font",font); 8 F" B) i6 ~/ }$ U" Q3 M; D$ i
UIManager.put("ToggleButton.font",font);
/ B- f3 V1 a( K/ L  ~8 V) ]/ VUIManager.put("RadioButton.font",font); & _) E" E& \2 d  {5 }0 y
UIManager.put("CheckBox.font",font);
! d7 h! {) {6 K. u2 g4 X( WUIManager.put("ColorChooser.font",font); - z- ~  u; p! i$ a$ @9 k
UIManager.put("ToggleButton.font",font); ( b9 x, y( r) k3 R  T' o+ \3 M
UIManager.put("ComboBox.font",font);
3 I( w2 o9 h- c% Q/ C6 dUIManager.put("ComboBoxItem.font",font);
- h  v9 d# V2 Y! L8 i7 ?9 VUIManager.put("InternalFrame.titleFont",font);
5 P  [7 H/ s. y" u* ]- z& A, t3 fUIManager.put("Label.font",font); 8 U: L( g( D# V7 E0 C
UIManager.put("List.font",font);
' `$ [, I6 h+ ]/ C! u- jUIManager.put("MenuBar.font",font);
* g7 `4 L6 m: d( H: H; x5 HUIManager.put("Menu.font",font); ( z) o5 S) `- @4 t
UIManager.put("MenuItem.font",font);
% e: ^7 a7 A! \" b8 Y# G9 S4 ~UIManager.put("RadioButtonMenuItem.font",font);
. A- N+ m2 g. p  |6 f. wUIManager.put("CheckBoxMenuItem.font",font); 7 k4 _" h, m' |4 j- y1 w# X$ L) t& v( Y
UIManager.put("PopupMenu.font",font); / o( Z; B4 j! Z7 n9 t" D' q: c! T, \, B
UIManager.put("OptionPane.font",font);
9 s. c0 I( K4 p* J* P0 AUIManager.put("Panel.font",font);
0 A$ L* g1 Z, |6 OUIManager.put("ProgressBar.font",font); % E8 H/ \; u8 b8 G, u
UIManager.put("ScrollPane.font",font);
; |9 o2 c& J# V* uUIManager.put("Viewport",font);
% Y/ _# B# c' v8 P- EUIManager.put("TabbedPane.font",font);
7 l+ a6 R  D' P5 V1 G* `6 s3 ]' tUIManager.put("TableHeader.font",font); 0 Q. T9 Z8 q' g$ D
UIManager.put("TextField.font",font);
  B! s. T; M; C* {; ~8 R* NUIManager.put("PasswordFiled.font",font); ! X) g4 J" @$ W4 E6 o
UIManager.put("TextArea.font",font); : u5 _0 l. l( x! K3 P
UIManager.put("TextPane.font",font); 1 J! U1 I" x9 R/ {* u# Z
UIManager.put("EditorPane.font",font);
' Y5 s5 D; }) g- `( t3 ?UIManager.put("TitledBorder.font",font); 4 a% k' |4 P1 l8 {) a2 n3 S/ M
UIManager.put("ToolBar.font",font); ( b1 E* q) h! Q  c0 R% c# }
UIManager.put("ToolTip.font",font);
- o, P: L$ w0 e; O* w  V' }UIManager.put("Tree.font",font); 5 a4 d- X* J7 c' U. W9 r
8 D0 @7 j; t& ~$ |! [; }6 C  G" ?
  3:)针对jsp和servlet: 7 ~( W1 ~& O1 j$ ~
解决办法:
. N9 ?) f) K* h第一: , v' r+ K* [( z8 L7 N
在jsp页面加入:
+ u; v6 x& d8 `0 t, o9 W $ Y. H- \0 F' s3 Q# t, r  B
或者在servlet里面
- @2 h7 F0 ?! }# P5 B: Zpublic void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { 1 f4 q  q4 `* T# g0 V
response.setContentType("text/html; charset=gb2312");//这是重要的
  N! O+ N3 B( c1 v4 {上面的如果在不行就用如下的方法在数据入库前进行调用:
3 Z2 g7 @# m: h2 }9 y! R/ d: ypublic static String UnicodeToChinese(String s){
6 `  u- R/ v' P- I" {: k% ctry{
' b% M) B! j1 R0 B3 o! L* Lif(s==null||s.equals("")) return "";
% p/ B" l3 e2 Y  VString newstring=null; 3 n1 r  g; J, z, @# T! x/ n( J
newstring=new String(s.getBytes("ISO8859_1"),"gb2312");
: L& J, z" _9 [" treturn newstring; 9 D4 f# t8 d9 P: H
}
0 m8 J( c8 X  F. _7 f5 O2 ~catch(UnsupportedEncodingException e) . q! X- w/ T$ e: M% O6 x
{ 0 Q+ j# g* J- v- A# O: G" _; {, c
return s; , C. T! a& A; t; d0 \
}
' g/ e1 P8 m( F: G8 O} 8 U, N: I6 Q# C* N

0 |4 ~8 G- d) |) P. B; V, upublic static String ChineseToUnicode(String s){
1 F3 z3 A4 h; d, {3 u; I7 N2 ptry{
1 @; Q+ \  D/ x" Q8 {3 ]if(s==null||s.equals("")) return "";   g3 }, m4 z& h! c5 E! m( B* U
String newstring=null; ; ?* O0 [" Z% x' Q  a/ T
newstring=new String(s.getBytes("gb2312"),"ISO8859_1"); ( u# C8 h2 \$ B5 ^( }4 V
return newstring; 6 A$ e* I! R- J. @
} - S4 K) Z9 J+ k
catch(UnsupportedEncodingException e) 1 B4 I* Z! Z' ?+ c. x
{
) _6 j8 e6 Y8 S4 f+ T% S5 Hreturn s; & C( x5 U' f- D  T2 e
} ( r" [' K( |  L) R# J4 P1 H
}
回复 支持 反对

使用道具 举报

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

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

3:)解决weblogic/webshpere中文问题:
$ P8 _" @% V8 A4 b1 ~: j+ X在web.xml文件中需要配置中文环境。r如下: & w; Z6 y# {! C0 W- N  y, p

4 @1 z, j' h$ tweblogic.httpd.inputCharset./* - T3 s& G6 ~$ o' U
GB2312
. G, u1 {% g# R, I
1 g; u2 s, G* T7 E+ K# t   4:)javamail附件中文乱码: . O, j% W# j5 v( K8 E% k+ E& S
/* 4 C+ u8 z7 H  S  E# D
@从BodyPart中提取使用ISO-8859-1编吗的文件名
7 w+ }6 T' N6 E2 p' w) A@因为BodyPart.getFilename()过程已经对文件名作了一次编码,有时不能直接使用
! R! h1 T8 f! f" d$ s*/ * T, @4 d: X' p! {6 c" c( f' f1 U( p: z
public static String getISOFileName(Part body){
& f) X0 P3 c  b" C, s, M" e//设置一个标志,判断文件名从Content-Disposition中获取还是从Content-Type中获取 % B3 D6 p$ u1 T4 q  `& R
boolean flag=true;
- a& N5 j) y/ t4 |5 n) s9 X, Q9 fif(body==null){ - x9 h% ]% [7 J: L- d
return null; 8 m8 y% R) B0 X
} : J3 Q' @+ k: @$ h7 p
String[] cdis; 3 L! b1 j$ o% o; y, R$ g
try{
6 `# r; H9 ^9 h+ e) Y# Scdis=body.getHeader("Content-Disposition");
9 o) R1 b+ L1 [7 b# Y6 U2 H- S, I}
/ y* r. [  s. S9 R' Lcatch(Exception e){
) S6 r9 d4 f) r) c1 |: W+ `% O6 Kreturn null; ; F) P0 _) }4 q& A2 w0 _! @
}
+ s7 J1 L5 X0 q; j7 y9 u' Oif(cdis==null){ & c/ V, q7 C; Q
flag=false;
8 }- I0 I' V  X9 x. f& ]. j}
. o3 t7 H  E/ I! i3 o9 `6 ^if(!flag){
0 h( S# z7 {+ ]6 f9 u; o( p' ]try{ ( O# ?) B" q! V; e; F
cdis=body.getHeader("Content-Type");   C  A* l( [) l( n3 R! R2 C
} ( _" i! P. E1 Z; z0 @8 R2 v0 w3 s
catch(Exception e){ + t* H" q5 k# ~. Y+ ?$ j2 ~
return null;
5 S9 W; A; r$ ?} $ f/ B, b" t3 K2 [* T7 q' r# J7 `3 `
}
. @. Q9 k  K/ y8 R$ wif(cdis==null){
2 u3 G0 f( c$ U! O8 ]return null; " f& o9 R7 i9 c! s
} & M: P! I/ y/ s3 a( u7 M8 M) N2 X6 o
if(cdis[0]==null){ 3 E" `: d( {( C* V  M2 ~
return null; 2 Z+ b* l$ R4 `' d  ^# x1 Y$ Y
} % X2 f" r, S9 K# l; E3 {% b) T
//从Content-Disposition中获取文件名 + x, y7 O1 s+ T$ d* ?% U
if(flag){
2 X$ n" k% E# M5 O; s' C7 o0 c7 gint pos=cdis[0].indexOf("filename="); ; {) }8 t  |0 K
if(pos
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-9-27 21:24 , Processed in 1.381051 second(s), 26 queries .

Powered by Discuz! X3.4 Licensed

© 2001-2017 Comsenz Inc.

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