• Servlet 获取商品信息作业


    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>表单</title>
    </head>
    <body>
    <form action="tijiao" method="post">
    
    添加商品信息:
    <br><br>
    商品名称:
    <input type="text" id="name" name="name">
    <br><br>
    商品厂商:
    <input type="text" id="changs" name="changs">
    <br><br>
    使用寿命:
    <input type="text" id="shoum" name="shoum">
    <br><br>
    厂家地址:
    <input type="text" id="dizhi" name="dizhi">
    <br><br>
    <input type="submit" value="提交">
    
    
    
    </form>
    </body>
    </html>
    index.html
    package com.hanqi;
    
    import java.io.IOException;
    import javax.servlet.ServletConfig;
    import javax.servlet.ServletContext;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    import javax.servlet.http.HttpSession;
    
    /**
     * Servlet implementation class tijiao
     */
    public class tijiao extends HttpServlet {
        private static final long serialVersionUID = 1L;
           String str = "";
        /**
         * @see HttpServlet#HttpServlet()
         */
        public tijiao() {
            super();
            // TODO Auto-generated constructor stub
        }
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        
        public void init(ServletConfig config) throws ServletException {
            
            str = config.getInitParameter("type");
            
            
            
        }
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            
            if(str.equals("1"))
            {
                response.setCharacterEncoding("GBK");
                
                String strName =new String(request.getParameter("name").getBytes("ISO-8859-1"),"UTF-8");
                
                String strChangs =new String(request.getParameter("changs").getBytes("ISO-8859-1"),"UTF-8");
                
                String strShoum =new String(request.getParameter("shoum").getBytes("ISO-8859-1"),"UTF-8");
                
                String strDizhi =new String(request.getParameter("dizhi").getBytes("ISO-8859-1"),"UTF-8");
                
                if(strName == null || strName.trim().length() ==0)
                {
                    response.getWriter().append("商品名称不能为空");
                }
                else if(strChangs == null || strChangs.trim().length() ==0)
                {
                    response.getWriter().append("商品厂商不能为空");
                }
                else if(strShoum == null || strShoum.trim().length() ==0)
                {
                    response.getWriter().append("使用寿命不能为空");
                }
                else if(strDizhi == null || strDizhi.trim().length() ==0)
                {
                    response.getWriter().append("厂家地址不能为空");
                }
                else
                {
    
                    response.getWriter().append("商品名称:" + strName );
                    response.getWriter().append("<br>商品厂商:" +strChangs);
                    response.getWriter().append("<br>使用寿命:" +strShoum);
                    response.getWriter().append("<br>厂家地址:" +strDizhi);
                    
                }
            
            
            //response.getWriter().append("Served at: asd ").append(request.getContextPath()).append(str);
        }
        else
        {
            response.getWriter().append("Served at:123 ").append(str);
        }
        
        }
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            doGet(request, response);
        }
    
    }
    tijiao.java
  • 相关阅读:
    Algs4-2.2.1给出原地归并排序merge的排序过程
    Algs4-2.2.2给出自顶向下归并排序的排序过程
    Algs4-2.1.38不同类型的元素
    Algs4-2.1.36不均匀的数据
    Algs4-2.1.37部分有序
    Algs4-2.1.35不均匀的概率分布
    Algs4-2.1.34罕见情况
    升级python到2.7版本pip不可用
    随机验证码
    python文件操作
  • 原文地址:https://www.cnblogs.com/chenning/p/5015019.html
Copyright © 2020-2023  润新知