当前位置: 首页 > news >正文

兰州企业网站网络公司网站

兰州企业网站,网络公司网站,dw如何做网站登陆验证,如何做盗版视频网站17:44 SSH即Strutsspringhibernate框架. 本次体验使用的Struts2spring3hibernate3 1,创建ssh工程. 2,添加hibernate访问数据库 Windows->show view->dbExplorer ●创建db连接,本次体验使用mysql作为体验数据库,其他数据库应该类似 ●选…

 

17:44

SSHStruts+spring+hibernate框架.

本次体验使用的Struts2+spring3+hibernate3

1,创建ssh工程.

2,添加hibernate访问数据库

Windows->show view->dbExplorer

●创建db连接,本次体验使用mysql作为体验数据库,其他数据库应该类似

选择配置的连接右键->openconnection建立数据库连接.

●添加hibernate配置:两种方式:POJODao/SpringDao两者没有太大差异只是在配置时略有不同)

如果使用Spring Dao则需要先引用Spring支持Library

右键projectMyEclipse->Add Spring Cap….

一路默认即可

添加Hibernate支持:Project->右键->MyEclipse->add hibernate cap…

Next如果Pojo则选择Hibernate.xfg.xml,如果SpringDao则选择applicatonContext.xml

根据需要选择xml文件

选择数据库连接配置

选择实体类生成文件存储路径和包

Finish完成Hibernate配置

添加Spring persistence jdbc libraries工程右键->properties->java build path->MyEclipse->spring xxx persistence jdbc libraries

●生成HibernateDao实体数据

数据库连接中选择schma->Table右键->Hibernate Reverse Engineering来生成Dao

如果为pojodao选择basicdao

如果springdao选择spring dao

nextid generator中选择native根据需要选择one-to-many/many-to-one等选项

Next->finish则在相应的package中将生成对应的xxxdao.java,xxx.hbm.xml等文件

●添加业务层逻辑

添加相应处理接口这里使用IOwenerService接口,添加getOwners()

public interface IOwnerService {

public List getOwners();

}

 

添加OwenerService继承自IOwenerService,然后添加相应的Dao对象作为OwenerService的成员。

然后生成getter/Setter

public class OwnerService implements IOwnerService {

public OwnersDAO getOwnerDao() {

return ownerDao;

}

public void setOwnerDao(OwnersDAO ownerDao) {

this.ownerDao = ownerDao;

}

private OwnersDAO ownerDao; //根据需要变更

public List getOwners() {

// TODO Auto-generated method stub                

return ownerDao.findAll();

}

}

●添加表现层处理

Project->右键->Add Struts cap….

 

选择struts2 core/struts 2 spring(strutsspring的连接必须选择)

Finish完成Struts的添加

 

添加页面以及相应的action

action

public class ListAction extends ActionSupport {

public Collection getOwners() {

return owners;

}

public void setOwenrSrv(IOwnerService owenrSrv) {

this.owenrSrv = owenrSrv;

}

private IOwnerService owenrSrv;

private Collection owners;

/**

 * @return

 */

public String execute() {

// TODO Auto-generated method stub

owners = this.owenrSrv.getOwners();

return SUCCESS;

}

}

 

Index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

   

    <title>My JSP 'index.jsp' starting page</title>

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">   

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

  </head>

 

  <body>

     <p><a href="<s:url action='listAction'/>">List</a></p><br>

  </body>

</html>

 

List.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>

<%@ taglib prefix="s" uri="/struts-tags"%>

<%

String path = request.getContextPath();

String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

%>

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

  <head>

    <base href="<%=basePath%>">

   

    <title>My JSP 'List.jsp' starting page</title>

   

<meta http-equiv="pragma" content="no-cache">

<meta http-equiv="cache-control" content="no-cache">

<meta http-equiv="expires" content="0">   

<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">

<meta http-equiv="description" content="This is my page">

<!--

<link rel="stylesheet" type="text/css" href="styles.css">

-->

 

  </head>

 

  <body>

  <table>

          <tbody>

            <s:iterator value="items">

            <tr>

            <td>

                    <a><s:property value="Username"/></a>

            </td>

            <td>

                    <a><s:property value="Descn"/></a>

            </td>

            </tr>

            </s:iterator>

    </tbody>

  </table>

  </body>

</html>

 

xml配置

Struts.xml配置如下

<?xml version="1.0" encoding="UTF-8" ?>

<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">

<struts>

<constant name="struts.enable.DynamicMethodInvocation" value="false" /> 

    <constant name="struts.devMode" value="false" />  

    <constant name="struts.objectFactory" value="spring"/>

   

 

<package name="default" extends="struts-default">

<!-- listActionBean 对应到applicationContextbean -->

<action name="listAction" class="listActionBean">

<result>/List.jsp</result></action></package></struts> 

 

Applicationcontext.xml

<?xml version="1.0" encoding="UTF-8"?>

<beans

xmlns="http://www.springframework.org/schema/beans"

xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

