Struts完成用户新增操作
点击新增客户出现该页面并完成前后台交互

代码逻辑分析:

jsp 页面部分代码
<TABLE id=table_1 style="DISPLAY: none" cellSpacing=0
cellPadding=2 width=155 align=center border=0>
<TBODY>
<TR>
<TD class=menuSmall><A class=style2 href="${pageContext.request.contextPath}/CustomerAction_saveUI"
target=main>- 新增客户</A></TD>
</TR>
<TR>
<TD class=menuSmall><A class=style2 href="${pageContext.request.contextPath}/CustomerAction_list"
target=main>- 客户列表</A></TD>
</TR> </TBODY>
</TABLE>
Struts.xml
<package name="crm" namespace="/" extends="struts-default" >
<action name="CustomerAction_*" class="com.huan.web.action.CustomerAction" method="{1}" >
<result name="list" >/jsp/customer/list.jsp</result>
<result name="saveUI">/jsp/customer/add.jsp</result>
<!-- 保存成功后,查询全部客户列表信息 这里返回的是Action类,但这里应该是重定向到页面中 -->
<result name="saveSuccess" type="redirect">CustomerAction_list.action</result>
</action>
</package>
add.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<TITLE>添加客户</TITLE>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<LINK href="${pageContext.request.contextPath }/css/Style.css" type=text/css rel=stylesheet>
<LINK href="${pageContext.request.contextPath }/css/Manage.css" type=text/css
rel=stylesheet> <META content="MSHTML 6.00.2900.3492" name=GENERATOR>
</HEAD>
<BODY>
<FORM id=form1 name=form1
action="${pageContext.request.contextPath }/CustomerAction_add"
method=post> <TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_019.jpg"
border=0></TD>
<TD width="100%" background="${pageContext.request.contextPath }/images/new_020.jpg"
height=20></TD>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_021.jpg"
border=0></TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15 background=${pageContext.request.contextPath }/images/new_022.jpg><IMG
src="${pageContext.request.contextPath }/images/new_022.jpg" border=0></TD>
<TD vAlign=top width="100%" bgColor=#ffffff>
<TABLE cellSpacing=0 cellPadding=5 width="100%" border=0>
<TR>
<TD class=manageHead>当前位置:客户管理 > 添加客户</TD>
</TR>
<TR>
<TD height=2></TD>
</TR>
</TABLE> <TABLE cellSpacing=0 cellPadding=5 border=0> <TR>
<td>客户名称:</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_name">
</td>
<td>客户级别 :</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_level">
</td>
</TR> <TR> <td>信息来源 :</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_source">
</td>
<td>联系人:</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_linkman">
</td>
</TR> <TR> <td>固定电话 :</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_phone">
</td>
<td>移动电话 :</td>
<td>
<INPUT class=textbox id=sChannel2
style="WIDTH: 180px" maxLength=50 name="cust_mobile">
</td>
</TR> <tr>
<td rowspan=2>
<INPUT class=button id=sButton2 type=submit
value=" 保存 " name=sButton2>
</td>
</tr>
</TABLE> </TD>
<TD width=15 background="${pageContext.request.contextPath }/images/new_023.jpg">
<IMG src="${pageContext.request.contextPath }/images/new_023.jpg" border=0></TD>
</TR>
</TBODY>
</TABLE>
<TABLE cellSpacing=0 cellPadding=0 width="98%" border=0>
<TBODY>
<TR>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_024.jpg"
border=0></TD>
<TD align=middle width="100%"
background="${pageContext.request.contextPath }/images/new_025.jpg" height=15></TD>
<TD width=15><IMG src="${pageContext.request.contextPath }/images/new_026.jpg"
border=0></TD>
</TR>
</TBODY>
</TABLE>
</FORM>
</BODY>
</HTML>
Action 类
package com.huan.web.action; import java.util.List; import org.apache.commons.lang3.StringUtils;
import org.apache.struts2.ServletActionContext;
import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.Restrictions; import com.huan.domain.Customer;
import com.huan.service.CustomerService;
import com.huan.service.impl.CustomerServiceImpl;
import com.opensymphony.xwork2.ActionSupport;
import com.opensymphony.xwork2.ModelDriven; public class CustomerAction extends ActionSupport implements ModelDriven<Customer>{ private CustomerService cs = new CustomerServiceImpl();
private Customer customer=new Customer(); public String list() throws Exception {
//1 接受参数
String cust_name = ServletActionContext.getRequest().getParameter("cust_name");
//2 创建离线查询对象
DetachedCriteria dc =DetachedCriteria.forClass(Customer.class);
//3 判断参数拼装条件
//StringUtils.isNotBlank 静态方法 判断
//当cust_name 不为null 不为 ""(空字符串) ,不为空格时 返回true
if(StringUtils.isNotBlank(cust_name)){
dc.add(Restrictions.like("cust_name", "%"+cust_name+"%"));
}
//4 调用Service将离线对象传递
List<Customer> list = cs.getAll(dc);
//5 将返回的list放入request域.转发到list.jsp显示
//引用ServletActionContext类的静态方法getRequest
//getRequest返回HttpServletRequest对象
ServletActionContext.getRequest().setAttribute("list", list); return "list";
}
public String saveUI(){ return "saveUI";
} public String add(){
cs.save(customer); return "saveSuccess";
} @Override
public Customer getModel() { return customer;
} }
Struts完成用户新增操作的更多相关文章
- 【php增删改查实例】第十六节 - 用户新增
6.1工具栏 <div id="toolbar"> <a href="javascript:openDialog()" class=" ...
- 【Java框架型项目从入门到装逼】第十三节 用户新增功能完结篇
这一节,我们把用户新增的功能继续做一个完善.首先,新增成功后,需要给前台返回一个信息,就是告诉浏览器,这次用户新增的操作到底是成功了呢,还是失败了呢?为此,我们需要专门引入一个结果类,里面只有两个属性 ...
- [原创]java WEB学习笔记25:MVC案例完整实践(part 6)---新增操作的设计与实现
本博客为原创:综合 尚硅谷(http://www.atguigu.com)的系统教程(深表感谢)和 网络上的现有资源(博客,文档,图书等),资源的出处我会标明 本博客的目的:①总结自己的学习过程,相当 ...
- Restful风格API中用put还是post做新增操作有什么区别?
Restful风格API中用put还是post做新增操作有什么区别? 转 头条面试归来,有些话想和Java开发者说!>>> 这个是华为面试官问我的问题,回来我找了很多资料,想验证这个 ...
- T-Sql(七)用户权限操作(grant)
一般数据库的权限操作我们很少用,除非一些大型的项目,需要给数据库配置不同的用户及权限,防患于未然,今天我们就来了解下t-sql中配置用户权限操作. 先看示例代码: --创建登录名 create log ...
- Gremlins.js – 模拟用户随机操作的 JS 测试库
Gremlins.js 是基于 JavaScript 编写的 Monkey 测试库,支持 Node.js 平台和浏览器中使用.Gremlins.js 随机模拟用户操作:单击窗口中的任意位置,在表格中输 ...
- 防止用户误操作退出APP的处理
/** * 软件退出的处理:先跳到第一个页面,再点提示“再点一次退出”,2秒内再点一次退出 * 防止用户误操作 */ private boolean isExist=false; private Ha ...
- 记录linux系统下所有用户的操作信息
在日常运维中,我们需要清楚服务器上每个用户登录后都做了哪些操作,我们需要记录下每个用户的操作命令.下面的内容设置可以实现在Linux下所有用户,不管是远程还是本地登陆,在本机的所有操作都会记录下来,并 ...
- 【 Jquery插件】引导用户如何操作网站功能的向导
Joyride是一个jQuery插件,可以利用它来创建一个引导用户如何操作网站功能的向导.通过定义一个操作步骤顺序,这个插件会在需要操作的HTML元素旁边显示一个帮助说明的Tooltips. http ...
随机推荐
- SpringBoot项目多数据源配置
博主总结的不错,事务也考虑到了,存一下: https://blog.csdn.net/xqnode/article/details/86498507
- 【设计模式】【最后一个】结构型07适配器模式(Adapter Pattern)
适配器模式(Adapter Pattern) 推荐一个很全面的博客:https://blog.csdn.net/zxt0601/article/details/52848004 定义:将一个类的接口转 ...
- SpringBoot 缓存注解 与EhCache的使用
在SpringBoot工程中配置EhCache缓存 1.在src/main/resources下新建ehcache.xml文件 eternal=true //缓存永久有效,false相反 maxEle ...
- Programming In Lua 第四章
1, 2, 3, 4, 5, 6, 7,
- Nginx添加Lua扩展模块
Nginx添加Lua扩展模块 编译安装LuaJIT wget http://luajit.org/download/LuaJIT-2.0.4.tar.gz tar xf LuaJIT-.tar.gz ...
- NMI watchdog: BUG: soft lockup - CPU#0 stuck for 22s!
今天测试环境一虚拟机运行中突然报错,,, 没见过的内核报错,于是google一番. 系统日志: Nov :: dev- kernel: NMI watchdog: BUG: soft lockup - ...
- 用kubeadm创建高可用kubernetes集群后,如何重新添加控制平面
集群信息 集群版本:1.13.1 3个控制平面,2个worker节点 k8s-001:10.0.3.4 k8s-002:10.0.3.5 k8s-003:10.0.3.6 k8s-004:10.0.3 ...
- .net core2学习笔记
在Linux上安装完netcore的sdk后,发现每次重新登录dotnet命令都会失效,咨询完同事后才知道之前的设置只是临时变量,需要vim /etc/profile 编辑这个文件,把环境变量写入 ...
- WPF 入门笔记之布局
一.布局原则: 1. 不应显示的设定元素的尺寸,反而元素可以改变它的尺寸,并适应它们的内容 2. 不应使用平布的坐标,指定元素的位置. 3. 布局容器和它的子元素是共享可以使用的空间 4. 可以嵌套的 ...
- .Net Core 学习新建Core MVC 项目
一.新建空的Core web项目 二.在Startup文件中添加如下配置 1. 在ConfigureServices 方法中添加 services.AddMvc();MVC服务 2. app.Use ...