一、项目结构

二、新建UserAction,继承自ActionSupport,并实现ModelDriven<User>接口;getModel方法是用来装配对象属性的;注意,userService字段名要和applicationContext.xml中配置的userservice bean中id名称一致

package com.hjp.action;

import com.hjp.domain.User;
import com.hjp.service.UserService;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven; /**
* Created by JiaPeng on 2015/12/13.
*/
public class UserAction extends ActionSupport implements ModelDriven<User> { User user = new User(); @Override
public User getModel() {
return user;
} private UserService userService; public void setUserService(UserService userService) {
this.userService = userService;
} public String register(){
userService.register(user);
return SUCCESS;
}
}

UserAction

三、新建index.jsp文件,代码如下

<%--
Created by IntelliJ IDEA.
User: JiaPeng
Date: 2015/12/13
Time: 11:36
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
<form method="post" action="${pageContext.request.contextPath}/userAction_register">
用户名:<input type="text" name="username"/><br/>
密码:<input type="password" name="password"/><br/>
年龄:<input type="text" name="age"/><br/>
<input type="submit" value="注册"/>
</form>
</body>
</html>

index.jsp

四、新建struts.xml文件,及message.jsp文件

<?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>
<!--包-->
<package name="hello" namespace="/" extends="struts-default">
<action name="userAction_*" class="com.hjp.action.UserAction" method="{1}">
<result name="success">/message.jsp</result>
</action>
</package> </struts>

struts.xml

<%--
Created by IntelliJ IDEA.
User: JiaPeng
Date: 2015/12/13
Time: 16:23
To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
<title></title>
</head>
<body>
成功!
</body>
</html>

message.jsp

五、配置web.xml文件,主要是配置spring和struts

<?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_3_1.xsd"
version="3.1">
<!--spring-->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath:applicationContext.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>

web.xml

SSH整合之spring整合struts2(续上)的更多相关文章

  1. Maven环境下搭建SSH框架之Spring整合Hibernate

    © 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Spring:4.3.8.RELEASE Hibernate:5.1.7.Final MySQL:5.7.17 注意:其他版本在某些特性 ...

  2. 【Saas-export项目】--项目整合(spring整合MVC)

    转: [Saas-export项目]--项目整合(spring整合MVC) 文章目录 Spring整合SpringMVC(export_web_manager子工程) (1)log4j.propert ...

  3. Maven环境下搭建SSH框架之Spring整合Struts2

    © 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Struts2:2.5.10 Spring:4.3.8.RELEASE 注意:其他版本在某些特性的使用上可能稍微存在差别 2.准备工作 ...

  4. 一 SSH整合:Spring整合Struts2的两种方式,struts.xml管理Action&Bean管理Action

    SSH回顾 1 引入jar包 Struts2的jar包 D:\Struts2\struts-2.3.35\apps\struts2-blank\WEB-INF\lib  开发基本包 Struts2有一 ...

  5. SSH整合之spring整合hibernate

    SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...

  6. 二 SSH整合:Spring整合Hibernate,无障碍整合&无核心配置整合,Hibernate模版常用方法,

    重建SSH项目 java项目可以直接复制,但是web项目除了改名字还要该配置,如下: 方式一:无障碍整合:带Hibernate配置文件 <?xml version="1.0" ...

  7. ssh框架中spring整合hibernate的配置文件模板(带详细注释)

    applicationContext.xml的配置文件模板 <?xml version="1.0" encoding="UTF-8"?> <b ...

  8. 阶段3 3.SpringMVC·_07.SSM整合案例_08.ssm整合之Spring整合MyBatis框架

    service能供成功的调用到service对象就算是整合成功 如果能把生成的代理对象也存大IOC的容器中.那么ServiceImpl就可以拿到这个对象 做一个注入,然后就可以调用代理对象的查询数据库 ...

  9. 阶段3 3.SpringMVC·_07.SSM整合案例_09.ssm整合之Spring整合MyBatis框架配置事务

    spring加入声明式的事物 配置事物 配置事物管理器 需要一个dataSource,引入上面的dataSource 配置事务通知 引入上面的transactionManager事物管理器 find开 ...

随机推荐

  1. FusionCharts参数的详细说明和功能特性(转)

    功能特性animation                    是否动画显示数据,默认为1(True)showNames                    是否显示横向坐标轴(x轴)标签名称ro ...

  2. win server 2008配置ftp无法登陆问题的解决办法

    解决办法放在最前面,方便急需答案的同学: 创建了ftp使用的windows账户后,一定要给该账户添加ftp目录的权限,如下图所示,为新账户添加权限后(且设置了“ftp身份验证”),即可正常访问ftp: ...

  3. C语言 百炼成钢13

    //题目37:将一个数组逆序输出.用第一个与最后一个交换. #include<stdio.h> #include<stdlib.h> #include<math.h> ...

  4. easyui-combobox的取值问题

    例子:<select id="cc" class="easyui-combobox" name="cc" style="wi ...

  5. Java系列:JVM指令详解(上)(zz)

    一.未归类系列A 此系列暂未归类. 指令码    助记符                            说明    59:iastore    60:lload 6       //因为str ...

  6. Java 环境下使用 AES 加密的特殊问题处理

    在 Java 环境下使用 AES 加密,在密钥长度和字节填充方面有一些比较特殊的处理. 1. 密钥长度问题 默认 Java 中仅支持 128 位密钥,当使用 256 位密钥的时候,会报告密钥长度错误 ...

  7. Redis入门学习(一)——安装配置

    最近马上要找实习了,听学长说他们公司里用了redis来解决缓存问题,在大三结束前来学习一下. 问:Redis是什么? 答:(官方)REmote DIctionary Server(Redis)是一个K ...

  8. 『设计』Slithice 分布式架构设计-支持一体式开发,分布式发布

    项目原因: 参与过各种 分布式项目,有 Socket,Remoting,WCF,当然还有最常用的可以跨平台的 WebService. 分布式编码的时间浪费: 但是,无一例外的,开发分布式程序的开发遵循 ...

  9. c#取得控制台应用程序根目录

    1.取得控制台应用程序的根目录方法 方法1.Environment.CurrentDirectory 取得或设置当前工作目录的完整限定路径方法2.AppDomain.CurrentDomain.Bas ...

  10. jqurey 遍历 div内的所有input单选复选按钮并判断是否选中及Attr(checked)无效的解决

    关于页面前面标签 <ul> @{ foreach (var item in vote) { if (!string.IsNullOrEmpty(item.Img)) { <li cl ...