zoukankan      html  css  js  c++  java
  • 编写servlet,输出商品信息

    1、输入商品信息

    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>Insert title here</title>
    </head>
    <body>
    <form action="Shangpinxinxi" method="post">
    <table>
    <tr align="center"><td>商品信息</td></tr>
    <tr><td>商品名称:<input type="text" name="ming"></td></tr>
    <tr><td>保质日期:<input type="text" name="yue"></td></tr>
    <tr><td>生产日期:<input type="text" name="date"></td></tr>
    <tr><td>出售价格:<input type="text" name="price"></td></tr>
    <tr algin="center"><td><input type="submit" value="提交信息"></td></tr>
    </table>
    </form>
    </body>
    </html>
    

     2、输出商品信息

    package lianxi;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    public class Shangpinxinxi extends HttpServlet {
    	private static final long serialVersionUID = 1L;
       
        public Shangpinxinxi() {
            super();
            
        }
    
    	
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html");
    		response.setCharacterEncoding("UTF-8");
    		String nm=request.getParameter("ming");
    		String bz=request.getParameter("yue");		
    		String p=request.getParameter("price");
    		String sc=request.getParameter("date");
    		if(nm!=""&&bz!=""&&sc!=""&&p!="")
    		{
    			response.getWriter().write("商品:"+nm+"<br>保质期:"+bz+"<br>生产日期:"+sc+"<br>价格:"+p);
    		}
    		else
    		{
    			response.getWriter().write("请输入完整地信息!<br>");
    			//3秒后,跳转到输入页面...........
    			response.setHeader("refresh", "3;URL=shangpin.jsp");
    			
    		}
    		
    		//response.getWriter().append("Served at: ").append(request.getContextPath());
    	}
    
    	
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
    		doGet(request, response);
    	}
    
    }
    

     3、运行结果

  • 相关阅读:
    书列君荐书|《福尔摩斯探案大全集》.(英)阿瑟.柯南道尔.扫描版
    anaconda同时集成Python2 和 Python3
    python 使用sqlite,ConfigParser实例
    python 爬虫爬取历年双色球开奖信息
    关于python 爬虫遇到的反盗链
    CentOS7搭建Docker私有仓库----Docker
    Ansible + shell 实现部署fastdfs+nginx 实现图片服务器并提供动态缩放功能;
    python+fastdfs+nginx实现打包下载功能
    监控生产服务器内存使用前十
    python操作MySQL--实例
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5633230.html
Copyright © 2011-2022 走看看