======================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的更多相关文章

  1. SSH框架整合

    SSH框架整合 一.原理图 action:(struts2) 1.获取表单的数据 2.表单的验证,例如非空验证,email验证等 3.调用service,并把数据传递给service Service: ...

  2. dwr与ssh框架整合教程

    (1)dwr与ssh框架整合教程dwr框架介绍. DWR(Direct Web Remoting)是一个用于改善web页面与Java类交互的远程服务器端Ajax开源框架,可以帮助开 发人员开发包含AJ ...

  3. ssh框架整合之登录以及增删改查

    1.首先阐述一下我用得开发工具,myeclipse2017+oracle,所以我的基本配置步骤可能不一样,下面我用几张图来详解我的开发步骤. ---1先配置structs (Target 选择apac ...

  4. Spring+Hibernate+Struts(SSH)框架整合

    SSH框架整合 前言:有人说,现在还是流行主流框架,SSM都出来很久了,更不要说SSH.我不以为然.现在许多公司所用的老项目还是ssh,如果改成流行框架,需要成本.比如金融IT这一块,数据库dao层还 ...

  5. J2EE进阶(十)SSH框架整合常见问题汇总(一)

    SSH框架整合常见问题汇总(一) 前言 以下所列问题具有针对性,但是遇到同类型问题时均可按照此思路进行解决. HTTP Status 404 - No result defined for actio ...

  6. 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 ...

  7. SSH框架整合的其它方式

    --------------------siwuxie095 SSH 框架整合的其它方式 1.主要是整合 Spring 框架和 Hibernate 框架时,可以不写 Hibernate 核心配置文件: ...

  8. SSH框架整合过程总结

    ---------------------siwuxie095                                 SSH 框架整合过程总结         (一)导入相关 jar 包(共 ...

  9. SSH框架整合思想

    --------------------siwuxie095                                 SSH 框架整合思想         1.SSH 框架,即 Struts2 ...

  10. SSH框架整合jar包时的注意事项

    SSH框架整合jar包时的注意事项: 在将三个框架所需的jar整合到一起后,要看一下有没有相同类型但是版本不同的jar包,如果有的话,需要把低版本的jar包删除掉,否则会报错.我这里整合的时候java ...

随机推荐

  1. Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现

    Python进阶----计算机基础知识(操作系统多道技术),进程概念, 并发概念,并行概念,多进程实现 一丶进程基础知识 什么是程序: ​   程序就是一堆文件 什么是进程: ​   进程就是一个正在 ...

  2. 【开发笔记】- QQ消息轰炸

    1.右键新建一个文本文件: 2.打开记事本将如下代码复制过去: On Error Resume Next Dim wsh,ye set wsh=createobject("wscript.s ...

  3. python3中try异常调试 raise 异常抛出

    一.什么是异常? 异常即是一个事件,该事件会在程序执行过程中发生,影响了程序的正常执行. 一般情况下,在Python无法正常处理程序时就会发生一个异常. 异常是Python对象,表示一个错误. 当Py ...

  4. java static变量及函数

    java以类为基础,没有游离在类之外单独存在的变量.所以,c++中的全局变量,在java中应该是不存在的.java中有的是成员变量和成员方法.当成员前以static修饰时,即为静态成员变量或静态成员方 ...

  5. springdata jpa 关于分页@Query问题

    关于springdata jpa 分页问题相信很多小伙伴都遇到过,只要表中数量到达分页条件就会报错 废话少说直接上代码: @Query(nativeQuery = true, value = &quo ...

  6. windows下用纯C实现一个简陋的imshow:基于GDI

    intro 先前实现了GDI显示图像时设定窗口大小为图像大小,不过并没有刻意封装函数调用接口,并不适合给其他函数调用.现在简单封装一下,特点: 纯C 基于GDI,因此只支持windows平台 类似于o ...

  7. 线性回归-API

    线性回归的定义 利用回归方程(函数)对一个或多个自变量(特征值)和因变量(目标值)之间关系进行建模的一种分析方式 线性回归的分类 线性关系 非线性关系 损失函数 最小二乘法 线性回归优化方法 正规方程 ...

  8. 【转】高性能网络编程6--reactor反应堆与定时器管理

    反应堆开发模型被绝大多数高性能服务器所选择,上一篇所介绍的IO多路复用是它的实现基础.定时触发功能通常是服务器必备组件,反应堆模型往往还不得不将定时器的管理囊括在内.本篇将介绍反应堆模型的特点和用法. ...

  9. meibu ddns update command

    http://main.meibu.com/ip/login.asp?name=[USERNAME]&pwd=[PASSWORD]

  10. 剖析和解决Python中网络粘包的正确姿势

    目录 1.粘包及其成因 1.1.粘包产生 1.2.粘包产生的原因 2.尝试解决粘包 2.1.指定数据包的长度 2.2.固定数据包的长度 2.3.用函数实现多次调用发送数据 3.解决粘包问题的正确姿势 ...