SSH学习笔记文档格式.docx
- 文档编号:16544751
- 上传时间:2022-11-24
- 格式:DOCX
- 页数:17
- 大小:63.29KB
SSH学习笔记文档格式.docx
《SSH学习笔记文档格式.docx》由会员分享,可在线阅读,更多相关《SSH学习笔记文档格式.docx(17页珍藏版)》请在冰豆网上搜索。
xsi="
http:
//www.w3.org/2001/XMLSchema-instance"
xsi:
schemaLocation="
<
filter>
!
--过滤器名struts2-->
filter-name>
struts2<
/filter-name>
filter-class>
org.apache.struts2.dispatcher.FilterDispatcher<
/filter-class>
/filter>
filter-mapping>
--表示过滤所有的请求-->
url-pattern>
/*<
/url-pattern>
/filter-mapping>
welcome-file-list>
--表示默认系统页面为login.jsp-->
welcome-file>
login.jsp<
/welcome-file>
/welcome-file-list>
---加载spring开始-->
listener>
<
listener-class>
org.springframework.web.context.ContextLoaderListener<
/listener-class>
/listener>
---加载spring完成-->
/web-app>
2)applicationContext.xml
beans
//www.springframework.org/schema/beans"
//www.springframework.org/schema/beanshttp:
//www.springframework.org/schema/beans/spring-beans-2.0.xsd"
beanid="
_userDao"
class="
org.dql.dao.impl.UserDao"
/bean>
---登陆相关-->
loginService"
org.dql.services.impl.LoginService"
propertyname="
userDao"
reflocal="
/>
/property>
--scope="
prototype表示请求是独立的不相互干扰,线程安全的-->
loginAction"
org.dql.action.LoginAction"
scope="
prototype"
--注册相关-->
registerAction"
org.dql.action.RegisterAction"
registerService"
org.dql.services.impl.RegisterService"
/beans>
3)hibernate.cfg.xml
xmlversion='
1.0'
encoding='
UTF-8'
DOCTYPEhibernate-configurationPUBLIC
"
-//Hibernate/HibernateConfigurationDTD3.0//EN"
--GeneratedbyMyEclipseHibernateTools.-->
hibernate-configuration>
session-factory>
connection.username"
root<
connection.url"
jdbc:
mysql:
//127.0.0.1/stud
dialect"
org.hibernate.dialect.MySQLDialect
myeclipse.connection.profile"
MySqlDriver<
connection.password"
manage<
connection.driver_class"
com.mysql.jdbc.Driver
mappingresource="
org/dql/entitys/User.hbm.xml"
/>
/session-factory>
/hibernate-configuration>
4)Struts.xml
?
DOCTYPEstrutsPUBLIC
-//ApacheSoftwareFoundation//DTDStrutsConfiguration2.0//EN"
//struts.apache.org/dtds/struts-2.0.dtd"
struts>
constantname="
struts.i18n.encoding"
value="
gbk"
/constant>
packagename="
struts2"
extends="
struts-default"
actionname="
login"
resultname="
input"
/login.jsp<
/result>
success"
/out_login.jsp<
/action>
register"
/register.jsp<
/out_register.jsp<
/package>
/struts>
5)struts.properties
struts.locale=zh_CN
struts.i18n.encoding=UTF-8
struts.objectFactory=spring
4.持久层
1)HibernateSessionFactory.java
packageorg.dql.hibernate;
importorg.hibernate.HibernateException;
importorg.hibernate.Session;
importorg.hibernate.cfg.Configuration;
publicclassHibernateSessionFactory{
privatestaticStringCONFIG_FILE_LOCATION="
/org/dql/hibernate/hibernate.cfg.xml"
;
privatestaticfinalThreadLocal<
Session>
threadLocal=newThreadLocal<
();
privatestaticConfigurationconfiguration=newConfiguration();
privatestaticorg.hibernate.SessionFactorysessionFactory;
privatestaticStringconfigFile=CONFIG_FILE_LOCATION;
static{
try{
configuration.configure(configFile);
sessionFactory=configuration.buildSessionFactory();
}catch(Exceptione){
System.err
.println("
%%%%ErrorCreatingSessionFactory%%%%"
);
e.printStackTrace();
}
}
privateHibernateSessionFactory(){
publicstaticSessiongetSession()throwsHibernateException{
Sessionsession=(Session)threadLocal.get();
if(session==null||!
session.isOpen()){
if(sessionFactory==null){
rebuildSessionFactory();
}
session=(sessionFactory!
=null)?
sessionFactory.openSession()
:
null;
threadLocal.set(session);
returnsession;
publicstaticvoidrebuildSessionFactory(){
publicstaticvoidcloseSession()throwsHibernateException{
threadLocal.set(null);
if(session!
=null){
session.close();
publicstaticorg.hibernate.SessionFactorygetSessionFactory(){
returnsessionFactory;
publicstaticvoidsetConfigFile(StringconfigFile){
HibernateSessionFactory.configFile=configFile;
sessionFactory=null;
publicstaticConfigurationgetConfiguration(){
returnconfiguration;
}
2)User.java
packageorg.dql.entitys;
publicclassUser{
privateStringusername;
privateStringpassword;
publicStringgetUsername(){
returnusername;
publicvoidsetUsername(Stringusername){
this.username=username;
publicStringgetPassword(){
returnpassword;
publicvoidsetPassword(Stringpassword){
this.password=password;
3)User.hbm.xml
DOCTYPEhibernate-mappingPUBLIC
-//Hibernate/HibernateMappingDTD3.0//EN"
hibernate-mapping>
classname="
org.dql.entitys.User"
table="
User"
lazy="
true"
idname="
username"
type="
string"
column="
/id>
propertytype="
name="
password"
/class>
/hibernate-mapping>
4)IUserDao.java
packageorg.dql.dao.interfaces;
importorg.dql.entitys.User;
publicinterfaceIUserDao{
publicbooleanaddUser(Useruser);
publicbooleancheckUser(Stringusername,Stringpassword);
5)UserDao.java
packageorg.dql.dao.impl;
importjava.util.List;
importorg.dql.dao.interfaces.IUserDao;
importorg.dql.hibernate.HibernateSessionFactory;
importorg.hibernate.Query;
importorg.hibernate.Transaction;
publicclassUserDaoimplementsIUserDao{
publicbooleanaddUser(Useruser){
Sessionsession=null;
Transactiontransaction=null;
session=HibernateSessionFactory.getSession();
transaction=session.getTransaction();
transaction.begin();
session.save(user);
mit();
returntrue;
}catch(Exceptionex){
if(transaction!
=null)
transaction.rollback();
}finally{
session.close();
returnfalse;
@SuppressWarnings("
unchecked"
)
publicbooleancheckUser(Stringusername,Stringpassword){
session=HibernateSessionFactory.getSession();
Stringhql="
fromUseruwhereu.username=?
andu.password=?
"
Queryquery=session.createQuery(hql);
query.setParameter(0,username);
query.setParameter(1,password);
Listlist=query.list();
if(list.size()>
0)
5.控制层
1)ILoginService.java
packageorg.dql.services.interfaces;
publicinterfaceILoginService{
publicbooleanisLogin(Stringusername,Stringpassword);
2)IRegisterService.java
publicinterfaceIRegisterService{
3)LoginService.java
packageorg.dql.services.impl;
importorg.dql.services.interfaces.ILoginService;
publicclassLoginServiceimplementsILoginService{
privateIUserDaouserDao;
publicvoidsetUserDao(IUserDaouserDao){
this.userDao=userDao;
publicbooleanisLogin(Stringusername,Stringpassword){
returnuserDao.checkUser(username,password);
4)RegisterService.java
importorg.dql.services.interfaces.IRegisterService;
publicclassRegisterServiceimplementsIRegisterService{
returnuserDao.addUser(user);
6.视图层
1)LoginAction.java
packageorg.dql.action;
importcom.opensymphony.xwork2.ActionSupport;
@SuppressWarnings("
serial"
publicclassLoginActionextendsActionSupport{
privateStringuse
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- SSH 学习 笔记
![提示](https://static.bdocx.com/images/bang_tan.gif)