no
no
BlogJava
首页
新随笔
联系
聚合
管理
6 Posts :: 2 Stories :: 0 Comments :: 0 Trackbacks
常用链接
我的随笔
我的评论
我的参与
留言簿
(1)
给我留言
查看公开留言
查看私人留言
随笔档案
2008年6月 (6)
文章档案
2008年6月 (2)
搜索
最新评论
阅读排行榜
1. TSysUserDAO(221)
2. struts(220)
3. applicationContext(204)
4. hbm(165)
5. TSysUserService(164)
评论排行榜
1. struts(0)
2. TSysUserDAO(0)
3. hbm(0)
4. TSysUser(0)
5. applicationContext(0)
UserAction
1
public
class
UserAction
extends
DispatchAction
{
2
private
ITSysUserService sysUserService;
3
private
ITSysDictService sysDictService;
4
5
public
ITSysUserService getSysUserService()
{
6
return
sysUserService;
7
}
8
public
void
setSysUserService(ITSysUserService sysUserService)
{
9
this
.sysUserService
=
sysUserService;
10
}
11
public
ITSysDictService getSysDictService()
{
12
return
sysDictService;
13
}
14
public
void
setSysDictService(ITSysDictService sysDictService)
{
15
this
.sysDictService
=
sysDictService;
16
}
17
18
private
String msg
=
""
;
19
private
String forward
=
""
;
20
21
/** */
/**
***用户注册*****
*/
22
public
ActionForward regist(ActionMapping mapping,ActionForm form,
23
HttpServletRequest request,HttpServletResponse response)
{
24
RegistForm rf
=
(RegistForm)form;
25
TSysUser user
=
new
TSysUser();
26
FormFile image
=
rf.getImPhoto();
27
try
{
28
InputStream img
=
image.getInputStream();
29
Blob imPhoto
=
Hibernate.createBlob(img);
30
user.setImPhoto(imPhoto);
31
}
32
catch
(Exception e)
{
33
e.printStackTrace();
34
System.out.println(
"
exception happened
"
);
35
}
36
user.setSzGraduationSchool(rf.getSzGraduationSchool());
37
user.setSzOfficeHolder(rf.getSzOfficeHolder());
38
user.setSzIdCardNumber(rf.getSzIdCardNumber());
39
user.setSzJob(rf.getSzJob());
40
user.setSzLifeAddress(rf.getSzLifeAddress());
41
user.setSzMarriageState(rf.getSzMarriageState());
42
user.setSzMobilePhone(rf.getSzRegState());
43
user.setSzSex(rf.getSzSex());
44
user.setSzStation(rf.getSzStation());
45
user.setSzUserRole(rf.getSzUserRole());
46
user.setSzWorkDate(rf.getSzWorkDate());
47
user.setSzBirthday(rf.getSzBirthday());
48
user.setSzEduExperience(rf.getSzEduExperience());
49
user.setSzEmployeeType(rf.getSzEmployeeType());
50
user.setSzEntryBankDate(rf.getSzEntryBankDate());
51
user.setSzFamilyAddress(rf.getSzFamilyAddress());
52
user.setSzFamilyTel(rf.getSzFamilyTel());
53
user.setSzOrgan(rf.getSzOrgan());
54
user.setSzUserId(rf.getSzUserId());
55
user.setSzUserName(rf.getSzUserName());
56
user.setSzPassword(rf.getSzPassword());
57
user.setSzRegState(
"
0
"
);
58
System.out.println(
"
checkeda!
"
);
59
//
注册成功
60
if
(sysUserService.addUser(user)
==
true
)
{
61
request.setAttribute(
"
user
"
, user);
62
System.out.println(
"
insert ok!
"
);
63
return
mapping.findForward(
"
success
"
);
64
}
65
else
{
66
ActionMessages error
=
new
ActionMessages();
67
error.add(
"
szUserId
"
,
new
ActionMessage(
"
error.regist.userexists
"
));
68
saveErrors(request,error);
69
String str
=
mapping.getInput();
//
得到输入ActionForward
70
System.out.println(
"
user alreday exists!
"
);
71
return
mapping.findForward(str);
72
}
73
}
74
75
/** */
/**
***用户登录*****
*/
76
public
ActionForward login(ActionMapping mapping, ActionForm form,
77
HttpServletRequest request, HttpServletResponse response)
{
78
HttpSession session
=
request.getSession();
79
80
String id
=
request.getParameter(
"
szUserId
"
);
81
82
//
??????
83
System.out.print(id);
84
System.out.println(
"
-----------------
"
+
id
+
"
---------------------
"
);
85
String password
=
request.getParameter(
"
szPassword
"
);
86
if
(id
==
null
||
""
.equals(id))
{
87
88
return
mapping.findForward(
"
index1
"
);
89
}
else
{
90
91
TSysUser user
=
sysUserService.getById(id);
92
if
(user
==
null
)
{
93
return
mapping.findForward(
"
nouser
"
);
94
}
else
{
95
96
//
?????漰?????????е???????????д????
97
if
(user.getSzPassword().equals(password))
98
{
99
String userid
=
user.getSzUserId();
100
//
String org=user.getSzOrgan();
101
//
String role=user.getSzUserRole();
102
//
String sta=user.getSzStation();
103
//
session.setAttribute("id",userid);
104
//
session.setAttribute("org",org);
105
//
session.setAttribute("role",role);
106
//
session.setAttribute("state",sta);
107
//
108
String org
=
sysUserService.getOnProperty(user,
"
szOrgan
"
);
109
String role
=
sysUserService.getUserRole(user,
"
szUserRole
"
);
110
String sta
=
sysUserService.getOnProperty(user,
"
szStation
"
);
111
String regState
=
sysUserService.getRgeState(user,
"
szRegState
"
);
112
//
String marriageState=irs.getOnProperty(user,"szMarriageState");
113
//
String jobb=irs.getOnProperty(user,"szJob");
114
//
String empType=irs.getOnProperty(user,"szEmployeeType");
115
//
String offHolder=irs.getOnProperty(user,"szOfficeHolder");
116
//
String eduExp=irs.getOnProperty(user,"szEduExperience");
117
118
119
session.setAttribute(
"
password
"
, password);
120
session.setAttribute(
"
id
"
,userid);
121
session.setAttribute(
"
org
"
,org);
122
session.setAttribute(
"
role
"
,role);
123
session.setAttribute(
"
state
"
,sta);
124
//
session.setAttribute("jobb",jobb );
125
//
session.setAttribute("marriagestate",marriageState);
126
//
session.setAttribute("employeetype",empType);
127
//
session.setAttribute("officeholder",offHolder);
128
session.setAttribute(
"
regstate
"
,regState);
129
//
session.setAttribute("eduexp", eduExp);
130
//
读取每页记录数
131
ResourceBundle bundle
=
ResourceBundle.getBundle(
"
page
"
);
132
int
pageSize
=
Integer.parseInt(bundle.getString(
"
pageSize
"
));
133
134
request.getSession().setAttribute(
"
pageSize
"
, pageSize);
135
session.setAttribute(
"
user1
"
, user);
136
return
mapping.findForward(
"
success
"
);
137
}
138
}
139
}
140
return
mapping.findForward(
"
info
"
);
141
}
142
143
/** */
/**
***加载注册信息*****
*/
144
public
ActionForward showInfo(ActionMapping mapping, ActionForm form,
145
HttpServletRequest request, HttpServletResponse response)
{
146
RegistForm myform
=
(RegistForm)form;
147
148
//
String id=request.getParameter("szUserId");
149
//
TSysUser user=sysUserService.getById(id);
150
//
request.setAttribute("user",user);
151
myform.setEduExp(getArray(sysDictService.getByEduExp()));
152
myform.setEmployeeType(getArray(sysDictService.getByEmployeeType()));
153
myform.setJob(getArray(sysDictService.getByJob()));
154
myform.setMarriageState(getArray(sysDictService.getByMarriageState()));
155
myform.setOfficeHolder(getArray(sysDictService.getByOfficeHolder()));
156
myform.setOrgan(getArray(sysDictService.getByOrgan()));
157
myform.setStation(getArray(sysDictService.getByStation()));
158
//
HttpSession session=request.getSession();
159
//
session.setAttribute("EduExp", sysUserService.getByEduExp());
160
//
session.setAttribute("EmployeeType", sysUserService.getByEmployeeType());
161
//
session.setAttribute("Job", sysUserService.getByJob());
162
//
session.setAttribute("MarriageState", sysUserService.getByMarriageState());
163
//
session.setAttribute("OfficeHolder", sysUserService.getByOfficeHolder());
164
//
session.setAttribute("Organ", sysUserService.getByOrgan());
165
//
session.setAttribute("Station",sysUserService.getByStation());
166
167
System.out.println(
"
JK
"
);
168
return
mapping.findForward(
"
regist
"
);
169
}
170
171
private
TSysDictDTO[] getArray(List
<
TSysDict
>
list)
{
172
TSysDictDTO[] tsd;
173
tsd
=
new
TSysDictDTO[list.size()];
174
Iterator
<
TSysDict
>
it
=
list.iterator();
175
int
i
=
0
;
176
while
(it.hasNext())
{
177
TSysDict fc
=
(TSysDict)it.next();
178
//
if(fc.getSzClass().equals("???????")) continue;
179
tsd[i]
=
new
TSysDictDTO(fc.getSzDictCode(),fc.getSzDictValue());
180
i
++
;
181
}
182
return
tsd;
183
}
184
185
/** */
/**
***获取用户信息*****
*/
186
public
ActionForward change(ActionMapping mapping, ActionForm form,
187
HttpServletRequest request, HttpServletResponse response)
{
188
JhfForm jhfForm
=
(JhfForm) form;
189
String id
=
request.getParameter(
"
SzUserId
"
);
190
TSysUser user
=
sysUserService.getById(id);
191
//
设置select选项中特定的bean属性
192
jhfForm.setEduExp(getArray(sysDictService.getByEduExp()));
193
jhfForm.setEmployeeType(getArray(sysDictService.getByEmployeeType()));
194
jhfForm.setJob(getArray(sysDictService.getByJob()));
195
jhfForm.setMarriageState(getArray(sysDictService.getByMarriageState()));
196
jhfForm.setOfficeHolder(getArray(sysDictService.getByOfficeHolder()));
197
jhfForm.setOrgan(getArray(sysDictService.getByOrgan()));
198
jhfForm.setStation(getArray(sysDictService.getByStation()));
199
200
//
设定request范围内可用的属性
201
request.setAttribute(
"
user
"
, user);
202
request.setAttribute(
"
Organ
"
, jhfForm.getOrgan());
203
request.setAttribute(
"
Station
"
, jhfForm.getStation());
204
request.setAttribute(
"
EduExp
"
, jhfForm.getEduExp());
205
request.setAttribute(
"
MarriageState
"
, jhfForm.getMarriageState());
206
request.setAttribute(
"
OfficeHolder
"
, jhfForm.getOfficeHolder());
207
request.setAttribute(
"
EmployeeType
"
, jhfForm.getEmployeeType());
208
request.setAttribute(
"
Job
"
, jhfForm.getJob());
209
//
request.setAttribute("sex",user.getSzSex());
210
211
212
System.out.println(
"
set ok!
"
);
213
//
request.setAttribute("user", user);
214
//
request.setAttribute("id1", "0212");
215
//
request.getSession().setAttribute("id", id);
216
//
jhfForm.setSzUserId(user.getSzUserId());
217
//
jhfForm.setSzUserName(user.getSzUserName());
218
//
jhfForm.setSzPassword((user.getSzPassword()));
219
//
jhfForm.setSzOrgan(user.getSzOrgan());
220
//
jhfForm.setSzStation(user.getSzStation());
221
//
jhfForm.setSzSex(user.getSzSex());
222
//
jhfForm.setSzBirthday(user.getSzBirthday());
223
//
jhfForm.setSzJob(user.getSzJob());
224
//
jhfForm.setSzGraduationSchool(user.getSzGraduationSchool());
225
//
jhfForm.setSzEduExperience(user.getSzEduExperience());
226
//
jhfForm.setSzOfficeHolder(user.getSzOfficeHolder());
227
//
jhfForm.setSzEmployeeType(user.getSzEmployeeType());
228
//
jhfForm.setSzEntryBankDate(user.getSzEntryBankDate());
229
//
jhfForm.setSzWorkDate(user.getSzWorkDate());
230
//
jhfForm.setSzIdCardNumber(user.getSzIdCardNumber());
231
//
jhfForm.setSzMarriageState(user.getSzMarriageState());
232
//
jhfForm.setSzFamilyAddress(user.getSzFamilyAddress());
233
//
jhfForm.setSzLifeAddress(user.getSzLifeAddress());
234
//
jhfForm.setSzFamilyTel(user.getSzFamilyTel());
235
//
jhfForm.setSzMobilePhone(user.getSzMobilePhone());
236
//
jhfForm.setSzRegState(user.getSzRegState());
237
//
jhfForm.setSzUserRole(user.getSzUserRole());
238
239
240
//
System.out.println(user.getSzUserId());
241
242
return
mapping.findForward(
"
changeuser
"
);
243
}
244
245
/** */
/**
***修改密码*****
*/
246
public
ActionForward modifyPassword(ActionMapping mapping, ActionForm form,
247
HttpServletRequest request, HttpServletResponse response)
{
248
String oldpass
=
request.getParameter(
"
oldpass
"
);
249
String newpass
=
request.getParameter(
"
newpass
"
);
250
String repass
=
request.getParameter(
"
repass
"
);
251
TSysUser user
=
(TSysUser)request.getSession().getAttribute(
"
user1
"
);
252
if
(repass.equals(newpass)
&&
oldpass.equals(user.getSzPassword()))
{
253
user.setSzPassword(newpass);
254
sysUserService.changeUser(user);
255
request.getSession().removeAttribute(
"
user1
"
);
256
request.getSession().setAttribute(
"
user1
"
,user);
257
return
mapping.findForward(
"
ModPassOk
"
);
258
}
259
return
mapping.findForward(
"
ModPassFail
"
);
260
}
261
262
/** */
/**
***加载用户图片*****
*/
263
public
ActionForward load(ActionMapping mapping, ActionForm form,
264
HttpServletRequest request, HttpServletResponse response)
{
265
String userId
=
request.getParameter(
"
id
"
);
266
TSysUser user
=
sysUserService.getById(userId);
267
Blob img
=
user.getImPhoto();
268
long
length
=
0
;
269
try
{
270
length
=
img.length();
271
}
catch
(SQLException e2)
{
272
//
TODO Auto-generated catch block
273
e2.printStackTrace();
274
}
275
if
(img
!=
null
&&
length
!=
0
)
{
276
InputStream is
=
null
;
277
try
{
278
is
=
img.getBinaryStream();
279
}
catch
(SQLException e1)
{
280
//
TODO Auto-generated catch block
281
282
e1.printStackTrace();
283
}
284
OutputStream os
=
null
;
285
try
{
286
os
=
new
BufferedOutputStream(response.getOutputStream());
287
response.setContentType(
"
image/jpeg
"
);
288
response.setContentLength(is.available());
289
byte
[] buf
=
new
byte
[
102400
];
290
int
len;
291
while
((len
=
is.read(buf))
!=-
1
)
292
{
293
os.write(buf,
0
,len);
294
}
295
os.close();
296
is.close();
297
}
catch
(IOException e)
{
298
//
TODO Auto-generated catch block
299
e.printStackTrace();
300
}
301
}
else
{
302
try
{
303
response.setContentType(
"
image/jpeg
"
);
304
int
width
=
125
,height
=
150
;
305
BufferedImage bufImg
=
new
BufferedImage(width,height,BufferedImage.TYPE_INT_RGB);
306
Graphics2D g2d
=
(Graphics2D) bufImg.getGraphics();
307
Font font
=
new
Font(
"
大标宋
"
, Font.LAYOUT_LEFT_TO_RIGHT,
13
);
308
309
g2d.setBackground(Color.white);
310
g2d.setColor(Color.BLUE);
311
g2d.clearRect(
0
,
0
, width, height);
312
//
设置前景色:
313
g2d.setColor(Color.RED);
314
g2d.setFont(font);
315
g2d.drawString(
"
该用户暂未上传照片!
"
,
0
,
75
);
316
g2d.dispose();
317
bufImg.flush();
318
OutputStream out
=
response.getOutputStream();
319
JPEGImageEncoder enc
=
JPEGCodec.createJPEGEncoder(out);
320
JPEGEncodeParam params
=
enc.getDefaultJPEGEncodeParam(bufImg);
321
params.setQuality(
100
,
true
);
322
enc.encode(bufImg);
323
out.close();
324
}
catch
(Exception e)
{
325
System.out.println(e);
326
}
327
}
328
return
null
;
329
}
330
331
public
ActionForward list(ActionMapping mapping, ActionForm form,
332
HttpServletRequest request, HttpServletResponse response)
{
333
HttpSession session
=
request.getSession();
334
String id
=
(String)session.getAttribute(
"
id
"
);
335
336
TSysUser user
=
sysUserService.getById(id);
337
request.setAttribute(
"
user
"
, user);
338
/** */
/**
***************************查看用户信息时需要的******************************************
*/
339
String marriageState
=
sysUserService.getOnProperty(user,
"
szMarriageState
"
);
340
String jobb
=
sysUserService.getOnProperty(user,
"
szJob
"
);
341
String empType
=
sysUserService.getOnProperty(user,
"
szEmployeeType
"
);
342
String offHolder
=
sysUserService.getOnProperty(user,
"
szOfficeHolder
"
);
343
String eduExp
=
sysUserService.getOnProperty(user,
"
szEduExperience
"
);
344
345
request.setAttribute(
"
jobb
"
,jobb );
346
request.setAttribute(
"
marriagestate
"
,marriageState);
347
request.setAttribute(
"
employeetype
"
,empType);
348
request.setAttribute(
"
officeholder
"
,offHolder);
349
request.setAttribute(
"
eduexp
"
, eduExp);
350
351
return
mapping.findForward(
"
list
"
);
352
}
353
/** */
/**
***用户信息修改*****
*/
354
public
ActionForward save(ActionMapping mapping, ActionForm form,
355
HttpServletRequest request, HttpServletResponse response)
{
356
HttpSession session
=
request.getSession();
357
JhfForm jhfForm
=
(JhfForm) form;
358
String id
=
(String)session.getAttribute(
"
id
"
);
359
TSysUser user
=
sysUserService.getById(id);
360
361
//
user.setSzUserName(jhfForm.getSzUserName());
362
//
user.setImPhoto(jhfForm.getImPhoto());
363
user.setSzOrgan(jhfForm.getSzOrgan());
364
user.setSzStation(jhfForm.getSzStation());
365
user.setSzSex(jhfForm.getSzSex());
366
user.setSzBirthday(jhfForm.getSzBirthday());
367
user.setSzJob(jhfForm.getSzJob());
368
user.setSzGraduationSchool(jhfForm.getSzGraduationSchool());
369
user.setSzEduExperience(jhfForm.getSzEduExperience());
370
user.setSzOfficeHolder(jhfForm.getSzOfficeHolder());
371
user.setSzEmployeeType(jhfForm.getSzEmployeeType());
372
user.setSzEntryBankDate(jhfForm.getSzEntryBankDate());
373
user.setSzWorkDate(jhfForm.getSzWorkDate());
374
user.setSzIdCardNumber(jhfForm.getSzIdCardNumber());
375
user.setSzMarriageState(jhfForm.getSzMarriageState());
376
user.setSzFamilyAddress(jhfForm.getSzFamilyAddress());
377
user.setSzLifeAddress(jhfForm.getSzLifeAddress());
378
user.setSzFamilyTel(jhfForm.getSzFamilyTel());
379
user.setSzMobilePhone(jhfForm.getSzMobilePhone());
380
381
sysUserService.saveUser(user);
382
383
/** */
/**
****************修改用户信息后要重新设置首页的各项的值************************
*/
384
String org
=
sysUserService.getOnProperty(user,
"
szOrgan
"
);
385
String role
=
sysUserService.getUserRole(user,
"
szUserRole
"
);
386
String sta
=
sysUserService.getOnProperty(user,
"
szStation
"
);
387
String password
=
user.getSzPassword();
388
389
session.setAttribute(
"
password
"
, password);
390
session.setAttribute(
"
org
"
,org);
391
session.setAttribute(
"
role
"
,role);
392
session.setAttribute(
"
state
"
,sta);
393
394
return
mapping.findForward(
"
changesuccess
"
);
395
}
396
397
/** */
/**
***用户注销*****
*/
398
public
ActionForward logOff(ActionMapping mapping, ActionForm form,
399
HttpServletRequest request, HttpServletResponse response)
{
400
TSysUser user
=
(TSysUser)request.getSession().getAttribute(
"
user1
"
);
401
if
(user
!=
null
)
{
402
request.getSession().removeAttribute(
"
user1
"
);
403
//
msg="ע��ɹ���";
404
}
405
//
forward="window.location.href='"+request.getContextPath()+"/login.vm'";
406
//
request.setAttribute("msg", msg);
407
//
request.setAttribute("forward", forward);
408
return
mapping.findForward(
"
logoff
"
);
409
}
410
411
/** */
/**
***用户详细信息*****
*/
412
public
ActionForward showDetail(ActionMapping mapping, ActionForm form,
413
HttpServletRequest request, HttpServletResponse response)
{
414
String id
=
request.getParameter(
"
SzUserId
"
);
415
TSysUser user
=
sysUserService.getById(id);
416
List
<
TSysDict
>
organ
=
sysDictService.listByOrgan();
417
List
<
TSysDict
>
station
=
sysDictService.listByStation();
418
List
<
TSysDict
>
job
=
sysDictService.listByJob();
419
List
<
TSysDict
>
education
=
sysDictService.listByEdu();
420
List
<
TSysDict
>
title
=
sysDictService.listByTitle();
421
List
<
TSysDict
>
type
=
sysDictService.listByType();
422
List
<
TSysDict
>
marriage
=
sysDictService.listByMarrigeState();
423
424
request.setAttribute(
"
User
"
, user);
425
request.setAttribute(
"
Organ
"
, organ);
426
request.setAttribute(
"
Station
"
, station);
427
request.setAttribute(
"
Job
"
, job);
428
request.setAttribute(
"
Education
"
, education);
429
request.setAttribute(
"
Title
"
, title);
430
request.setAttribute(
"
Type
"
, type);
431
request.setAttribute(
"
Marriage
"
, marriage);
432
433
return
mapping.findForward(
"
showdetail
"
);
434
}
435
436
public
ActionForward forward(ActionMapping mapping, ActionForm form,
437
HttpServletRequest request, HttpServletResponse response)
{
438
msg
=
"
只是一个测试
"
;
439
//
forward="window.location.href='"+request.getContextPath()+"/login.vm'";
440
forward
=
"
window.location.href='http://www.baidu.com'
"
;
441
request.setAttribute(
"
msg
"
, msg);
442
request.setAttribute(
"
forward
"
, forward);
443
return
mapping.findForward(
"
info
"
);
444
445
}
446
}
posted on 2008-06-17 07:12
yasoo
阅读(89)
评论(0)
编辑
收藏
新用户注册
刷新评论列表
只有注册用户
登录
后才能发表评论。
网站导航:
博客园
IT新闻
Chat2DB
C++博客
博问
管理
Powered by:
BlogJava
Copyright © yasoo