CalculationServlet.java:

package com.you.servlet;

import java.io.IOException;
import java.io.PrintWriter; import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; import com.you.model.Calculator; /**
*
* 类功能说明
* 类改动者 改动日期
* 改动说明
* <p>Title:CalculationServlet.java</p>
* <p>Description:游海东个人开发</p>
* <p>Copyright:Copyright(c)2013</p>
* @author:游海东
* @date:2014-6-15 下午10:52:42
* @version V1.0
*/
public class CalculationServlet extends HttpServlet
{
/**
* @Fields serialVersionUID:序列化
*/
private static final long serialVersionUID = 1L; /**
* Constructor of the object.
*/
public CalculationServlet()
{
super();
} /**
* The doGet method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to get.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
this.doPost(request, response);
} /**
* The doPost method of the servlet. <br>
*
* This method is called when a form has its tag value method equals to post.
*
* @param request the request send by the client to the server
* @param response the response send by the server to the client
* @throws ServletException if an error occurred
* @throws IOException if an error occurred
*/
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException
{
response.setContentType("text/html");
PrintWriter out = response.getWriter();
//操作数一
String operandOne=request.getParameter("operandOne");
//操作数二
String operandTwo=request.getParameter("setOperandTwo");
//运算符
String operator=request.getParameter("operator");
//计算结果
double calResult=0; Calculator cal=new Calculator();
//将字符串转换成double
cal.setOperandOne(Double.parseDouble(operandOne));
cal.setOperandTwo(Double.parseDouble(operandTwo)); //加法
if(operator.equals("+"))
{
calResult=cal.addition();
}
//减法
else if(operator.equals("-"))
{
calResult=cal.subtraction();
}
//乘法
else if(operator.equals("*"))
{
calResult=cal.multiplication();
}
//除法
else if(operator.equals("/"))
{
calResult=cal.division();
}
request.setAttribute("calResult", calResult);
request.getRequestDispatcher("/resultServlet").forward(request, response);
out.print(calResult);
} /**
* Destruction of the servlet. <br>
*/
public void destroy()
{
super.destroy();
} /**
* Initialization of the servlet. <br>
*
* @throws ServletException if an error occurs
*/
public void init() throws ServletException
{ } }

制作简易计算器处理过程Servlet的更多相关文章

  1. 制作简易计算器处理结果Servlet

    ResultServlet.java: package com.you.servlet; import java.io.IOException; import java.io.PrintWriter; ...

  2. Vue 制作简易计算器

    <!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...

  3. 用js制作简易计算器及猜随机数字游戏

    <!doctype html><html><head> <meta charset="utf-8"> <title>JS ...

  4. 大一C语言学习笔记(10)---编程篇--制作简易计算器,支持加,减,乘,除,取余运算,要求 0 bug

    博主自开学初就一直在努力为自己的未来寻找学习方向,学习编程嘛,尽量还是要抱大腿的,所以我就加入了我们学校的智能设备研究所,别的不说,那的学长们看起来是真的很靠谱,学长们的学习氛围也超级浓厚,所以我就打 ...

  5. 利用Unity3D制作简易2D计算器

    利用Unity3D制作简易2D计算器 标签(空格分隔): uiniy3D 1. 操作流程 在unity3DD中创建一个新项目 注意选择是2D的(因为默认3D) 在Assets框右键新建C#脚本 在新建 ...

  6. 制作一个简易计算器——基于Android Studio实现

    一个计算器Android程序的源码部分分为主干和细节两部分. 一.主干 1. 主干的构成 计算器的布局 事件(即计算器上的按钮.文本框)监听 实现计算 2. 详细解释 假设我们的项目名为Calcula ...

  7. 菜鸟学习Struts——简易计算器

    这是学习Struts的一个简单的例子文件结构如下: 1.配置Struts环境 2.新建input.jsp,success.jsp,error.jsp input.jsp代码如下: <%@ pag ...

  8. Python之实现一个简易计算器

    自己动手写计算器 一.功能分析 用户输入一个类似这样 3*( 4+ 50 )-(( 100 + 40 )*5/2- 3*2* 2/4+9)*((( 3 + 4)-4)-4) 这样的表达式,假设表达式里 ...

  9. C#制作简易屏保(转)

    C#制作简易屏保[原创] 原始网址: http://www.cnblogs.com/drizzlecrj/archive/2006/10/06/522182.html 2006-10-06 16:25 ...

随机推荐

  1. POJ 2778 AC自己主动机+矩阵幂 不错的题

    http://poj.org/problem?id=2778 有空再又一次做下,对状态图的理解非常重要 题解: http://blog.csdn.net/morgan_xww/article/deta ...

  2. C语言复合字面量的使用

    C99添加的特性,复合字面量(composite literal).一旦熟悉并使用,便会体会到简洁强大的表达. 所谓字面量就是固定数值的表示.数值和字符串类型都有字面量的表达.如: // 100, 1 ...

  3. UDP vs. TCP

    UDP vs. TCP 原文:UDP vs. TCP,作者是Glenn Fiedler,专注于游戏网络编程相关工作多年. 说在最前面的话 翻译这篇文章的初衷:我在工作中根本接触不到网络游戏编程,但是我 ...

  4. graph driver-device mapper-02driver基本操作

    // 清除thin pool 1.1 func (d *Driver) Cleanup() error { // 停止thin pool err := d.DeviceSet.Shutdown() r ...

  5. appium简明教程

    appium简明教程 什么是appium? 下面这段介绍来自于appium的官网. Appium is an open-source tool you can use to automate mobi ...

  6. poj3974(manacher)

    传送门:Palindrome 题意:给定一个字符串,求最长回文子串. 分析:manach裸题,核心理解mx>i?p[i]=min(p[2*id-i],mx-i):1. #pragma comme ...

  7. [WPF]使用Pack URI路径訪问二进制资源

    一.路径格式定义 完整的URI定义为: pack://application,,,[/可选程序集名称;][可选版本;][目录名称/]文件名 缩略后的写法是: [目录名称/]文件名 二.在XAML代码中 ...

  8. 用XAML做网页!!—开篇

    原文:用XAML做网页!!-开篇 这几日一直没发表新文章,一来是因为事比较多,二来就是我在研究使用XAML挑战传统HTML来做网页,这很可能是在全球的首次尝试,至少我从未找到任何可供参考的相关资料. ...

  9. 去掉windows文件末尾的^M: %s/\r//g

    去掉windows文件末尾的^M: %s/\r//g

  10. Oracle本地管理对照数据字典管理表空间

    Locally vs. Dictionary Managed Tablespaces 整理自:http://www.orafaq.com/node/3. When Oracleallocates sp ...