制作简易计算器处理过程Servlet
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的更多相关文章
- 制作简易计算器处理结果Servlet
ResultServlet.java: package com.you.servlet; import java.io.IOException; import java.io.PrintWriter; ...
- Vue 制作简易计算器
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title> ...
- 用js制作简易计算器及猜随机数字游戏
<!doctype html><html><head> <meta charset="utf-8"> <title>JS ...
- 大一C语言学习笔记(10)---编程篇--制作简易计算器,支持加,减,乘,除,取余运算,要求 0 bug
博主自开学初就一直在努力为自己的未来寻找学习方向,学习编程嘛,尽量还是要抱大腿的,所以我就加入了我们学校的智能设备研究所,别的不说,那的学长们看起来是真的很靠谱,学长们的学习氛围也超级浓厚,所以我就打 ...
- 利用Unity3D制作简易2D计算器
利用Unity3D制作简易2D计算器 标签(空格分隔): uiniy3D 1. 操作流程 在unity3DD中创建一个新项目 注意选择是2D的(因为默认3D) 在Assets框右键新建C#脚本 在新建 ...
- 制作一个简易计算器——基于Android Studio实现
一个计算器Android程序的源码部分分为主干和细节两部分. 一.主干 1. 主干的构成 计算器的布局 事件(即计算器上的按钮.文本框)监听 实现计算 2. 详细解释 假设我们的项目名为Calcula ...
- 菜鸟学习Struts——简易计算器
这是学习Struts的一个简单的例子文件结构如下: 1.配置Struts环境 2.新建input.jsp,success.jsp,error.jsp input.jsp代码如下: <%@ pag ...
- Python之实现一个简易计算器
自己动手写计算器 一.功能分析 用户输入一个类似这样 3*( 4+ 50 )-(( 100 + 40 )*5/2- 3*2* 2/4+9)*((( 3 + 4)-4)-4) 这样的表达式,假设表达式里 ...
- C#制作简易屏保(转)
C#制作简易屏保[原创] 原始网址: http://www.cnblogs.com/drizzlecrj/archive/2006/10/06/522182.html 2006-10-06 16:25 ...
随机推荐
- 分类器是如何做检测的?——CascadeClassifier中的detectMultiScale函数解读
原地址:http://blog.csdn.net/delltdk/article/details/9186875 在进入detectMultiScal函数之前,首先需要对CascadeClassifi ...
- SimpleWiFi模块评估板
SimpleWiFi评估套件,发货清单: 1.评估版一块. 2.专用WiFi天线一根. 3.配套电源一个. 单模块 是60元,链接如下: http://item.taobao.com/i ...
- Java Word Ladder(字梯)
问题: Given two words (start and end), and a dictionary, find the length of shortest transformation se ...
- Python处理海量手机号码
Python处理海量手机号码 一.任务描述 上周,老板给我一个小任务:批量生成手机号码并去重.给了我一个Excel表,里面是中国移动各个地区的可用手机号码前7位(如下图),里面有十三张表,每个表里的电 ...
- [android]APP启动界面——SplashActivity
概念 当前应用程序在启动的时候都会有一个展示自己公司LOGO和APP名字的界面.这个界面成为SplashActivity. 布局 <? xml version="1.0" e ...
- cocos2D(四)---- CCSprite
在介绍CCSprite之前,先要理解游戏开发中的一个核心概念:精灵.精灵也称为游戏对象,它能够用来表示游戏中的不论什么物体,比方敌人.子弹.甚至是一个背景图片.一段文字.CCSprite能够说是在co ...
- springMVC中一个class中的多个方法
在前面.已经可以利用SpringMVC进行简单的例子了,但是,在controller中我们实现了Controller接口.这样就必须实现handleRequest(HttpServletRequest ...
- Oracle 数据迁移(从Oracle11G迁移到更高的版本号Oracle10G低版本号)
1.数据库状况 生产环境是11G,linux系统,測试环境是10G,windows系统,须要从生产环境导出一个用户下全部的数据,导入測试环境中. 由于数据量比較小,准备採用EXP和IMP工具来做 ...
- pygame系列_游戏窗口显示策略
在这篇blog中,我将给出一个demo演示: 当我们按下键盘的‘f’键的时候,演示的窗口会切换到全屏显示和默认显示两种显示模式 并且在后台我们可以看到相关的信息输出: 上面给出了一个简单的例子,当然在 ...
- Eclipse关闭检查
有没有发现每次操作Eclipse过后,都会有build Workspace的操作一直在后台执行,JS校验一直validate,非常卡非常受不了有木有? 有木有?以下是我个人成功的步骤,曾经试过非常多次 ...