xmlns:p="http://www.springframework.org/schema/p"

xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">

 

 

<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource">

<property name="driverClassName"

value="com.mysql.jdbc.Driver">

</property>

<property name="url" value="jdbc:mysql://localhost:3306"></property>

<property name="username" value="root"></property>

<property name="password" value="sa"></property>

</bean>

<bean id="sessionFactory" class="org.springframework.orm.hibernate3.LocalSessionFactoryBean">

<property name="dataSource">

<ref bean="dataSource" />

</property>

<property name="hibernateProperties">

<props>

<prop key="hibernate.dialect">

org.hibernate.dialect.MySQLDialect

</prop>

<prop key="hibernate.hbm2ddl.auto">update</prop>

</props>

</property>

<property name="mappingResources">

<list>

<value>./sshDemo/Entities/Owners.hbm.xml</value>

<value>./sshDemo/Entities/Pets.hbm.xml</value>

<value>./sshDemo/Entities/Types.hbm.xml</value>

<value>./Visits.hbm.xml</value>

</list>

</property>

</bean>

<bean id="OwnersDAO" class="sshDemo.Entities.OwnersDAO">

<property name="sessionFactory">

<ref bean="sessionFactory" />

</property>

</bean>

<bean id="PetsDAO" class="sshDemo.Entities.PetsDAO">

<property name="sessionFactory">

<ref bean="sessionFactory" />

</property>

</bean>

<bean id="TypesDAO" class="sshDemo.Entities.TypesDAO">

<property name="sessionFactory">

<ref bean="sessionFactory" />

</property>

</bean>

<bean id="VisitsDAO" class="sshDemo.Entities.VisitsDAO">

<property name="sessionFactory">

<ref bean="sessionFactory" />

</property>

</bean>

<!-- 依赖注入 -->

<bean id="ownerSerivce" class="sshDemo.bll.OwnerService">

<property name="ownerDao">

<ref bean="OwnersDAO" />

</property>

</bean>

<bean id="listActionBean" class="sshDemo.Actions.ListAction">

<property name="owenrSrv">

<ref bean="ownerSerivce" />

</property>

</bean>

</beans>

 

Web.xml配置

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"

 xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee   http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">

 <context-param>

         <param-name>contextConfigLocation</param-name>

         <param-value>/WEB-INF/classes/applicationContext.xml</param-value>

 </context-param>

 <filter>

  <filter-name>struts2</filter-name>

  <filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>

 </filter>

 <filter-mapping>

  <filter-name>struts2</filter-name>

  <url-pattern>/*</url-pattern>

 </filter-mapping>

 <welcome-file-list>

  <welcome-file>index.jsp</welcome-file>

 </welcome-file-list>

 <login-config>

  <auth-method>BASIC</auth-method>

 </login-config>

 <listener>

         <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>

 </listener>

</web-app>

至此,已经完成了ssh架构的初次体验。

 

转载于:https://www.cnblogs.com/SkyMouse/archive/2011/01/05/2340746.html

http://www.lbrq.cn/news/2554849.html

相关文章:

  • 提供邯郸做移动网站seo教程
  • 学校网站建设调查报告软件开发外包公司
  • 无锡商城网站建设哈尔滨网络推广
  • app拉新渠道南宁seo营销推广
  • 做动态网站学php_asp+还是jsp好?武汉网站搜索引擎优化
  • 清远网站建设推广关键词排名点击软件推荐
  • 面包类网站设计成都网站设计
  • 可以自己做视频网站吗拼多多商品关键词搜索排名
  • 怎么买域名自己做网站营销团队找产品合作
  • 网站文章更新做销售找客户渠道
  • 昆明网站开发哪家好网站定制
  • 上海松江区做网站的公司成都百度seo优化公司
  • 对省政府网站建设的发展有期待seo快速推广
  • 平顶山公司做网站seo关键词优化系统
  • 网站开发团队介绍谷歌商店下载官网
  • 品划做网站广告公司广告牌制作
  • 常德市人民政府网站今日最新闻
  • 律师网站深圳网站设计关键词热度分析工具
  • 河南映天建设网站关键词优化技巧
  • 网站建设综合推荐指数网站
  • 做网站咋不用买虚拟机网址和网站的区别
  • 海南专业网站建设seo的排名机制
  • 做网站服务器需要系统关键词生成器 在线
  • 网站建设差打不开疫情防控最新通告
  • 重庆百度网站快速排名怎么样推广自己的产品
  • 高端企业门户网站建设服务公司外贸营销推广
  • 做视频网站视频存放问题企业培训计划方案
  • 榆林公司做网站外链发布
  • 有没有发布需求的网站网络营销公司招聘
  • 河南省建设监理协会网站重庆做网络优化公司电话
  • Node.js的用途和安装方法
  • 【云计算】云主机的亲和性策略(二):集群节点组
  • 渗透测试常用指令
  • Excel文件解析
  • 学以致用——用Docker搭建ThinkPHP开发环境
  • STM32F1 Flash的操作