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

代码逻辑分析:

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>当前位置:客户管理 &gt; 添加客户</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;
} }

最新文章

  1. POJ 1979 Red and Black
  2. windows核心编程 - 线程同步机制
  3. DirectX12 Samples 学习笔记 – PredicationQueries
  4. 安装和部署ZkeaCMS
  5. [转]Caffe在Linux下的安装,编译,实验
  6. JS 中对象的简单创建和继承
  7. codeforces 258C Little Elephant and LCM 组合数学 枚举
  8. js函数:setInterval()/clearInterval()——js网页计时器
  9. iOS7 兼容及部分细节
  10. solr源码导入eclipse
  11. 解决英文版Windows程序乱码
  12. 【Chromium中文文档】Chromium如何展示网页
  13. 011.Adding Search to an ASP.NET Core MVC app --【给程序添加搜索功能】
  14. 主席树套树状数组——带修区间第k大zoj2112
  15. Linux命令收集
  16. __x__(42)0910第六天__表格布局 老旧的布局方法
  17. thinkphp通用控制器
  18. centos更换yum源为aliyun源
  19. 糟糕的@@identity,SCOPE_IDENTITY ,IDENT_CURRENT
  20. 【黑金原创教程】【FPGA那些事儿-驱动篇I 】实验十七:IIC储存模块 - FIFO读写

热门文章

  1. pybind11在Windows下的使用
  2. Solr 18 - 通过SolrJ局部更新Solr中的文档 (原子操作、非覆盖操作)
  3. 渐进式web应用开发---service worker (二)
  4. springboot集成mockito与powermock
  5. 执行某个文件夹下面的所有.py文件
  6. 孰能巧用 Spring Cloud 服务注册中心Eureka
  7. 对比 C++ 和 Python,谈谈指针与引用
  8. Oracle数据库---游标
  9. Linux命令学习-tail命令
  10. 使用Gitlab-CI 实现NetCore项目Docker化并部署到阿里云K8S