总流程:
index.jsp页面 :
<
s:form
action
=
"PersonLogin"
method
=
"post"
>
<
table
border
=
"1"
bgcolor
=
"red"
>
<
tr
>
<
th
>
<
s:textfield
name
=
"uname"
label
=
"用户名"
size
=
"14"
/>
</
th
>
</
tr
>
<
tr
>
<
td
>
<
s:password
name
=
"pwd"
label
=
"密码"
size
=
"14"
/>
</
td
>
</
tr
>
</
table
>
<
s:submit
value
=
"登陆"
align
=
"center"
/>
</
s:form
>
Struts-xml:
<!-- 个人登陆 -->
<
action
name
=
"PersonLogin"
class
=
"PersonLogin"
>
<
result
name
=
"success"
>
/WEB-INF/ jsp/person/main.jsp
</
result
>
<
result
name
=
"input"
>
/WEB-INF/jsp/person/login.jsp
</
result
>
<
result
name
=
"error"
>
/WEB-INF/jsp/person/main.jsp
</
result
>
</
action
>
applicationcontext.xml:
<!-- 个人登陆 -->
<
bean
id
=
"PersonLogin"
class
=
"com.qzzp.action.PersonLogin"
scope
=
"prototype"
>
<
property
name
=
"service"
ref
=
"person_Service"
></
property
>
</
bean
>
Action层:
public
class
PersonLogin
extends
ActionSupport {
private
Person
person
;
private
Person_Service
service
;
public
Person getPerson() {
return
person
;
}
public
void
setPerson(Person person) {
this
.
person
= person;
}
public
Person_Service getService() {
return
service
;
}
public
void
setService(Person_Service service) {
this
.
service
= service;
}
@Override
public
String execute()
throws
Exception {
int
id=
this
.
service
.personLogin(
person
.getUname(),
person
.getPwd());
if
(id>0){
return
SUCCESS
;
}
else
{
return
ERROR
;
}
}
}
dao层:
public
Person loginByNP(String uname, String pwd);
//个人登陆
dao impl 层:
public
Person loginByNP(String uname, String pwd) {
ht
= getHibernateTemplate();
List personList =
ht
.find(
"from Person person where person.uname=?and person.pwd=?"
,
new
String[] { uname, pwd });
if
(personList !=
null
&& personList.size() >= 1) {
return
(Person) personList.get(0);
}
return
null
;
}
service层:
public
int
personLogin(String uname,String pwd)
throws
Exception;
service Impl层:
public
int
personLogin(String uname, String pwd)
throws
Exception {
try
{
Person person=
personDAO
.loginByNP(uname, pwd);
if
(person!=
null
)
return
person.getId();
}
catch
(Exception e) {
e.printStackTrace();
throw
new
Exception(
"验证用户登陆时出现错误"
);
}
return
-1;
}