zoukankan      html  css  js  c++  java
  • 关系管理系统:Web层controller控制页面Servlet AddCustomerServlet

    package cn.itcast.web.controller;
    
    import java.io.IOException;
    
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import cn.itcast.domain.Customer;
    import cn.itcast.serivce.BusinessServiceInterface;
    import cn.itcast.service.impl.BusinessService;
    import cn.itcast.utils.WebUtils;
    
    public class AddCustomerServlet extends HttpServlet {
    
        public void doGet(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            request.setCharacterEncoding("UTF-8");
            
            try{
                Customer c = WebUtils.request2Bean(request, Customer.class);
                c.setId(WebUtils.makeId());
                BusinessServiceInterface serivce = new BusinessService();
                serivce.addCustomer(c);
                request.setAttribute("message", "客户添加成功!!");
            }catch (Exception e) {
                e.printStackTrace();
                request.setAttribute("message", "客户添加失败!!");
            }
            
            request.getRequestDispatcher("/message.jsp").forward(request, response);
            
        }
    
        public void doPost(HttpServletRequest request, HttpServletResponse response)
                throws ServletException, IOException {
    
            doGet(request, response);
        }
    
    }
  • 相关阅读:
    使用ForEach循环控制器对返回参数进行多次调用
    html基础
    Eclipse使用github并开启命令行
    vim
    使用Jsoup爬取网站图片
    YUM
    javaagent项目中使用
    Linux基础三---打包压缩&vim&系统的初始化和服务
    linux 基础二---用户群租权限
    Linux 基础一---操作系统&常用命令
  • 原文地址:https://www.cnblogs.com/lichone2010/p/3175896.html
Copyright © 2011-2022 走看看