您好,欢迎来到爱够旅游网。
搜索
您的当前位置:首页ssh教程

ssh教程

来源:爱够旅游网


第一步, 创建WEB工程,添加struts框架

第二步, 添加必要的包

第三步, 添加spring支持

添加两个库:

Core和web lib

第四步, 修改web.xml文件

添加初始化配置文件

contextConfigLocation

/WEB-INF/applicationContext.xml

Web上下文的监听

org.springframework.web.context.ContextLoaderListenerener-class>

第五步, 添加struts的代理,(在struts-config.xml中)

processorClass=\"org.springframework.web.struts.DelegatingRequestProcessor\">

第六步, 添加hibernate支持

第七步, 在spring中会帮助生成一下配置(包括: 数据源, sessionFactory)

value=\"com.microsoft.jdbc.sqlserver.SQLServerDriver\">

value=\"jdbc:microsoft:sqlserver://localhost:1433;databaseName=pubs\">

class=\"org.springframework.orm.hibernate3.LocalSessionFactoryBean\">

org.hibernate.dialect.SQLServerDialect

true

第八步, 反向生成”表对象”, ”hbm配置文件”, “dao类”

第九步, 在appilcationContext.xml配置文件中将会添加一个配置(反转了DAO类, 这个类供service层使用)

第十步, 修改了applicationContext.xml文件中的sessionFactory配置(新加上了表对象的映射)

//……

org.hibernate.dialect.SQLServerDialect

true

com/alex/sshtest/entity/Root65.hbm.xml

第十一步, 创建service层

public class RootService {

private Root65DAO dao;

public Root65DAO getDao() {

return dao;

}

public void setDao(Root65DAO dao) {

this.dao = dao;

}

public void save(RootForm root) {

Root65 r = new Root65();

r.setUsername(root.getUsername());

r.setUsercity(root.getUsercity());

this.getDao().save(r);

}

}

第十二步, 反转service

第十三步, 创建action, form, jsp

第十四步, 修改struts-config.xml配置文件(将action元素中的type属性删除)

第十五步, 在action中添加调用service的代码

private RootService service;

public RootService getService() {

return service;

}

public void setService(RootService service) {

this.service = service;

}

public ActionForward execute(ActionMapping mapping, ActionForm form,

HttpServletRequest request, HttpServletResponse response) {

RootForm rootForm = (RootForm) form;

this.getService().save(rootForm);

return new ActionForward(mapping.getInput());

}

第十六步, 代理action,

第十七步,运行调试

总结,ssh程序的处理过程

因篇幅问题不能全部显示,请点此查看更多更全内容

Copyright © 2019- igbc.cn 版权所有 湘ICP备2023023988号-5

违法及侵权请联系:TEL:199 1889 7713 E-MAIL:2724546146@qq.com

本站由北京市万商天勤律师事务所王兴未律师提供法律服务