SSH整合之spring整合struts2(续上)
一、项目结构

二、新建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(续上)的更多相关文章
- Maven环境下搭建SSH框架之Spring整合Hibernate
© 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Spring:4.3.8.RELEASE Hibernate:5.1.7.Final MySQL:5.7.17 注意:其他版本在某些特性 ...
- 【Saas-export项目】--项目整合(spring整合MVC)
转: [Saas-export项目]--项目整合(spring整合MVC) 文章目录 Spring整合SpringMVC(export_web_manager子工程) (1)log4j.propert ...
- Maven环境下搭建SSH框架之Spring整合Struts2
© 版权声明:本文为博主原创文章,转载请注明出处 1.搭建环境 Struts2:2.5.10 Spring:4.3.8.RELEASE 注意:其他版本在某些特性的使用上可能稍微存在差别 2.准备工作 ...
- 一 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有一 ...
- SSH整合之spring整合hibernate
SSH整合要导入的jar包: MySQL中创建数据库 create database ssh_db; ssh_db 一.spring整合hibernate带有配置文件hibernate.cfg.xml ...
- 二 SSH整合:Spring整合Hibernate,无障碍整合&无核心配置整合,Hibernate模版常用方法,
重建SSH项目 java项目可以直接复制,但是web项目除了改名字还要该配置,如下: 方式一:无障碍整合:带Hibernate配置文件 <?xml version="1.0" ...
- ssh框架中spring整合hibernate的配置文件模板(带详细注释)
applicationContext.xml的配置文件模板 <?xml version="1.0" encoding="UTF-8"?> <b ...
- 阶段3 3.SpringMVC·_07.SSM整合案例_08.ssm整合之Spring整合MyBatis框架
service能供成功的调用到service对象就算是整合成功 如果能把生成的代理对象也存大IOC的容器中.那么ServiceImpl就可以拿到这个对象 做一个注入,然后就可以调用代理对象的查询数据库 ...
- 阶段3 3.SpringMVC·_07.SSM整合案例_09.ssm整合之Spring整合MyBatis框架配置事务
spring加入声明式的事物 配置事物 配置事物管理器 需要一个dataSource,引入上面的dataSource 配置事务通知 引入上面的transactionManager事物管理器 find开 ...
随机推荐
- 第五章 使用 Bootstrap Typeahead 组件(百度下拉效果)
推荐链接:http://www.cnblogs.com/haogj/p/3376874.html UnderScore官网:http://underscorejs.org/ 参考文档:http://w ...
- [tools]google神器浏览器下载
google神器下载 这是一款优化了的google浏览器 http://www.ccav1.me/chromegae.html
- C语言 内存四大存储区域
#include<stdio.h> #include<stdlib.h> //程序代码指令,define定义的常量---代码区(只读) //全局(关键)变量/常量,静态(关键) ...
- 使用地址栏访问CXF Webservice写法
/* * 通过url调用 * http://localhost:8080/EFP/webService/TestWebservice/testOut/arg0/liuyx */ http://loca ...
- no.1
#import requests import urllib import bs4 try: html=urllib.urlopen('http://anyun.org') except HTTPer ...
- Linux常用指令---快捷键
Linux下快捷键使用 Ctrl + a 切换到命令行开始 这个操作跟Home实现的结果一样的,但Home在某些unix环境下无法使用,便可以使用这个组合:在Linux下的vim,这个也是有效的:另外 ...
- initializer for conditional binding must have optional type not AVAudioPlayer
if let buttonBeep = self.setupAudioPlayerWithFile("ButtonTap", type: "wav") { ...
- 上位机用USB做虚拟串口,总算抓到一个纯代码的总结了,没有坑的完美解决。
用libUSB来实现自己的驱动+下位机理论速度.=1M字节每秒. 达到极限速度 WINDOWS已经自带虚拟串口驱动,只不过还需要一个Inf文件 方法1:直接下载一个串口inf,来修改文件. 方 ...
- nginx自学
需要了解的linux的命令: linux的命令:netstat -antnetstat -antp(天假了参数P)ps aux | grep 80kill -9 2985 号进程pkill -9 ht ...
- [BZOJ 2186][Sdoi2008]沙拉公主的困惑(欧拉函数)
题目:http://www.lydsy.com:808/JudgeOnline/problem.php?id=2186 分析: 就是要求1~n!中与m!互质的数的个数 首先m!以内的就是φ(m!) 关 ...