码迷,mamicode.com
首页 > 其他好文 > 详细

SSH框架搭建

时间:2016-06-16 13:17:44      阅读:204      评论:0      收藏:0      [点我收藏+]

标签:

1.建项目

技术分享

2.添加Struts

技术分享

 

技术分享

3.添加String

技术分享

 

技术分享

注意:这里一共是五个包

技术分享

4.添加Hibernate

技术分享

 

技术分享

 

技术分享

技术分享

技术分享

添加完成,然后导入数据库

技术分享

 

技术分享

 

技术分享

这时候是这样的

技术分享

把小绿叶放到WEB-INF

技术分享

5.简单写struts

技术分享

技术分享

<?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>

    <package name="default" extends="struts-default">
        <action name="Login" class="com.hao.action.login">
            <result name="success">/Success.html</result></action></package></struts>    

6.web.xml添加监听

 <!-- Spring配置与Struts2的监听 -->
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>

完整代码:

<?xml version="1.0" encoding="UTF-8"?>
<web-app version="3.0" 
    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_3_0.xsd">
  <display-name></display-name>    
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>
  <filter>
      <filter-name>struts2</filter-name>
      <filter-class>
          org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
      </filter-class>
  </filter>
  <filter-mapping>
      <filter-name>struts2</filter-name>
      <url-pattern>*.action</url-pattern>
  </filter-mapping>
   <!-- Spring配置与Struts2的监听 -->
  <context-param>
      <param-name>contextConfigLocation</param-name>
      <param-value>/WEB-INF/applicationContext.xml</param-value>
  </context-param>
  <listener>
      <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
  </listener>
  </web-app>

7.小绿叶添加

<bean id="LoginAction" class="com.hao.action.login"></bean>

代码为:

<?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.microsoft.sqlserver.jdbc.SQLServerDriver">
        </property>
        <property name="url" value="jdbc:sqlserver://127.0.0.1"></property>
        <property name="username" value="sa"></property>
        <property name="password" value="1"></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.SQLServerDialect
                </prop>
            </props>
        </property>
        <property name="mappingResources">
            <list>
                <value>com/chao/db/UserInfo.hbm.xml</value></list>
        </property></bean>
        
        <bean id="LoginAction" class="com.hao.action.login"></bean>
        
        </beans>

8.修改strurs

<action name="Login" class="LoginAction">

9.index.jsp提交

 <body>
    This is my JSP page. <br>
     <form action="Login.action">
    <input type="submit">
    </form>
  </body>

10.结果截图

技术分享

技术分享

成功跳转

SSH框架搭建

标签:

原文地址:http://www.cnblogs.com/feifeishi/p/5590614.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!