首页 技术 正文
技术 2022年11月8日
0 收藏 373 点赞 1,947 浏览 4943 个字

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

Struts完成用户新增操作

代码逻辑分析:

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" rel="external nofollow"
target=main>- 新增客户</A></TD>
</TR>
<TR>
<TD class=menuSmall><A class=style2 href="${pageContext.request.contextPath}/CustomerAction_list" rel="external nofollow"
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" rel="external nofollow" type=text/css rel=stylesheet>
<LINK href="${pageContext.request.contextPath }/css/Manage.css" rel="external nofollow" 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;
}}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,083
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,558
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,407
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,180
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,817
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,900