zoukankan      html  css  js  c++  java
  • servlet编写简单计算器

    1、servlet内代码

    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 jiafa extends HttpServlet {
    	private static final long serialVersionUID = 1L;
           
       
        public jiafa() {
            super();
            
        }
    
    	
    	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		response.setContentType("text/html");
    		response.setCharacterEncoding("UTF-8");
    		String num1=request.getParameter("shu1");
    		String num2=request.getParameter("shu2");
    		int a=Integer.parseInt(num1);
    		int b=Integer.parseInt(num2);
    		int sum=a+b;
    		response.getWriter().write("两个数之和:"+sum);
    		int cheng=a*b;
    		response.getWriter().write("<br>两个数之积:"+cheng);
    		int cha=a-b;
    		response.getWriter().write("<br>两个数之差:"+cha);
    	}
    
    	
    	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    		
    		doGet(request, response);
    	}
    
    }
    

     2、jsp内代码

    <%@ 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>加法运算</title>
    </head>
    <body>
    <form action="jiafa" method="post">
    请输入第一个数字:<input type="text" name="shu1"><br>
    请输入第二个数字:<input type="text" name="shu2"><br>
    <input type="submit" value="确定">
    </form>
    </body>
    </html>
    

     3、运算结果

  • 相关阅读:
    Redis 数据结构之dict
    分布式一致性算法——paxos
    分布式事务、两阶段提交协议、三阶提交协议
    MySQL主从数据同步延时分析
    MySQL数据丢失情况分析
    INSERT ... ON DUPLICATE KEY UPDATE Syntax
    分布式系统的数据一致性
    分布式系统的BASE理论
    分布式系统的CAP理论
    性能指标体系构建
  • 原文地址:https://www.cnblogs.com/jakeasd/p/5634255.html
Copyright © 2011-2022 走看看