SSH框架整合1
======================web.xml=======================
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd"
version="4.0"> <context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:spring.xml</param-value>
</context-param>
<!--配置监听器-->
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener> <!-- Struts核心过滤器 -->
<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>/*</url-pattern>
</filter-mapping>
</web-app> =============================spring.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:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd"> <!--开启注解-->
<context:annotation-config/> <!--告知spring要去哪个包找注解-->
<context:component-scan base-package="com.ssh"/> <aop:aspectj-autoproxy/> <bean name="myDataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<!--配置数据库信息-->
<property name="driverClassName" value="com.mysql.jdbc.Driver"/>
<property name="url" value="jdbc:mysql://localhost:3306/houserent"/>
<property name="username" value="root"/>
<property name="password" value="123456"/>
</bean> <!--配置session信息-->
<bean id="sessionFactory" class="org.springframework.orm.hibernate5.LocalSessionFactoryBean">
<property name="dataSource" ref="myDataSource"/>
<!--由于这里我们使用的是注解的方式得到属性,因此使用packagesToScan,
若在hibernate中使用hibernate.cfg.xml则在此处就使用mappingResources,
作用是指定从哪个包中查找注解的model-->
<property name="packagesToScan">
<value>com.ssh.model</value>
</property>
<!--配置hibernate属性-->
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQL5Dialect</prop>
<prop key="hibernate.hbm2ddl.auto">update</prop>
<prop key="hibernate.show_sql">true</prop>
</props>
</property>
</bean>
</beans> ======================struts.xml====================
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<constant name="struts.devMode" value="true"/>
<constant name="struts.enable.DynamicMethodInvocation" value="true"/>
<package name="default" extends="struts-default"> <!--使用通配符-->
<action name="*_*" class="{1}Controller" method="{2}">
<result name="success">{2}.jsp</result>
</action>
</package>
</struts> =========================Group.java(model层实体类)===============
package com.ssh.model; import org.hibernate.annotations.GenericGenerator;
import javax.persistence.*; @Entity
@Table(name="t_group")
public class Group {
private int id;
private String name; public Group(){} public Group(int id, String name) {
this.id = id;
this.name = name;
} @Id
@GenericGenerator(name = "increment",strategy = "increment")
@GeneratedValue(generator = "increment")
public int getId() {
return id;
} public void setId(int id) {
this.id = id;
} @Column(name="name")
public String getName() {
return name;
} public void setName(String name) {
this.name = name;
}
} ========================GroupDao.java(dao层实现类)===================
package com.ssh.dao; import com.ssh.model.Group;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.stereotype.Repository; import javax.annotation.Resource; @Repository
public class GroupDao implements IGroupDao {
private SessionFactory sessionFactory; @Resource
public void setSessionFactory(SessionFactory sessionFactory) {
this.sessionFactory = sessionFactory;
} @Override
public void add(Group group) {
Session session = sessionFactory.openSession();
session.beginTransaction();
session.save(group);
session.getTransaction().commit();
} @Override
public Group load() {
return null;
}
} ========================IGroupDao.java(dao层接口)====================
package com.ssh.dao; import com.ssh.model.Group; public interface IGroupDao {
public void add(Group group);
public Group load();
} ===================GroupService.java(service层实现类)===========
package com.ssh.service; import com.ssh.dao.IGroupDao;
import com.ssh.model.Group;
import org.springframework.stereotype.Service; import javax.annotation.Resource; @Service
public class GroupService implements IGroupService {
private IGroupDao groupDao; @Resource
public void setGroupDao(IGroupDao groupDao) {
this.groupDao = groupDao;
} @Override
public void save(Group group) {
groupDao.add(group);
} @Override
public Group load(int id) {
return null;
}
} ===================IGroupService.java(service层接口)===========
package com.ssh.service; import com.ssh.model.Group; public interface IGroupService {
public void save(Group group);
public Group load(int id);
} ===================IGroupController.java(Controller层实现类)===========
package com.ssh.controller; import com.ssh.model.Group;
import com.ssh.service.IGroupService;
import org.springframework.stereotype.Controller;
import javax.annotation.Resource; @Controller("groupController")
public class GroupController {
private IGroupService groupService;
private Group group; public Group getGroup() {
return group;
} public void setGroup(Group group) {
this.group = group;
} @Resource
public void setGroupService(IGroupService groupService) {
this.groupService = groupService;
} public String add(){
groupService.save(group);
return "success";
}
} ==================================add.jsp(前端页面)===========================
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title>add</title>
</head>
<body>
<form method="post" action="group_add">
组名:<input type="text" name="group.name">
<input type="submit" value="保存">
</form>
</body>
</html> ============================================遇到的问题=============================
Unable to instantiate Action, groupController, defined for 'group_add' in namespace ''groupController - action - file:/E:/ssh_basic/out/artifacts/ssh_basic_war_exploded/WEB-INF/classes/struts.xml:8:63
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:317)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:398)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter (StrutsPrepareAndExecuteFilter.java:99)
root cause java.lang.ClassNotFoundException: groupController
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1928)
org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1771)
com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:152)
com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:135)
com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:246)
com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:163)
com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)
com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)
com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:148)
com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:298)
com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:398)
com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)
org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)
org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)
com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)
org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)
org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter (StrutsPrepareAndExecuteFilter.java:99) 解决方法:struts.xml配置文件使用通配符方式时,要先开启struts.enable.DynamicMethodInvocation
Unable to instantiate Action, groupController, defined for 'group_add' in namespace ''groupController - action -
file:/E:/ssh_basic/out/artifacts/ssh_basic_war_exploded/WEB-INF/classes/struts.xml:8:63com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:317)com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:398)com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter
(StrutsPrepareAndExecuteFilter.java:99)root cause
java.lang.ClassNotFoundException: groupControllerorg.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1928)org.apache.catalina.loader.WebappClassLoaderBase.loadClass(WebappClassLoaderBase.java:1771)com.opensymphony.xwork2.util.ClassLoaderUtil.loadClass(ClassLoaderUtil.java:152)com.opensymphony.xwork2.ObjectFactory.getClassInstance(ObjectFactory.java:135)com.opensymphony.xwork2.spring.SpringObjectFactory.getClassInstance(SpringObjectFactory.java:246)com.opensymphony.xwork2.spring.SpringObjectFactory.buildBean(SpringObjectFactory.java:163)com.opensymphony.xwork2.ObjectFactory.buildBean(ObjectFactory.java:178)com.opensymphony.xwork2.factory.DefaultActionFactory.buildAction(DefaultActionFactory.java:22)com.opensymphony.xwork2.ObjectFactory.buildAction(ObjectFactory.java:148)com.opensymphony.xwork2.DefaultActionInvocation.createAction(DefaultActionInvocation.java:298)com.opensymphony.xwork2.DefaultActionInvocation.init(DefaultActionInvocation.java:398)com.opensymphony.xwork2.DefaultActionProxy.prepare(DefaultActionProxy.java:194)org.apache.struts2.impl.StrutsActionProxy.prepare(StrutsActionProxy.java:63)org.apache.struts2.impl.StrutsActionProxyFactory.createActionProxy(StrutsActionProxyFactory.java:37)com.opensymphony.xwork2.DefaultActionProxyFactory.createActionProxy(DefaultActionProxyFactory.java:58)org.apache.struts2.dispatcher.Dispatcher.serviceAction(Dispatcher.java:565)org.apache.struts2.dispatcher.ng.ExecuteOperations.executeAction(ExecuteOperations.java:81)org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter.doFilter
(StrutsPrepareAndExecuteFilter.java:99)
SSH框架整合1的更多相关文章
- SSH框架整合
SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...
- dwr与ssh框架整合教程
(1)dwr与ssh框架整合教程dwr框架介绍. DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开 发人员开发包含AJ ...
- ssh框架整合之登录以及增删改查
1.首先阐述一下我用得开发工具,myeclipse2017+oracle,所以我的基本配置步骤可能不一样,下面我用几张图来详解我的开发步骤. ---1先配置structs (Target 选择apac ...
- Spring+Hibernate+Struts(SSH)框架整合
SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...
- J2EE进阶(十)SSH框架整合常见问题汇总(一)
SSH框架整合常见问题汇总(一) 前言 以下所列问题具有针对性,但是遇到同类型问题时均可按照此思路进行解决. HTTP Status 404 - No result defined for actio ...
- MVC+Spring.NET+NHibernate .NET SSH框架整合 C# 委托异步 和 async /await 两种实现的异步 如何消除点击按钮时周围出现的白线? Linq中 AsQueryable(), AsEnumerable()和ToList()的区别和用法
MVC+Spring.NET+NHibernate .NET SSH框架整合 在JAVA中,SSH框架可谓是无人不晓,就和.NET中的MVC框架一样普及.作为一个初学者,可以感受到.NET出了MV ...
- SSH框架整合的其它方式
--------------------siwuxie095 SSH 框架整合的其它方式 1.主要是整合 Spring 框架和 Hibernate 框架时,可以不写 Hibernate 核心配置文件: ...
- SSH框架整合过程总结
---------------------siwuxie095 SSH 框架整合过程总结 (一)导入相关 jar 包(共 ...
- SSH框架整合思想
--------------------siwuxie095 SSH 框架整合思想 1.SSH 框架,即 Struts2 ...
- SSH框架整合jar包时的注意事项
SSH框架整合jar包时的注意事项: 在将三个框架所需的jar整合到一起后,要看一下有没有相同类型但是版本不同的jar包,如果有的话,需要把低版本的jar包删除掉,否则会报错.我这里整合的时候java ...
随机推荐
- 闭锁CountDownLatch与栅栏CyclicBarrier
https://blog.csdn.net/lmc_wy/article/details/7866863 闭锁CountDownLatch与栅栏CyclicBarrier 浅谈 java ...
- Matlab观察者模式
要点: 1.服务端(Subject)维护一个观察者的列表,以便能够向所有的观察者(Observer)推送信息 2.观察者可以获取服务端的状态 3.服务端和观察者可抽象,可以有多个不同实现 Subjec ...
- 利用onMouseOver和onMouseOut实现图像翻滚
代码: <img src="images/001.jpg" alt="pic" onmouseover="this.src='images/00 ...
- 【书评:Oracle查询优化改写】第四章
[书评:Oracle查询优化改写]第四章 BLOG文档结构图 一.1 导读 各位技术爱好者,看完本文后,你可以掌握如下的技能,也可以学到一些其它你所不知道的知识,~O(∩_∩)O~: ① check的 ...
- sql 查询某个字段最长的记录
sql 查询文本字段中值的长度最长的记录 一.函数1.SQL ServerLEN() 函数返回文本字段中值的长度.SELECT LEN(column_name) FROM table_name;2. ...
- MYSQL5.7生成列简介及创建
1.说明 生成列是由已存在的字段通过表达式计算得来的 2.生成列类型 VIRTUAL,即虚拟类型,字段值不实际存储,当读取行时再计算,虚拟列类型不占存储 STORED,即存储类型,字段值会实际存储起来 ...
- 如何在Win7电脑上增加新磁盘分区?
原文链接: https://www.cnblogs.com/haoxitong/p/9405497.html 我们在重装好系统Win7系统后有时会碰到需要新建磁盘分区的情况,这时我们再重装系统进行磁盘 ...
- 【Mac】微信视频对方听不见你的声音
解决方案: 1.打开系统设置 2.选择声音 3.输出选择第一个就可以
- Windows Cmd 命令管理服务
今天在Windows 干净环境上安装软件过程中,安装完成后,发现部署在IIS 上的网站无法使用,提示 "您提交的参数有误!,请重新提交" 纯净的windows 7 x64位环境, ...
- kubernetes存储之GlusterFS
目录 1.glusterfs概述 1.1.glusterfs简介 1.2.glusterfs特点 1.3.glusterfs卷的模式 2.heketi概述 3.部署heketi+glusterfs 3 ...